BIND DNS服务高可用(二) 辅助服务器部署

1
2
3
4
5
6
7
作者:李晓辉

联系方式:

1. 微信:Lxh_Chat

2. 邮箱:939958092@qq.com

环境介绍

操作系统IP地址主机名BIND版本角色
rhel8172.25.250.10serveraBIND 9主DNS服务器
rhel8172.25.250.11serverbBIND 9辅助DNS服务器

本篇文章是继上一篇BIND DNS服务高可用(一) 主服务器部署 之后的续作,上一篇主要是将如何实现主要的DNS服务器,本篇是用来对DNS服务器进行灾备,在主服务器出现问题时,备用服务器还能提供服务。

了解BIND 辅助 DNS 服务器

BIND(Berkeley Internet Name Domain) 是一种广泛使用的 DNS 服务器软件,它具有高可配置性和扩展性。在 BIND 中,DNS 服务可以分为主服务器(Primary DNS Server)和辅助服务器(Secondary DNS Server)。辅助 DNS 服务器也被称为从服务器(Slave DNS Server),它们通过从主服务器同步数据来提供冗余和高可用性。

辅助 DNS 服务器的主要功能

  1. 数据冗余和高可用性:辅助服务器从主服务器获取区域数据(zone data),确保当主服务器不可用时,DNS 查询依然能够得到响应。这提高了整个 DNS 系统的可靠性和可用性。

  2. 负载均衡:通过分散 DNS 查询负载到多个服务器,辅助服务器有助于减轻主服务器的负载,提升服务响应速度。

  3. 防止单点故障:辅助服务器可以在主服务器发生故障时接管 DNS 服务,避免单点故障导致的服务中断。

  4. 数据同步:辅助服务器定期与主服务器同步数据,确保辅助服务器上的 DNS 记录与主服务器保持一致。这种同步通常通过 zone transfer(区域传输)来实现,常见的方式有全量传输(AXFR)和增量传输(IXFR)。

配置辅助bind服务器

安装bind

1
[root@serverb ~]# yum install bind -y

配置主配置文件

将 BIND 配置为具有与主 BIND 服务器相同的安全配置。从 主服务器 复制 /etc/named.conf 配置

1
2
[root@serverb ~]# scp servera:/etc/named.conf /etc/named.conf
[root@serverb ~]# scp servera:/etc/named.rfc1912.zones /etc/named.rfc1912.zones

配置区域文件

在刚才scp中,我们把主服务器的配置复制过来了,但是里面的类型是主服务器,我们需要修改为次要的,需要注意的是辅助区域在 slaves/ 子目录中创建区域文件

1
[root@serverb ~]# vim /etc/named.rfc1912.zones
1
2
3
4
5
6
7
8
9
10
zone "lixiaohui.cn" IN {
type slave;
file "slaves/lixiaohui.cn.zone";
masters { 172.25.250.10; };
};
zone "250.25.172.in-addr.arpa" IN {
type slave;
file "slaves/lixiaohui.cn.ptr";
masters { 172.25.250.10; };
};

配置文件权限

1
2
[root@serverb ~]# chown :named /etc/named.conf /etc/named.rfc1912.zones
[root@serverb ~]# chmod 0640 /etc/named.conf /etc/named.rfc1912.zones

启动服务

1
[root@serverb ~]# systemctl enable --now named

开通防火墙

1
2
[root@serverb ~]# firewall-cmd --add-service=dns --permanent
[root@serverb ~]# firewall-cmd --reload

查询同步状态

1
[root@serverb ~]# journalctl -xeu named
1
2
3
4
5
6
7
8
9
10
11
Aug 23 01:01:51 serverb.lab.example.com named[26633]: zone lixiaohui.cn/IN: Transfer started.
Aug 23 01:01:51 serverb.lab.example.com named[26633]: transfer of 'lixiaohui.cn/IN' from 172.25.250.10#53: connected using 172.25.250.11#52091
Aug 23 01:01:51 serverb.lab.example.com named[26633]: zone lixiaohui.cn/IN: transferred serial 1
Aug 23 01:01:51 serverb.lab.example.com named[26633]: transfer of 'lixiaohui.cn/IN' from 172.25.250.10#53: Transfer status: success
Aug 23 01:01:51 serverb.lab.example.com named[26633]: transfer of 'lixiaohui.cn/IN' from 172.25.250.10#53: Transfer completed: 1 messages, 9 records, 281 bytes, 0.002 secs (140500 bytes/sec)
Aug 23 01:01:51 serverb.lab.example.com named[26633]: zone 250.25.172.in-addr.arpa/IN: Transfer started.
Aug 23 01:01:51 serverb.lab.example.com named[26633]: transfer of '250.25.172.in-addr.arpa/IN' from 172.25.250.10#53: connected using 172.25.250.11#33001
Aug 23 01:01:51 serverb.lab.example.com named[26633]: zone 250.25.172.in-addr.arpa/IN: transferred serial 1
Aug 23 01:01:51 serverb.lab.example.com named[26633]: transfer of '250.25.172.in-addr.arpa/IN' from 172.25.250.10#53: Transfer status: success
Aug 23 01:01:51 serverb.lab.example.com named[26633]: transfer of '250.25.172.in-addr.arpa/IN' from 172.25.250.10#53: Transfer completed: 1 messages, 5 records, 197 bytes, 0.001 secs (197000 bytes/sec)
Aug 23 01:02:01 serverb.lab.example.com named[26633]: resolver priming query complete

查询辅助DNS服务器

