一、正向解析
1、安装
yum install -y bind
2、编辑配置文件
vim /etc/named.conf
添加
zone "123.com" IN {
type master;
file "123.com.zone";
};
3、编辑123.zone文件
vim /var/named/123.com.zone
$TTL 1D
@ IN SOA @ admin.123.com. (
2016060301 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS ns.123.com.
IN MX 5 mail.123.com.
mail IN A 10.10.13.248
ns IN A 10.10.13.247
www IN A 11.11.11.11
bbs IN CNAME www
4、重启服务测试
/etc/init.d/named restart
dig @10.10.13.247 www.123.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> @10.10.13.247 www.123.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11907
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;www.123.com. IN A
;; ANSWER SECTION:
www.123.com. 86400 IN A 11.11.11.11
;; AUTHORITY SECTION:
123.com. 86400 IN NS ns.123.com.
;; ADDITIONAL SECTION:
ns.123.com. 86400 IN A 10.10.13.247
;; Query time: 0 msec
;; SERVER: 10.10.13.247#53(10.10.13.247)
;; WHEN: Fri Jun 3 10:49:35 2016
;; MSG SIZE rcvd: 78
二、反向解析
1、编辑配置文件
vim /etc/named.conf
添加
zone "13.10.10.in-addr.arpa" IN {
type master;
file "13.10.10.zone";
};
2、编辑zone文件
vim /var/named/13.10.10.zone
$TTL 1D
@ IN SOA @ admin.123.com. (
2016060301 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS ns.123.com.
247 IN PTR ns.123.com.
248 IN PTR mail.123.com.
3、重启测试
/etc/init.d/named restart
dig @10.10.13.247 -x 10.10.13.248
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> @10.10.13.247 -x 10.10.13.248
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64644
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;248.13.10.10.in-addr.arpa. IN PTR
;; ANSWER SECTION:
248.13.10.10.in-addr.arpa. 86400 IN PTR mail.123.com.
;; AUTHORITY SECTION:
13.10.10.in-addr.arpa. 86400 IN NS ns.123.com.
;; ADDITIONAL SECTION:
ns.123.com. 86400 IN A 10.10.13.247
;; Query time: 1 msec
;; SERVER: 10.10.13.247#53(10.10.13.247)
;; WHEN: Fri Jun 3 10:53:14 2016
;; MSG SIZE rcvd: 102
三、dns主从配置
1、在从服务器上安装bind程序并配置
[root@redhat01 ~]# yum install -y bind
[root@redhat01 ~]# vim /etc/named.conf
// listen-on port 53 { 127.0.0.1; };
// listen-on-v6 port 53 { ::1; }; #用//注释掉这两行
添加以下
zone "123.com" IN {
type slave;
file "slaves/123.com.zone";
masters { 10.10.13.247; };
};
zone "13.10.10.in-addr.arpa" IN {
type slave;
file "slaves/13.10.10.zone";
masters { 10.10.13.247; };
};
2、启动从服务器的bind服务
/etc/init.d/named start
3、验证主从
[root@redhat01 ~]# ls /var/named/slaves/
123.com.zone 13.10.10.zone
#/var/named/slaves/底下已经生成两个zone文件
查看zone文件跟主服务器一样
4、验证正向解析
[root@redhat01 slaves]# dig @10.10.13.248 www.123.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> @10.10.13.248 www.123.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11713
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;www.123.com. IN A
;; ANSWER SECTION:
www.123.com. 86400 IN A 11.11.11.11
;; AUTHORITY SECTION:
123.com. 86400 IN NS ns.123.com.
;; ADDITIONAL SECTION:
ns.123.com. 86400 IN A 10.10.13.247
;; Query time: 1 msec
;; SERVER: 10.10.13.248#53(10.10.13.248)
;; WHEN: Fri Jun 3 11:18:11 2016
5、验证反解析
[root@redhat01 slaves]# dig @10.10.13.248 -x 10.10.13.248
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> @10.10.13.248 -x 10.10.13.248
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9372
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;248.13.10.10.in-addr.arpa. IN PTR
;; ANSWER SECTION:
248.13.10.10.in-addr.arpa. 86400 IN PTR mail.123.com.
;; AUTHORITY SECTION:
13.10.10.in-addr.arpa. 86400 IN NS ns.123.com.
;; ADDITIONAL SECTION:
ns.123.com. 86400 IN A 10.10.13.247
;; Query time: 0 msec
;; SERVER: 10.10.13.248#53(10.10.13.248)
;; WHEN: Fri Jun 3 11:18:41 2016
;; MSG SIZE rcvd: 102
四、设置当主服务器变化时从服务器立刻更新主服务器配置
1、在主服务器上编辑配置文件
vim /etc/named.conf
修改zone "123.com" IN {
type master;
file "123.com.zone";
};
zone "13.10.10.in-addr.arpa" IN {
type master;
file "13.10.10.zone";
};
改为:
zone "123.com" IN {
type master;
file "123.com.zone";
notify yes;
also-notify { 10.10.13.248;};
};
zone "13.10.10.in-addr.arpa" IN {
type master;
file "13.10.10.zone";
notify yes;
also-notify { 10.10.13.248;};
};
#添加notify yes;
also-notify ( 10.10.13.248;);表示当主服务器更新数据时从服务器立即复制主服务器数据
2、在主服务器上修改zone文件的序列号并添加一条记录
vim /var/named/slaves/123.com.zone
将 2016060301 ; serial
改为 2016060302 ; serial
添加记录
river A 111.111.111.111
2、重启主服务器测试解析
/etc/init.d/named restart
dig @10.10.13.247 river.123.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> @10.10.13.247 river.123.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5069
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;river.123.com. IN A
;; ANSWER SECTION:
river.123.com. 86400 IN A 111.111.111.111
;; AUTHORITY SECTION:
123.com. 86400 IN NS ns.123.com.
;; ADDITIONAL SECTION:
ns.123.com. 86400 IN A 10.10.13.247
;; Query time: 0 msec
;; SERVER: 10.10.13.247#53(10.10.13.247)
;; WHEN: Fri Jun 3 11:50:00 2016
;; MSG SIZE rcvd: 80
3、查看从服务器配置及解析
cat /var/named/slaves/123.com.zone
$ORIGIN .
$TTL 86400 ; 1 day
123.com IN SOA 123.com. admin.123.com. (
2016060302 ; serial
86400 ; refresh (1 day)
3600 ; retry (1 hour)
604800 ; expire (1 week)
10800 ; minimum (3 hours)
)
NS ns.123.com.
MX 5 mail.123.com.
$ORIGIN 123.com.
bbs CNAME www
mail A 10.10.13.248
ns A 10.10.13.247
river A 111.111.111.111
www A 11.11.11.11
#已经更改序列号和添加一条river.123.com记录
[root@redhat01 slaves]# dig @10.10.13.248 river.123.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> @10.10.13.248 river.123.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3135
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;river.123.com. IN A
;; ANSWER SECTION:
river.123.com. 86400 IN A 111.111.111.111
;; AUTHORITY SECTION:
123.com. 86400 IN NS ns.123.com.
;; ADDITIONAL SECTION:
ns.123.com. 86400 IN A 10.10.13.247
;; Query time: 59 msec
;; SERVER: 10.10.13.248#53(10.10.13.248)
;; WHEN: Fri Jun 3 11:52:01 2016
;; MSG SIZE rcvd: 80
#可以解析主服务器新增加的记录
本文出自 “愺艮搥豩” 博客,请务必保留此出处http://riverxyz.blog.51cto.com/533303/1785765
原文地址:http://riverxyz.blog.51cto.com/533303/1785765