如何在Ubuntu 20.04上配置从站绑定DNS服务器

时间:2020-02-23 14:44:30  来源:igfitidea点击:

在上一篇文章中,我们涵盖了如何使用bind9设置主DNS服务器。
我们将探索如何设置辅助DNS服务器。
从属DNS服务器使用区域传输方法获取来自主DNS的数据副本。
此方法将区域数据保存在特定时间的缓存中,并将其用于DNS查询。

在我们的设置中,我们有一个IP的主要DNS服务器 172.16.10.2和域名是 ns1.theitroad.local

我们正在设置辅助服务器 172.16.10.10ns2.theitroad.local

绑定主DNS上的配置

对于主从安装程序,我们需要配置主DNS服务器并将区域传输到辅助名称服务器。

我们将编辑 /etc/named.conf.local主服务器上的文件 (ns1.theitroad.local)并添加 allow-transferalso-notify参数。

sudo vim /etc/bind/named.conf.local

这将为前向和反向条目进行。

##Forward zone
zone "theitroad.local" IN { //Domain name
    
      type master; //Primary DNS
     file "/etc/bind/forward.theitroad.local.db"; //Forward lookup file
     allow-update { none; }; //Since this is the primary DNS, it should be none.
     allow-transfer  { 172.16.10.10; }; //Allow Transfer of zone from the master server
     also-notify { 172.16.10.10; }; //Notify slave for zone changes
};
##Reverse zone
zone "10.16.172.in-addr.arpa" IN { //Reverse lookup name, should match your network in reverse order
     type master; //Primary DNS
     file "/etc/bind/reverse.theitroad.local.db"; //Reverse lookup file
     allow-update { none; }; //Since this is the primary DNS, it should be none.
     allow-transfer  { 172.16.10.10; }; //Allow Transfer of zone from the master server
     also-notify { 172.16.10.10; }; //Notify slave for zone changes
};

allow-transfer参数允许在主设备中传输区域文件到从属DNS also-notify只要有来自主设备的区域文件更新,可以帮助启动从站。

我们必须在ns1.theitroad.local上重新启动DNS服务:

sudo systemctl restart bind9

配置从属DNS

安装必要的包:

sudo apt-get install -y bind9 bind9utils bind9-doc dnsutils

在/etc/bind/named.conf.local处编辑文件并添加前进和反向区域参数:

sudo vi /etc/bind/named.conf.local
###Forward Zone
zone "theitroad.local" IN { //Domain name
     type slave; //Secondary Slave DNS
     file "/var/cache/bind/forward.theitroad.local.db"; //Forward Zone Cache file
     masters { 172.16.10.2; }; //Master Server IP
};
####Reverse zone
zone "10.16.172.in-addr.arpa" IN { //Reverse lookup name. Should match your network in reverse order
     type slave; //Secondary/Slave DNS
     file "/var/cache/bind/reverse.theitroad.local.db"; //Reverse Zone Cache file
     masters { 172.16.10.2; }; //Master Server IP
};

重新启动DNS服务:

sudo systemctl restart bind9

测试从属DNS

要测试如果区域传输成功并且DNS正在从服务器上运行,我们需要配置客户端主机并使用从站作为其DNS服务器。

在Ubuntu:

sudo echo "nameserver 172.16.10.10" >> /etc/resolv.conf

然后我们可以使用 dig命令验证DNS。

Hyman@theitroad:~# dig www.theitroad.local
; <<>> DiG 9.16.1-Ubuntu <<>> www.theitroad.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24401
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: b1e287dd1d118ad6010000005f8c88233ef562a7063e7a15 (good)
;; QUESTION SECTION:
;www.theitroad.local.	IN	A
;; ANSWER SECTION:
www.theitroad.local. 604800 IN	A	172.16.10.3
;; Query time: 0 msec
;; SERVER: 172.16.10.10#53(172.16.10.10)
;; WHEN: Sun Oct 18 18:23:31 UTC 2017
;; MSG SIZE  rcvd: 100

你可以使用 dig domain-name <@nameserver>如果我们希望将查询显式指向从属DNS。

dig www.theitroad.local @172.16.10.10

结果表明,从属DNS能够处理查询。
这意味着主从DNS设置根据需要工作。