設置主從 DNS 的主要是為了冗餘,分擔壓力,防止伺服器宕機後, DNS 無法正常解析。 ...
設置主從DNS
的主要是為了冗餘,分擔壓力,防止伺服器宕機後,DNS
無法正常解析。
配置 master
正常配置
DNS
服務。
設置主機名
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash
安裝 bind 包
[root@master ~]# yum install bind bind-utils -y
編輯主配置文件
[root@master ~]# vim /etc/named.conf
- 配置監聽網段、允許查詢網段
listen-on port 53 { 192.168.28.128; };
allow-query { any; };
編輯區域配置文件
[root@master ~]# vim /etc/named.rfc1912.zones
zone "yun.com" IN {
type master;
file "yun.com.zone";
allow-update { none; };
};
zone "100.168.192.in-addr.arpa" IN {
type master;
file "100.168.192.zone";
allow-update { none; };
};
編輯區域數據配置文件
[root@master ~]# cd /var/named/
- 編輯正向區域數據文件
[root@master named]# cp -p named.localhost yun.com.zone
[root@master named]# vim yun.com.zone
$TTL 1D
@ IN SOA yun.com admin.yun.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS yun.com.
IN A 192.168.28.128
IN MX 10 mail.yun.com.
www IN A 192.168.100.10
ftp IN A 192.168.100.20
bbs IN CNAME www
* IN A 8.8.8.8
- 編輯反向區域數據文件
[root@master named]# cp -p yun.com.zone 100.168.192.zone
[root@master named]# vim 100.168.192.zone
$TTL 1D
@ IN SOA yun.com admin.yun.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS yun.com.
IN A 192.168.28.128
10 IN PTR www.yun.com.
20 IN PTR ftp.yun.com.
啟動服務
[root@master ~]# systemctl start named
[root@master ~]# systemctl enable named
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
[root@master ~]# netstat -ntuap | grep named
tcp 0 0 192.168.28.128:53 0.0.0.0:* LISTEN 34822/named
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 34822/named
tcp6 0 0 ::1:53 :::* LISTEN 34822/named
tcp6 0 0 ::1:953 :::* LISTEN 34822/named
udp 0 0 192.168.28.128:53 0.0.0.0:* 34822/named
udp6 0 0 ::1:53 :::* 34822/named
關閉防火牆
[root@master ~]# systemctl stop firewalld
[root@master ~]# setenforce 0
nslookup
- 設置
DNS
地址
[root@master ~]# vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.28.128
- 正向查詢
[root@master ~]# nslookup www.yun.com
Server: 192.168.28.128
Address: 192.168.28.128#53
Name: www.yun.com
Address: 192.168.100.10
[root@master ~]# nslookup ftp.yun.com
Server: 192.168.28.128
Address: 192.168.28.128#53
Name: ftp.yun.com
Address: 192.168.100.20
[root@master ~]# nslookup bbs.yun.com
Server: 192.168.28.128
Address: 192.168.28.128#53
bbs.yun.com canonical name = www.yun.com.
Name: www.yun.com
Address: 192.168.100.10
[root@master ~]# nslookup asd.yun.com
Server: 192.168.28.128
Address: 192.168.28.128#53
Name: asd.yun.com
Address: 8.8.8.8
- 反向查詢
[root@master ~]# nslookup 192.168.100.10
Server: 192.168.28.128
Address: 192.168.28.128#53
10.100.168.192.in-addr.arpa name = www.yun.com.
[root@master ~]# nslookup 192.168.100.20
Server: 192.168.28.128
Address: 192.168.28.128#53
20.100.168.192.in-addr.arpa name = ftp.yun.com.
allow-transfer
這是最重要的一步,允許傳送。配置好後重啟服務。
[root@master ~]# vim /etc/named.rfc1912.zones
zone "yun.com" IN {
type master;
file "yun.com.zone";
allow-transfer { 192.168.28.129; };
allow-update { none; };
};
zone "100.168.192.in-addr.arpa" IN {
type master;
file "100.168.192.zone";
allow-transfer { 192.168.28.129; };
allow-update { none; };
};
配置 slave
設置主機名
[root@localhost ~]# hostnamectl set-hostname slave
[root@localhost ~]# bash
安裝 bind 包
[root@slave ~]# yum install bind bind-utils -y
編輯主配置文件
[root@slave ~]# vim /etc/named.conf
- 配置監聽網段、允許查詢網段
listen-on port 53 { 192.168.28.129; };
allow-query { any; };
編輯區域配置文件
[root@slave ~]# vim /etc/named.rfc1912.zones
zone "yun.com" IN {
type slave;
file "slaves/yun.com.zone";
masters { 192.168.28.128; };
allow-update { none; };
};
zone "100.168.192.in-addr.arpa" IN {
type slave;
file "slaves/100.168.192.zone";
masters { 192.168.28.128; };
allow-update { none; };
};
啟動服務
[root@slave ~]# systemctl start named
[root@slave ~]# systemctl enable named
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
[root@slave ~]# netstat -ntuap | grep named
tcp 0 0 192.168.28.129:53 0.0.0.0:* LISTEN 1661/named
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 1661/named
tcp6 0 0 ::1:53 :::* LISTEN 1661/named
tcp6 0 0 ::1:953 :::* LISTEN 1661/named
udp 0 0 192.168.28.129:53 0.0.0.0:* 1661/named
udp6 0 0 ::1:53 :::* 1661/named
關閉防火牆
[root@slave ~]# systemctl stop firewalld
[root@slave ~]# setenforce 0
- 區域數據文件自動傳送到從伺服器
[root@slave ~]# ll /var/named/slaves/
total 8
-rw-r--r--. 1 named named 378 Sep 12 02:11 100.168.192.zone
-rw-r--r--. 1 named named 392 Sep 12 02:11 yun.com.zone
nslookup
- 設置
DNS
地址
[root@slave ~]# vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.28.129
- 正向查詢
[root@slave ~]# nslookup www.yun.com
Server: 192.168.28.129
Address: 192.168.28.129#53
Name: www.yun.com
Address: 192.168.100.10
[root@slave ~]# nslookup ftp.yun.com
Server: 192.168.28.129
Address: 192.168.28.129#53
Name: ftp.yun.com
Address: 192.168.100.20
[root@slave ~]# nslookup bbs.yun.com
Server: 192.168.28.129
Address: 192.168.28.129#53
bbs.yun.com canonical name = www.yun.com.
Name: www.yun.com
Address: 192.168.100.10
[root@slave ~]# nslookup asd.yun.com
Server: 192.168.28.129
Address: 192.168.28.129#53
Name: asd.yun.com
Address: 8.8.8.8
- 反向查詢
[root@slave ~]# nslookup 192.168.100.10
Server: 192.168.28.129
Address: 192.168.28.129#53
10.100.168.192.in-addr.arpa name = www.yun.com.
[root@slave ~]# nslookup 192.168.100.20
Server: 192.168.28.129
Address: 192.168.28.129#53
20.100.168.192.in-addr.arpa name = ftp.yun.com.