# 编辑配置文件[root@zyxfx ~]# vim /etc/named.conf# 找到其中两行(15行左右)
listen-on port 53{127.0.0.1;};
allow-query { localhost;};# 修改为
listen-on port 53{ any;};
allow-query { any;};
配置正向解析
# 编辑文件/etc/named.rfc1912.zones,在末尾添加需要解析的域[root@zyxfx ~]# vim /etc/named.rfc1912.zones
zone "test.com" IN {type master;file"data/test.com.zone";};# 创建test.com.zone解析域[root@zyxfx ~]# vim /var/named/data/test.com.zone$TTL 3H
@ IN SOA test.com. root (20180928; serial
1D ; refresh
1H ; retry
1W ; expire
3H ); minimum
IN NS @
IN A 192.168.10.2
www IN A 192.168.10.2
file IN A 192.168.10.2
# 编辑/etc/resolv.conf,添加配置[root@zyxfx ~]# vim /etc/resolv.conf#添加配置
search localdomain
nameserver 192.168.10.2
重启DNS服务器
# 重启named[root@zyxfx ~]# systemctl restart named# 开机自启[root@zyxfx ~]# systemctl enable named# 查看状态[root@zyxfx ~]# systemctl status named
检查解析是否成功
# ping命令验证[root@zyxfx ~]# ping -c 4 www.test.com# 输出如下即解析成功
PING www.test.com (192.168.10.2)56(84) bytes of data.
64 bytes from file.test.com (192.168.10.2): icmp_seq=1ttl=64time=0.033 ms
64 bytes from file.test.com (192.168.10.2): icmp_seq=2ttl=64time=0.058 ms
64 bytes from file.test.com (192.168.10.2): icmp_seq=3ttl=64time=0.066 ms
64 bytes from file.test.com (192.168.10.2): icmp_seq=4ttl=64time=0.037 ms
--- www.test.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev =0.033/0.053/0.066/0.014 ms
# nslookup命令验证[root@zyxfx ~]# nslookup>www.test.com
# 输出如下即解析成功
Server: 192.168.10.2
Address: 192.168.10.2#53
Name: www.test.com
Address: 192.168.10.2
配置反向解析
# 编辑文件/etc/named.rfc1912.zones,在末尾添加 [root@zyxfx ~]# vim etc/named.rfc1912.zones
zone "10.168.192.in-addr.arpa" IN {type master;file"data/10.168.192.zone";};# 创建10.168.192.zone解析域[root@zyxfx ~]# vim /var/named/data/10.168.192.zone$TTL 3H
@ IN SOA web3.com. root (20180928; serial
1D ; refresh
1H ; retry
1W ; expire
3H ); minimum
@ IN NS www.test.com.
10 IN PTR www.test.com.
10 IN PTR file.test.com.
重启DNS服务器
# 重启named[root@zyxfx ~]# systemctl restart named# 开机自启[root@zyxfx ~]# systemctl enable named# 查看状态[root@zyxfx ~]# systemctl status named
检查解析是否成功
# ping命令验证[root@zyxfx ~]# ping -c 4 192.168.10.2# 输出如下即解析成功
PING 192.168.10.2 (192.168.10.2)56(84) bytes of data.
64 bytes from 192.168.10.2: icmp_seq=1ttl=64time=0.061 ms
64 bytes from 192.168.10.2: icmp_seq=2ttl=64time=0.058 ms
64 bytes from 192.168.10.2: icmp_seq=3ttl=64time=0.081 ms
64 bytes from 192.168.10.2: icmp_seq=4ttl=64time=0.060 ms
--- 192.168.10.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev =0.058/0.065/0.081/0.009 ms
# nslookup命令验证[root@zyxfx ~]# nslookup 192.168.10.2# 输出如下即解析成功
Server: 192.168.10.2
Address: 192.168.10.2#5310.10.168.192.in-addr.arpa name = file.test.com.
10.10.168.192.in-addr.arpa name = www.test.com.
配置从DNS服务器(192.168.10.3)
# 先修改主DNS服务器(192.168.10.2)的配置/etc/named.rfc1912.zones[root@zyxfx ~]# vim /etc/named.rfc1912.zones
zone "test.com" IN {type master;file"data/test.com.zone";
allow-transfer {192.168.10.3;};
notify yes;
also-notify {192.168.10.3;};};
zone "10.168.192.in-addr.arpa" IN {type master;file"data/10.168.192.zone";
allow-transfer {192.168.10.3;};
notify yes;
also-notify {192.168.10.3;};};
配置从DNS服务器(192.168.10.3)正向解析
# 编辑named.conf文件[root@zyxfx ~]# vim /etc/named.conf# 找到其中两行
listen-on port 53{127.0.0.1;};
allow-query { localhost;};# 修改为
listen-on port 53{ any;};
allow-query { any;};# 编辑文件/etc/named.rfc1912.zones,在末尾添加需要解析的域 [root@zyxfx ~]# vim /etc/named.rfc1912.zones
zone "test.com" IN {type slave;file"data/test.com.zone";};
masters {192.168.10.2;};# 创建test.com.zonek空文件 [root@zyxfx ~]# touch /var/named/data/test.com.zone # 设置所有者 chown named:named test.com.zone
# 编辑/etc/resolv.conf,添加配置[root@zyxfx ~]# vim /etc/resolv.conf
search localdomain
nameserver 192.168.10.3
重启DNS服务器
# 重启named[root@zyxfx ~]# systemctl restart named# 开机自启[root@zyxfx ~]# systemctl enable named# 查看状态[root@zyxfx ~]# systemctl status named
检测解析是否成功
# ping命令验证[root@zyxfx ~]# ping -c 4 www.test.com# 输出如下即解析成功
PING www.test.com (192.168.10.2)56(84) bytes of data.
64 bytes from file.test.com (192.168.10.2): icmp_seq=1ttl=64time=0.033 ms
64 bytes from file.test.com (192.168.10.2): icmp_seq=2ttl=64time=0.058 ms
64 bytes from file.test.com (192.168.10.2): icmp_seq=3ttl=64time=0.066 ms
64 bytes from file.test.com (192.168.10.2): icmp_seq=4ttl=64time=0.057 ms
--- www.test.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev =0.033/0.053/0.066/0.014 ms
# nslookup命令验证[root@zyxfx ~]# nslookup>www.test.com
# 输出如下即解析成功
Server: 192.168.10.3
Address: 192.168.10.3#53
Name: www.test.com
Address: 192.168.10.2
配置从DNS服务器(192.168.10.3)反向解析
# 在文件/etc/named.rfc1912.zones中添加 [root@zyxfx ~]# vim etc/named.rfc1912.zones
zone "10.168.192.in-addr.arpa" IN {type master;file"data/10.168.192.zone";
masters {192.168.10.2;};};# 创建空文件10.168.192.zone[root@zyxfx ~]# touch /var/named/data/10.168.192.zone# 设置所有者 [root@zyxfx ~]# chown named:named 10.168.192.zone
重启DNS服务器
# 重启named[root@zyxfx ~]# systemctl restart named# 开机自启[root@zyxfx ~]# systemctl enable named# 查看状态[root@zyxfx ~]# systemctl status named