Linux DNS reverse analysis, DNS master server and slave server configuration (with experimental diagram)

1. DNS reverse resolution

1. Install bind

Insert picture description here

2. Find the configuration file path

Insert picture description here

3. Configure reverse analysis

1. Edit the main configuration file

Insert picture description here

vim /etc/named.conf
options {
  listen-on-v6 poet 53 { any; };              #监听53端口,IP地址使用提供服务的本地IP,也可用any代表所有
#   listen-on-v6 port 53 { : :1; };                      #ipv6注释掉或者删除
  directory       "/var/named";                          #区域数据文件的默认存放位置
  dump- file      "/var/ named/data/cache_ dump . db";   #域名缓存数据库文件的位置
  statistics-file "/var/named/data/named stats.txt";     #状态统计文件的位置
  memstatistics-file "/var/named/data/named_ mem_ stats. txt";    #内存统计文件的位置
  allow-query       { any; };                            #允许使用本DNS解析服务的网段,也可用any代表所有

2. Modify zone configuration file, add reverse zone configuration

vim /etc/named.rfc1912.zones						#文件里有模版,可复制粘贴后修改
zone "172.168.192.in-addr.arpa" IN {			#反向解析的地址倒过来写,代表解析192.168.172段的地址
        type master;
        file "zhangsan.com.zone.local";			#指定区域数据文件为zhangsan.com.zone.local
        allow-update { none; };
};

Insert picture description here

Insert picture description here

3. Configure the reverse zone data file

d /var/named/
cp -p named.localhost zhangsan.com.zone.local
vim /var/named/zhangsan.com.zone.local
$TTL 1D
@       IN SOA  zhangsan.com. admin.zhangsan.com. (		#这里的“@”代表192.168.172段地址
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      zhangsan.com.
        A       192.168.172.10
20 IN  PTR     www.zhangsan.com.

#PTR为反向指针,反向解析192.168.172.10地址结果为www.zhangsan.com.

Insert picture description here

4. Restart the service to test

systemctl restart named
host 192.168.132.20
nslookup 192.168.132.20

Insert picture description here
Insert picture description here

Insert picture description here

Second, build a master-slave domain name server

1. Modify the zone configuration file of the primary domain name server, modify the forward and reverse zone configuration

vim /etc/ named. rfc1912. zone
zone "kgc.com" IN {
         type master;                         #类型为主区域
         file "kgc.com.zone";
         allow-transfer { 192.168.132.10; } ;  #允许从服务器下载正向区域数据,这里添从服务器的IP地址
};

zone "132.168.192.in-addr.arpa" IN {
       type master;
file "kgc.com.zone.local";
allow-transfer { 192.168.132.10; } ;
};

Insert picture description here

2. Modify the master configuration file of the slave domain name server

yum -y install bind
vim /etc/named.conf
options {
    listen-on port 53 { any; };	#监听53端口,ip地址使用提供服务的本地IP即可,也可用any代表所有
#    listen-on-v6 port 53 { ::1; };			
    directory       "/var/named";			
    dump-file       "/var/named/data/cache_dump.db";	
    statistics-file "/var/named/data/named_stats.txt";	
    memstatistics-file "/var/named/data/named_mem_stats.txt";	
    recursing-file  "/var/named/data/named.recursing";
    secroots-file   "/var/named/data/named.secroots";
    allow-query     { any; }; 				#允许使用本DNS解析服务的网段,也可用any代表所有
	……

Insert picture description here

3. Modify the zone configuration file from the domain name server, add positive and negative zone configuration

vim /etc/named.rfc1912.zones
zone "kgc.com" IN {
		type slave;							#类型为从区域
		masters { 192.168.132.20; };			#指定主服务器的IP地址
		file "slaves/zhangsan.com.zone";   	#下载的区域数据文件保存到slaves/目录下
};

zone "132.168.192.in-addr.arpa" IN {	
        type slave;
		masters { 192.168.132.20; };
        file "slaves/zhangsan.com.zone.local";
};

Insert picture description here

4. Both the master and slave restart the service, turn off the firewall, and check whether the area data file has been downloaded successfully

systemctl restart named    
systemctl stop firewalld     
setenforce 0
ls -l /var/named/slaves/

Insert picture description here

5. Add the slave DNS server address in the client's domain name resolution configuration file

echo "nameserver 192.168.132.10" >> /etc/resolv.conf
echo "nameserver 192.168.132.20" >> /etc/resolv.conf

6. Test

host 192.168.132.21
nslookup 192.168.132.22

Insert picture description here

#停止主服务器的服务,模拟主服务器故障
systemctl stop named
host 192.168.132.21
nslookup 192.168.132.22

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/zhangyuebk/article/details/114016516
Recommended