1
2
3
4
[root@serverb ~]# ll /var/named/slaves/
total 8
-rw-r--r--. 1 named named 326 Aug 23 01:01 lixiaohui.cn.ptr
-rw-r--r--. 1 named named 480 Aug 23 01:01 lixiaohui.cn.zone

默认情况下无法用cat查询以上两个文件,因为是性能更好的raw格式,如果需要查询,可以将masterfile-format text;参数加入slave配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@serverb ~]# cat /etc/named.rfc1912.zones
zone "lixiaohui.cn" IN {
type slave;
file "slaves/lixiaohui.cn.zone";
masterfile-format text;
masters { 172.25.250.10; };
};
zone "250.25.172.in-addr.arpa" IN {
type slave;
masterfile-format text;
file "slaves/lixiaohui.cn.ptr";
masters { 172.25.250.10; };
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@serverb ~]# cat /var/named/slaves/lixiaohui.cn.zone
$ORIGIN .
$TTL 86400 ; 1 day
lixiaohui.cn IN SOA ns.lixiaohui.cn. 939958092.qq.com. (
1 ; serial
86400 ; refresh (1 day)
3600 ; retry (1 hour)
604800 ; expire (1 week)
10800 ; minimum (3 hours)
)
NS ns.lixiaohui.cn.
$TTL 20 ; 20 seconds
MX 10 mail.lixiaohui.cn.
$ORIGIN lixiaohui.cn.
abc NS ns.zhangsan.com.
$TTL 30 ; 30 seconds
lxh A 192.168.8.100
AAAA 2001:db8:2020::5300
$TTL 86400 ; 1 day
ns A 172.25.250.10
$TTL 3600 ; 1 hour
support.online A 172.25.250.10

正式用辅助DNS服务器查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@serverb slaves]# dig -x 172.25.250.10 @172.25.250.11

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el8 <<>> -x 172.25.250.10 @172.25.250.11
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28337
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 6d630cc38d0004131424d42c66c77727a4c53994dcef3b99 (good)
;; QUESTION SECTION:
;10.250.25.172.in-addr.arpa. IN PTR

;; ANSWER SECTION:
10.250.25.172.in-addr.arpa. 86400 IN PTR ns.lixiaohui.cn.

;; AUTHORITY SECTION:
250.25.172.in-addr.arpa. 86400 IN NS ns.lixiaohui.cn.

;; ADDITIONAL SECTION:
ns.lixiaohui.cn. 86400 IN A 172.25.250.10

;; Query time: 0 msec
;; SERVER: 172.25.250.11#53(172.25.250.11)
;; WHEN: Fri Aug 23 01:36:39 CST 2024
;; MSG SIZE rcvd: 142

触发主辅服务器同步

在主服务器更新区域文件,并序号加1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@servera ~]# cd /var/named/
[root@servera named]# vim lixiaohui.cn.zone
[root@servera named]# cat lixiaohui.cn.zone
$TTL 1D
lixiaohui.cn. IN SOA ns.lixiaohui.cn. 939958092.qq.com. (
2 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
1D IN NS ns.lixiaohui.cn.
ns 1D IN A 172.25.250.10
lxh 30 IN A 192.168.8.100
lxh-2 30 IN A 192.168.8.100
30 IN AAAA 2001:db8:2020::5300
@ 20 IN MX 10 mail.lixiaohui.cn.
mail 30 IN A 172.25.250.10
support.online 1H IN A 172.25.250.10

[root@servera named]# systemctl reload named

在辅助服务器查看是否自动更新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@serverb ~]# cd /var/named/slaves/
[root@serverb slaves]# cat lixiaohui.cn.zone
$ORIGIN .
$TTL 86400 ; 1 day
lixiaohui.cn IN SOA ns.lixiaohui.cn. 939958092.qq.com. (
2 ; serial
86400 ; refresh (1 day)
3600 ; retry (1 hour)
604800 ; expire (1 week)
10800 ; minimum (3 hours)
)
NS ns.lixiaohui.cn.
$TTL 20 ; 20 seconds
MX 10 mail.lixiaohui.cn.
$ORIGIN lixiaohui.cn.
$TTL 30 ; 30 seconds
lxh A 192.168.8.100
lxh-2 A 192.168.8.100
AAAA 2001:db8:2020::5300
mail A 172.25.250.10
$TTL 86400 ; 1 day
ns A 172.25.250.10
$TTL 3600 ; 1 hour
support.online A 172.25.250.10

确认日志消息正确

1
2
3
4
5
6
7
Aug 23 04:05:50 serverb.lab.example.com named[864]: client @0x7fe308044c90 172.25.250.10#53572: received notify for zone 'lixiaohui.cn'
Aug 23 04:05:50 serverb.lab.example.com named[864]: zone lixiaohui.cn/IN: notify from 172.25.250.10#53572: serial 2
Aug 23 04:05:50 serverb.lab.example.com named[864]: zone lixiaohui.cn/IN: Transfer started.
Aug 23 04:05:50 serverb.lab.example.com named[864]: transfer of 'lixiaohui.cn/IN' from 172.25.250.10#53: connected using 172.25.250.11#46605
Aug 23 04:05:50 serverb.lab.example.com named[864]: zone lixiaohui.cn/IN: transferred serial 2
Aug 23 04:05:50 serverb.lab.example.com named[864]: transfer of 'lixiaohui.cn/IN' from 172.25.250.10#53: Transfer status: success
Aug 23 04:05:50 serverb.lab.example.com named[864]: transfer of 'lixiaohui.cn/IN' from 172.25.250.10#53: Transfer completed: 1 messages, 10 records, 289 bytes, 0.001 secs (289000 bytes/sec)