更新升级 专属应用 系统故障 硬件故障 电脑汽车 鸿蒙刷机 鸿蒙开发Linux教程 鸿蒙开发Linux命令
当前位置:HMXT之家 > 鸿蒙开发Linux教程 > 在Ubuntu 22.04操作系统上配置从属BIND DNS服务器

在Ubuntu 22.04操作系统上配置从属BIND DNS服务器

更新时间:2022-12-29 09:45:36浏览次数:461+次

本文介绍在Ubuntu 22.04操作系统上配置从属BIND DNS服务器的方法。从属DNS服务器使用区域传输方法从主DNS获取数据副本,此方法将区域数据保存在缓存中特定时间,并使用它来服务DNS查询。在我们的设置中,我们有一个主DNS服务器,其IP为172.16.10.2,域名为ns1.computingforgeeks.local。我们正在设置具有172.16.10.10和ns2.computingforgeeks.local的辅助服务器。

在Ubuntu 22.04上配置从属BIND DNS服务器

步骤1、绑定主DNS上的配置

对于主从设置,我们需要配置主DNS服务器并启用到辅助名称服务器的区域传输。

我们将编辑主服务器上的/etc/named.conf.local文件(ns1.computingforgeks.local),并添加allow-transfer和also-notify参数:

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

这将用于正向和反向条目:

##Forward zone

zone "computingforgeeks.local" IN { // Domain name

      type master; // Primary DNS

     file "/etc/bind/forward.computingforgeeks.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.computingforgeeks.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传输到从属DNS,而also-notify有助于在主DNS更新区域文件时通知从属DNS。

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

sudo systemctl restart bind9

步骤2、配置从属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 "computingforgeeks.local" IN { //Domain name

     type slave; //Secondary Slave DNS

     file "/var/cache/bind/forward.computingforgeeks.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.computingforgeeks.local.db"; //Reverse Zone Cache file

     masters { 172.16.10.2; }; //Master Server IP

};

重新启动DNS服务:

sudo systemctl restart bind9

步骤3、测试从属DNS设置

为了测试区域传输是否成功,DNS是否在从属服务器上运行,我们需要配置一个客户端主机,并将从属服务器用作其DNS服务器。

在Ubuntu中:

$ sudo vim /etc/resolv.conf

nameserver 172.16.10.10

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

root@ubuntu:~# dig www.computingforgeeks.local

; <<>> DiG 9.16.1-Ubuntu <<>> www.computingforgeeks.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.computingforgeeks.local. IN A

;; ANSWER SECTION:

www.computingforgeeks.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 2020

;; MSG SIZE  rcvd: 100

如果希望明确地将查询定向到从属DNS,则可以使用dig domain-name @<nameserver>:

dig www.computingforgeeks.local @172.16.10.10

结果表明,从属DNS能够处理查询。这意味着主从DNS设置正在按预期工作。

至此,已使用BIND9在Ubuntu 22.04上成功设置了从属DNS服务器。