1.主从DNS:
主DNS:进行数据修改并在修改后主动向从DNS发送数据已经更新的信息;
从DNS:主动请主DNS进行数据同步;
2.从DNS区域数据文件中:
type slave;
master {主DNS服务器IP地址;}; #从哪一台主DNS服务器中同步数据
3.DNS服务器建立后不应该给所有的用户进行递归,如果用户把他的DNS指向我们的DNS服务器并且要求递归时,用户若是发起恶意查询和攻击的话,我们的DNS服务器可能就会很快挂掉,因此不应该给所有的用户递归的,也就是说如果用户请求解析的是我们的DNS服务器负责的mageedu.com域中的,那么我们可以为其解析。但是如果请求的是,而sohu.com域不是我们所负责的域那么我们就有可能为其递归了,因此,可以为谁递归我们应该定义好;
4.配置文件中的全局段常用参数:
forwarders {IP;}; #DNS转发,指定其上级域名服务器
allow-query { IP; }; #指定允许提交查询的客户端,如不指定默认是所有查询
recursion yes|no; #是否递归,默认开启递归
allow-recursion {IP;}; #通过ip(段)限制谁可以进行递归
5.测试递归
5.1 默认情况下是递归查询的
[root@localhost named]# dig -t A
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.3 <<>> -t A
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5457
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 7, ADDITIONAL: 0
;; QUESTION SECTION:
;. IN A
;; ANSWER SECTION:
. 5 IN CNAME gs.a.sohu.com.
gs.a.sohu.com. 5 IN CNAME fzz.a.sohu.com.
fzz.a.sohu.com. 5 IN A 61.158.246.131
;; AUTHORITY SECTION:
a.sohu.com. 5 IN NS s.a.sohu.com.
a.sohu.com. 5 IN NS v.a.sohu.com.
a.sohu.com. 5 IN NS w.a.sohu.com.
a.sohu.com. 5 IN NS x.a.sohu.com.
a.sohu.com. 5 IN NS y.a.sohu.com.
a.sohu.com. 5 IN NS z.a.sohu.com.
a.sohu.com. 5 IN NS k.a.sohu.com.
;; Query time: 11 msec
;; SERVER: 192.168.85.2#53(192.168.85.2)
;; WHEN: Fri Jul 31 05:44:12 2015
;; MSG SIZE rcvd: 195
5.2 允许递归情况下和默认情况下一样
[root@localhost named]# dig +recurse -t A @192.168.85.128
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.3 <<>> +recurse -t A
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58326
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 7, ADDITIONAL: 0
;; QUESTION SECTION:
;. IN A
;; ANSWER SECTION:
. 5 IN CNAME gs.a.sohu.com.
gs.a.sohu.com. 5 IN CNAME fzz.a.sohu.com.
fzz.a.sohu.com. 5 IN A 61.158.246.131
;; AUTHORITY SECTION:
a.sohu.com. 5 IN NS w.a.sohu.com.
a.sohu.com. 5 IN NS x.a.sohu.com.
a.sohu.com. 5 IN NS y.a.sohu.com.
a.sohu.com. 5 IN NS z.a.sohu.com.
a.sohu.com. 5 IN NS k.a.sohu.com.
a.sohu.com. 5 IN NS s.a.sohu.com.
a.sohu.com. 5 IN NS v.a.sohu.com.
;; Query time: 9 msec
;; SERVER: 192.168.85.2#53(192.168.85.2)
;; WHEN: Fri Jul 31 05:45:46 2015
;; MSG SIZE rcvd: 195
5.3 不允许递归情况下
[root@localhost named]# dig +norecurse -t A @192.168.85.128
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.3 <<>> +norecurse -t A
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54336
;; flags: qr ra; QUERY: 1, ANSWER: 3, AUTHORITY: 7, ADDITIONAL: 0
;; QUESTION SECTION:
;. IN A
;; ANSWER SECTION: #这里出现结果是因为本机已经有了缓存了,所以还能查到
. 5 IN CNAME gs.a.sohu.com.
gs.a.sohu.com. 5 IN CNAME fzz.a.sohu.com.
fzz.a.sohu.com. 5 IN A 61.158.246.131
;; AUTHORITY SECTION:
a.sohu.com. 5 IN NS v.a.sohu.com.
a.sohu.com. 5 IN NS w.a.sohu.com.
a.sohu.com. 5 IN NS x.a.sohu.com.
a.sohu.com. 5 IN NS y.a.sohu.com.
a.sohu.com. 5 IN NS z.a.sohu.com.
a.sohu.com. 5 IN NS k.a.sohu.com.
a.sohu.com. 5 IN NS s.a.sohu.com.
;; Query time: 13 msec
;; SERVER: 192.168.85.2#53(192.168.85.2)
;; WHEN: Fri Jul 31 05:47:04 2015
;; MSG SIZE rcvd: 195
换一个测试不允许递归的情况
[root@localhost named]# dig +norecurse -t A @192.168.85.128
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.3 <<>> +norecurse -t A @192.168.85.128
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63500
;; flags: qr ra; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 14
;; QUESTION SECTION:
;. IN A
;; AUTHORITY SECTION:
com. 172057 IN NS i.gtld-servers.net.
com. 172057 IN NS d.gtld-servers.net.
com. 172057 IN NS m.gtld-servers.net.
com. 172057 IN NS h.gtld-servers.net.
com. 172057 IN NS k.gtld-servers.net.
com. 172057 IN NS l.gtld-servers.net.
com. 172057 IN NS f.gtld-servers.net.
com. 172057 IN NS g.gtld-servers.net.
com. 172057 IN NS e.gtld-servers.net.
com. 172057 IN NS a.gtld-servers.net.
com. 172057 IN NS b.gtld-servers.net.
com. 172057 IN NS c.gtld-servers.net.
com. 172057 IN NS j.gtld-servers.net.
;; ADDITIONAL SECTION:
f.gtld-servers.net. 172057 IN A 192.35.51.30
e.gtld-servers.net. 172057 IN A 192.12.94.30
b.gtld-servers.net. 172057 IN A 192.33.14.30
b.gtld-servers.net. 172057 IN AAAA 2001:503:231d::2:30
k.gtld-servers.net. 172057 IN A 192.52.178.30
i.gtld-servers.net. 172057 IN A 192.43.172.30
j.gtld-servers.net. 172057 IN A 192.48.79.30
g.gtld-servers.net. 172057 IN A 192.42.93.30
d.gtld-servers.net. 172057 IN A 192.31.80.30
a.gtld-servers.net. 172057 IN A 192.5.6.30
a.gtld-servers.net. 172057 IN AAAA 2001:503:a83e::2:30
m.gtld-servers.net. 172057 IN A 192.55.83.30
c.gtld-servers.net. 172057 IN A 192.26.92.30
h.gtld-servers.net. 172057 IN A 192.54.112.30
;; Query time: 5 msec
;; SERVER: 192.168.85.128#53(192.168.85.128)
;; WHEN: Fri Jul 31 05:49:58 2015
;; MSG SIZE rcvd: 503
这里没有递归,所以去查根了,而根告诉我们他属于.com
从.com的服务器中找一个出来查
[root@localhost named]# dig +norecurse -t A @i.gtld-servers.net.
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.3 <<>> +norecurse -t A @i.gtld-servers.net.
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38757
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 5, ADDITIONAL: 5
;; QUESTION SECTION:
;. IN A
;; AUTHORITY SECTION:
baidu.com. 172800 IN NS dns.baidu.com.
baidu.com. 172800 IN NS ns2.baidu.com.
baidu.com. 172800 IN NS ns3.baidu.com.
baidu.com. 172800 IN NS ns4.baidu.com.
baidu.com. 172800 IN NS ns7.baidu.com.
;; ADDITIONAL SECTION:
dns.baidu.com. 172800 IN A 202.108.22.220
ns2.baidu.com. 172800 IN A 61.135.165.235
ns3.baidu.com. 172800 IN A 220.181.37.10
ns4.baidu.com. 172800 IN A 220.181.38.10
ns7.baidu.com. 172800 IN A 119.75.219.82
;; Query time: 87 msec
;; SERVER: 192.43.172.30#53(192.43.172.30)
;; WHEN: Fri Jul 31 05:55:48 2015
;; MSG SIZE rcvd: 201
这里.com告诉我们他属于baidu.com(这里得到的只是baidu.com并不是最终结果),然后再从baidu.com服务器中找一出来查
[root@localhost named]# dig +norecurse -t A @dns.baidu.com.
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.3 <<>> +norecurse -t A @dns.baidu.com.
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43157
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 5, ADDITIONAL: 5
;; QUESTION SECTION:
;. IN A
;; ANSWER SECTION:
. 1200 IN CNAME />
;; AUTHORITY SECTION:
a.shifen.com. 1200 IN NS ns2.a.shifen.com.
a.shifen.com. 1200 IN NS ns1.a.shifen.com.
a.shifen.com. 1200 IN NS ns4.a.shifen.com.
a.shifen.com. 1200 IN NS ns3.a.shifen.com.
a.shifen.com. 1200 IN NS ns5.a.shifen.com.
;; ADDITIONAL SECTION:
ns1.a.shifen.com. 1200 IN A 61.135.165.224
ns2.a.shifen.com. 1200 IN A 180.149.133.241
ns3.a.shifen.com. 1200 IN A 61.135.162.215
ns4.a.shifen.com. 1200 IN A 115.239.210.176
ns5.a.shifen.com. 1200 IN A 119.75.222.17
;; Query time: 29 msec
;; SERVER: 202.108.22.220#53(202.108.22.220)
;; WHEN: Fri Jul 31 06:00:24 2015
;; MSG SIZE rcvd: 228
好了,到了这里查到了
当然也可以加trace跟踪查询过程,这样更简单易懂
[root@localhost named]# dig +trace -t A @192.168.85.128
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.3 <<>> +trace -t A @192.168.85.128
;; global options: +cmd
. 505506 IN NS a.root-servers.net.
. 505506 IN NS j.root-servers.net.
. 505506 IN NS k.root-servers.net.
. 505506 IN NS d.root-servers.net.
. 505506 IN NS h.root-servers.net.
. 505506 IN NS f.root-servers.net.
. 505506 IN NS i.root-servers.net.
. 505506 IN NS b.root-servers.net.
. 505506 IN NS l.root-servers.net.
. 505506 IN NS c.root-servers.net.
. 505506 IN NS g.root-servers.net.
. 505506 IN NS m.root-servers.net.
. 505506 IN NS e.root-servers.net.
;; Received 508 bytes from 192.168.85.128#53(192.168.85.128) in 490 ms
com. 172800 IN NS m.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
;; Received 503 bytes from 192.5.5.241#53(192.5.5.241) in 3353 ms
baidu.com. 172800 IN NS dns.baidu.com.
baidu.com. 172800 IN NS ns2.baidu.com.
baidu.com. 172800 IN NS ns3.baidu.com.
baidu.com. 172800 IN NS ns4.baidu.com.
baidu.com. 172800 IN NS ns7.baidu.com.
;; Received 201 bytes from 192.35.51.30#53(192.35.51.30) in 395 ms
. 1200 IN CNAME />
a.shifen.com. 1200 IN NS ns5.a.shifen.com.
a.shifen.com. 1200 IN NS ns2.a.shifen.com.
a.shifen.com. 1200 IN NS ns1.a.shifen.com.
a.shifen.com. 1200 IN NS ns3.a.shifen.com.
a.shifen.com. 1200 IN NS ns4.a.shifen.com.
;; Received 228 bytes from 220.181.37.10#53(220.181.37.10) in 24 ms
阅读(1770) | 评论(0) | 转发(0) |