实验环境
ns1.magedu.com 172.18.71.101/24 CentOS-6.7-x86_64
iptables
与SELinux
均处于关闭状态。
安装bind
[root@ns1 ~]# yum install -y bind bind-libs bind-utils
首先,修改主配置文件/etc/named.conf
,注释掉仅允许本机查询请求和dnssec
(可能影响实验结果),并在监听地址列表中增加各自向外部提供服务的IP
地址。
options { listen-on port 53 { 127.0.0.1; 172.18.71.101; }; ... //allow-query { localhost; }; ... //dnssec-enable yes; //dnssec-validation yes; //dnssec-lookaside auto; ... };
在配置文件/etc/named.rfc1912.zones
中增加区域magedu.com
zone "magedu.com" IN { type master; file "magedu.com.zone"; allow-update { none; }; };
在/var/named/
目录中增加magedu.com
的区域解析数据库文件magedu.com.zone
[root@ns1 ~]# cd /var/named/ [root@ns1 named]# vim magedu.com.zone $TTL 1D @ IN SOA @ ns-admin.magedu.com. ( 2016040801 1D 1H 1W 3H ) IN NS ns1 IN MX 10 mx1 ns1 IN A 172.18.71.101 mx1 IN A 172.18.71.101 www IN A 172.18.71.101 www IN A 172.18.71.102 bbs IN CNAME www
改变区域解析数据库文件属组和权限
[root@ns1 named]# chgrp named magedu.com.zone [root@ns1 named]# chmod o= magedu.com.zone [root@ns1 named]# ls -al magedu.com.zone -rw-r----- 1 root named 213 Apr 8 21:29 magedu.com.zone
检查区域解析数据库文件和主配置文件的语法
[root@ns1 named]# named-checkzone magedu.com magedu.com.zone zone magedu.com/IN: loaded serial 2016040801 OK [root@ns1 named]# named-checkconf
启动服务
[root@ns1 named]# /etc/init.d/named start Generating /etc/rndc.key: [ OK ] Starting named: [ OK ]
使用dig
测试
[root@ns1 named]# dig -t A www.magedu.com @172.18.71.101 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6 <<>> -t A www.magedu.com @172.18.71.101 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56731 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.magedu.com. IN A ;; ANSWER SECTION: www.magedu.com. 3600 IN A 172.18.71.102 www.magedu.com. 3600 IN A 172.18.71.101 ;; AUTHORITY SECTION: magedu.com. 3600 IN NS ns1.magedu.com. ;; ADDITIONAL SECTION: ns1.magedu.com. 3600 IN A 172.18.71.101 ;; Query time: 0 msec ;; SERVER: 172.18.71.101#53(172.18.71.101) ;; WHEN: Fri Apr 8 21:37:34 2016 ;; MSG SIZE rcvd: 98
使用host
测试
[root@ns1 named]# host -t A bbs.magedu.com 172.18.71.101 Using domain server: Name: 172.18.71.101 Address: 172.18.71.101#53 Aliases: bbs.magedu.com is an alias for www.magedu.com. www.magedu.com has address 172.18.71.101 www.magedu.com has address 172.18.71.102
使用nslookup
测试(windows
一般使用此命令)
[root@ns1 named]# nslookup > server 172.18.71.101 Default server: 172.18.71.101 Address: 172.18.71.101#53 > set q=A > mx1.magedu.com Server: 172.18.71.101 Address: 172.18.71.101#53 Name: mx1.magedu.com Address: 172.18.71.101
在的配置文件/etc/named.rfc1912.zones
中增加区域71.18.172.in-addr.arpa
zone "71.18.172.in-addr.arpa" IN { type master; file "71.18.172.zone; allow-update { none; }; };
在/var/named/
目录中增加71.18.172.in-addr.arpa
的区域解析数据库文件71.18.172.zone
[root@ns1 ~]# cd /var/named/ [root@ns1 named]# vim 71.18.172.zone $TTL 1D @ IN SOA magedu.com. ns-admin.magedu.com. ( 2016040801 1D 1H 1W 3H ) IN NS ns1.magedu.com. 101 IN PTR ns1.magedu.com. 101 IN PTR mx1.magedu.com. 101 IN PTR www.magedu.com. 102 IN PTR www.magedu.com. 101 IN PTR bbs.magedu.com. 102 IN PTR bbs.magedu.com.
改变区域解析数据库文件属组和权限
[root@ns1 named]# chgrp named 71.18.172.zone [root@ns1 named]# chmod o= 71.18.172.zone [root@ns1 named]# ls -al 71.18.172.zone -rw-r----- 1 root named 275 Apr 8 21:59 71.18.172.zone
检查区域解析数据库文件和主配置文件的语法
[root@ns1 named]# named-checkzone 71.18.172.in-addr.arpa 71.18.172.zone zone 71.18.172.in-addr.arpa/IN: loaded serial 2016040801 OK [root@ns1 named]# named-checkconf
重载配置文件
[root@ns1 named]# rndc reload server reload successful 或者 [root@ns1 named]# /etc/init.d/named reload Reloading named: [ OK ]
使用dig
测试
[root@ns1 named]# dig -x 172.18.71.102 @172.18.71.101 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6 <<>> -x 172.18.71.102 @172.18.71.101 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6137 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;102.71.18.172.in-addr.arpa. IN PTR ;; ANSWER SECTION: 102.71.18.172.in-addr.arpa. 86400 IN PTR bbs.magedu.com. 102.71.18.172.in-addr.arpa. 86400 IN PTR www.magedu.com. ;; AUTHORITY SECTION: 71.18.172.in-addr.arpa. 86400 IN NS ns1.magedu.com. ;; ADDITIONAL SECTION: ns1.magedu.com. 3600 IN A 172.18.71.101 ;; Query time: 0 msec ;; SERVER: 172.18.71.101#53(172.18.71.101) ;; WHEN: Fri Apr 8 22:04:53 2016 ;; MSG SIZE rcvd: 124
使用host
测试
[root@ns1 named]# host 172.18.71.102 172.18.71.101 Using domain server: Name: 172.18.71.101 Address: 172.18.71.101#53 Aliases: 102.71.18.172.in-addr.arpa domain name pointer www.magedu.com. 102.71.18.172.in-addr.arpa domain name pointer bbs.magedu.com.
使用nslookup
测试
[root@ns1 named]# nslookup > server 172.18.71.101 Default server: 172.18.71.101 Address: 172.18.71.101#53 > set q=PTR > 172.18.71.102 Server: 172.18.71.101 Address: 172.18.71.101#53 102.71.18.172.in-addr.arpa name = bbs.magedu.com. 102.71.18.172.in-addr.arpa name = www.magedu.com.