配置从节点
1、前面已经安装并且修改了主配置文件,接下来修改区域配置文件
添加
[root@mail ~]# vi /etc/named.rfc1912.zones
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
};
zone "testmail.com" IN {
type slave;
file "slaves/slavertestmail.com.zone";
masters{192.168.200.80;}; # 这里是主服务器的IP
};
zone "200.168.192.in-addr.arpa" IN {
type slave;
file "slaves/70.200.168.192.in-addr.arpa.local";
masters{192.168.200.80;}; # 这里是主服务器的IP
};
"/etc/named.rfc1912.zones" 53L, 1213C written
2、修改解析文件/etc/reslove.conf
[root@mail ~]# vi /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.200.70
nameserver 192.168.200.80
nameserver 114.114.114.114
3、重启服务
[root@mail ~]# systemctl restart named
4、主节点关闭服务
[root@dns named]# systemctl stop named
5、测试dns解析结果
[root@mail ~]# nslookup dns.testmail.com
Server: 192.168.200.70
Address: 192.168.200.70#53
Name: dns.testmail.com
Address: 192.168.200.70
6、主节点关闭后,在 /var/named/slaves/目录下会生成两个文件
[root@mail ~]# cd /var/named/
[root@mail named]# ll
total 16
drwxr-x---. 7 root named 56 Nov 6 16:48 chroot
drwxrwx---. 2 named named 22 Nov 6 16:48 data
drwxrwx---. 2 named named 58 Nov 6 18:04 dynamic
-rw-r-----. 1 root named 2253 Apr 5 2018 named.ca
-rw-r-----. 1 root named 152 Dec 15 2009 named.empty
-rw-r-----. 1 root named 152 Jun 21 2007 named.localhost
-rw-r-----. 1 root named 168 Dec 15 2009 named.loopback
drwxrwx---. 2 named named 70 Nov 6 18:03 slaves
[root@mail named]# cd slaves/
[root@mail slaves]# ll
total 8
-rw-r--r--. 1 named named 282 Nov 6 18:03 70.200.168.192.in-addr.arpa.local
-rw-r--r--. 1 named named 403 Nov 6 18:03 testmail.com.zone
7、可以上主节点测试
测试正向解析
[root@dns named]# dig dns.testmail.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.4 <<>> dns.testmail.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39856
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;dns.testmail.com. IN A
;; ANSWER SECTION:
dns.testmail.com. 86400 IN A 192.168.200.70
;; AUTHORITY SECTION:
testmail.com. 86400 IN NS dns.testmail.com.
;; Query time: 0 msec
;; SERVER: 192.168.200.70#53(192.168.200.70) ## 显示主机在从节点
;; WHEN: Thu Nov 26 05:56:27 CST 2020
;; MSG SIZE rcvd: 75
测试反向解析
[root@dns named]# dig -x dns.testmail.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.4 <<>> -x dns.testmail.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 8829
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;com.testmail.dns.in-addr.arpa. IN PTR
;; Query time: 659 msec
;; SERVER: 192.168.200.70#53(192.168.200.70) ## 服务在从节点
;; WHEN: Thu Nov 26 05:56:32 CST 2020
;; MSG SIZE rcvd: 58
7、开启主节点的服务
服务又回到主节点
[root@dns named]# systemctl start named
[root@dns named]# dig -x dns.testmail.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.4 <<>> -x dns.testmail.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 14439
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;com.testmail.dns.in-addr.arpa. IN PTR
;; Query time: 891 msec
;; SERVER: 192.168.200.70#53(192.168.200.80) ## 这里回到主节点
;; WHEN: Thu Nov 26 05:57:08 CST 2020
;; MSG SIZE rcvd: 58
DNS检测工具
1.nslookup 命令是常用域名查询工具,就是查 DNS 信息用的命令。
一般格式: nslookup [-option] [name | -] [server]
参数说明:
option:表示一些选项。这些选项可以通过 set 命令设置修改。
name:表示查询的域名。
server:可以指定 DNS 主机 IP。
set 命令说明: set all:打印当前的选项值。
set calss=value:设置查询的类型,一般情况下为 Internet。
set debug:设置调试模式。 set d2:设置详细调试模式。
set domin=name:设置默认的域名。
set search: set port=value:设置 DNS 端口。
set querytype=value:改变查询的信息的类型。默认的类型为 A 纪录。
set type=value:和 set querytype 一样。
set recurse:设置查询类型为递归;若为 set norecurse,查询类型为跌代;缺省为前者。
set retry=number:设置重试的次数。
set timeout=number:设置等待应答的限制时间(单位为秒),超出即为超时,如果还可以 重试,就会将长超时值加倍,重新查询。 set vc:通过 tcp 方式查询。 具体说明可以查看 man 手册。 格式:nslookup -nameserver/ip。例如:
[root@controller ~]# nslookup 192.168.100.30
30.100.168.192.in-addr.arpa name = dns.testmail.com. 30.100.168.192.in-addr.arpa name = mail.testmail.com.