dig - DNS lookup utility
当域名出现访问故障时,可以通过检查域名解析来判断是否是由错误的解析导致的问题。
1.域名解析无结果(不存在或被HOLD(未实名认证等))
2.域名解析到错误的IP(被阻断,被劫持响应错误结果,需要对解析流程做判断)
3.对应CNAME记录的值无法解析
4.部分解析异常(配置多个域名服务器时,多个服务器解析结果不一致,需要确认是否在DNS服务器上配置添加的解析记录一致)
简单使用解析一下www.baidu.com结果如下:
可以看到有请求段和应答段,最后解析出的A记录有两条。
dig命令做迭代查询
在命令后加上+trace可以跟踪整个解析流程:
1. 由根域名服务器查找到负责解析.com的顶级域名服务器
2. 由顶级域名服务器查找到baidu.com的二级域名服务器
3. 由二级域名服务器查找到www.baidu.com对应一条CNAME记录www.a.shifen.com
4. 再去查找www.a.shifen.com对应的A记录
5. 最后返回A记录对应的IP地址
[root@jia3 ~]# dig www.baidu.com +trace
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> www.baidu.com +trace
;; global options: +cmd
. 320307 IN NS a.root-servers.net.
. 320307 IN NS k.root-servers.net.
. 320307 IN NS i.root-servers.net.
. 320307 IN NS l.root-servers.net.
. 320307 IN NS b.root-servers.net.
. 320307 IN NS e.root-servers.net.
. 320307 IN NS h.root-servers.net.
. 320307 IN NS d.root-servers.net.
. 320307 IN NS g.root-servers.net.
. 320307 IN NS j.root-servers.net.
. 320307 IN NS f.root-servers.net.
. 320307 IN NS m.root-servers.net.
. 320307 IN NS c.root-servers.net.
;; Received 228 bytes from 202.106.0.20#53(202.106.0.20) in 98 ms
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
;; Received 491 bytes from 192.5.5.241#53(192.5.5.241) in 93 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.48.79.30#53(192.48.79.30) in 501 ms
www.baidu.com. 1200 IN CNAME www.a.shifen.com.
a.shifen.com. 1200 IN NS ns1.a.shifen.com.
a.shifen.com. 1200 IN NS ns2.a.shifen.com.
a.shifen.com. 1200 IN NS ns5.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 8 ms
域名不存在时,dig命令如何返回
比如解析 www.not-exists-domain.com这个域名,是不存在的。
整个过程如下:
1. 由根域名返回.com顶级域的服务器地址
2. 由.com顶级域查到二级域名不存在,返回一条SOA记录
[root@jia3 ~]# dig www.not-exists-domain.com +trace
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> www.not-exists-domain.com +trace
;; global options: +cmd
. 319714 IN NS b.root-servers.net.
. 319714 IN NS e.root-servers.net.
. 319714 IN NS h.root-servers.net.
. 319714 IN NS d.root-servers.net.
. 319714 IN NS g.root-servers.net.
. 319714 IN NS j.root-servers.net.
. 319714 IN NS f.root-servers.net.
. 319714 IN NS m.root-servers.net.
. 319714 IN NS c.root-servers.net.
. 319714 IN NS a.root-servers.net.
. 319714 IN NS k.root-servers.net.
. 319714 IN NS i.root-servers.net.
. 319714 IN NS l.root-servers.net.
;; Received 228 bytes from 202.106.0.20#53(202.106.0.20) in 105 ms
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
;; Received 503 bytes from 192.112.36.4#53(192.112.36.4) in 228 ms
com. 900 IN SOA a.gtld-servers.net. nstld.verisign-grs.com. 1524576381 1800 900 604800 86400
;; Received 116 bytes from 192.12.94.30#53(192.12.94.30) in 333 ms
nslookup - query Internet name servers interactively
nslookup有交互式和非交互式两种使用方式如下图:
nslookup还可以指定到某个域名服务器做解析命令格式如下:
nslookup www.baidu.com 8.8.8.8(域名服务器地址)