0、环境
系统版本:CentOS Linux release 7.5.1804 (Core)
IP地址:192.168.0.2
1、安装
yum -y install bind.x86_64
2、配置
(1)全局配置文件
vim /etc/named.conf
options { listen-on port 53 { 127.0.0.1;192.168.0.2; }; 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"; allow-query { any; }; recursion yes; forwarders { 223.5.5.5; }; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; }; zone "." IN { type hint; file "named.ca"; }; include "/etc/named.rfc1912.zones"; include "/etc/named.root.key"; include "/etc/named.zones";
(2)主配置文件
vim /etc/named.zones
zone "youjiabest.com" IN { type slave; masters { 192.168.0.1; }; file "slaves/youjiabest.com.zone"; }; zone "zzzz.com" IN { type slave; masters { 192.168.0.1; }; file "slaves/zzzz.com.zone"; };
(3)区域配置文件:slave不需要配置,会从master服务器同步过来
3、启动
service named start
4、测试
(1)slave启动后,会从master服务器同步区域配置文件,在主配置文件里面定义的/var/named/slaves下面:
注:allow-transfer参数:允许区域传输的辅助区域,未指定将允许传输到所有的主机,所有我们就不在master服务器的全局配置文件的option块里面添加了
(2)如果我们在master服务器上新增一条解析记录,比如:
xxx IN A 192.168.0.4
会发现使用slave无法解析出来,dig @192.168.0.2 xxx.youjiabest.com失败,
原因是我们需要在master服务器全局配置文件的option块,增加两个参数:
notify yes;
also-notify { 192.168.0.2; }
同时修改对应的区域配置文件youjiabest.com.zone里面的序列号,
增加完成后,重启master服务器的named,再使用slave进行解析,就会成功:
;; ANSWER SECTION: xxx.youjiabest.com. 86400 IN A 192.168.0.4 ;; AUTHORITY SECTION: youjiabest.com. 86400 IN NS dns.youjiabest.com. ;; ADDITIONAL SECTION: dns.youjiabest.com. 86400 IN A 192.168.0.