dig命令用于测试dns系统(不会查询hosts文件中的解析)
安装dig命令:yum install bind-utils -y
dig命令语法:dig [-t TYPE] name [@SERVER] [+trace]
[-t TYPE]:表示解析类型
[@SERVER]:表示以指定的DNS服务器进行解析,如果不写,则以本机上配置DNS进行解析
[+trace]:表示跟踪解析过程,可不写
示例:dig -t A www.baidu.com
返回结果解释:
[root@dns-master named]# dig -t A www.baidu.com ; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> -t A www.baidu.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15788 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;www.baidu.com. IN A ;; ANSWER SECTION: www.baidu.com. 380 IN CNAME www.a.shifen.com. www.a.shifen.com. 300 IN A 115.239.210.27 www.a.shifen.com. 300 IN A 115.239.211.112 ;; Query time: 18 msec ;; SERVER: 114.114.114.114#53(114.114.114.114) ;; WHEN: Sat Jun 01 15:23:47 CST 2019 ;; MSG SIZE rcvd: 90
flags:如果有aa,表示权威回答;如果没有aa表示非权威回答;上例中即非权威回答;可能使用了dns缓存;
QUESTION SECTION:表示问题部分,即你咨询的内容
ANSWER SECTION:表示针对你的问题,返回的解析结果;
AUTHORITY SECTION:表示权威回答,由哪些DNS服务器进行响应;
ADDITIONAL SECTION:表示如果是权威回答,额外返回更多的解析信息,返回响应的DNS服务器的解析A记录;
增加@SERVER结果演示:
[root@dns-master named]# dig -t A www.51yunv.com @192.168.1.115 ; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> -t A www.51yunv.com @192.168.1.115 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17389 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.51yunv.com. IN A ;; ANSWER SECTION: www.51yunv.com. 86400 IN A 192.168.1.116 ;; AUTHORITY SECTION: 51yunv.com. 86400 IN NS ns1.51yunv.com. 51yunv.com. 86400 IN NS ns2.51yunv.com. ;; ADDITIONAL SECTION: ns1.51yunv.com. 86400 IN A 192.168.1.114 ns2.51yunv.com. 86400 IN A 192.168.1.115 ;; Query time: 0 msec ;; SERVER: 192.168.1.115#53(192.168.1.115) ;; WHEN: Sat Jun 01 15:21:39 CST 2019 ;; MSG SIZE rcvd: 127
此例中flags中有aa,表示为权威回答;
增加+trace解析结果:
[root@shvpuppet01 ~]# dig -t A www.baidu.com +trace ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6 <<>> -t A www.baidu.com +trace ;; global options: +cmd . 3600 IN NS b.root-servers.net. . 3600 IN NS c.root-servers.net. . 3600 IN NS d.root-servers.net. . 3600 IN NS e.root-servers.net. . 3600 IN NS f.root-servers.net. . 3600 IN NS g.root-servers.net. . 3600 IN NS h.root-servers.net. . 3600 IN NS i.root-servers.net. . 3600 IN NS j.root-servers.net. . 3600 IN NS k.root-servers.net. . 3600 IN NS l.root-servers.net. . 3600 IN NS m.root-servers.net. . 3600 IN NS a.root-servers.net. ;; Received 257 bytes from 10.10.2.98#53(10.10.2.98) in 3954 ms com. 172800 IN NS a.gtld-servers.net. com. 172800 IN NS b.gtld-servers.net. com. 172800 IN NS c.gtld-servers.net. com. 172800 IN NS d.gtld-servers.net. com. 172800 IN NS e.gtld-servers.net. com. 172800 IN NS f.gtld-servers.net. com. 172800 IN NS g.gtld-servers.net. com. 172800 IN NS h.gtld-servers.net. com. 172800 IN NS i.gtld-servers.net. com. 172800 IN NS j.gtld-servers.net. com. 172800 IN NS k.gtld-servers.net. com. 172800 IN NS l.gtld-servers.net. com. 172800 IN NS m.gtld-servers.net. ;; Received 491 bytes from 199.7.91.13#53(199.7.91.13) in 260 ms 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 ns1.baidu.com. baidu.com. 172800 IN NS ns7.baidu.com. ;; Received 201 bytes from 192.41.162.30#53(192.41.162.30) in 341 ms www.baidu.com. 1200 IN CNAME www.a.shifen.com. 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 ns3.a.shifen.com. a.shifen.com. 1200 IN NS ns4.a.shifen.com. a.shifen.com. 1200 IN NS ns1.a.shifen.com. ;; Received 228 bytes from 202.108.22.220#53(202.108.22.220) in 25 ms
可以看到解析过程为:从根DNS服务器中找com.,从com.的DNS服务器中找baidu.com.,从baidu.com.的DNS服务器中找www.baidu.com.