DNS诊断工具dig的详细使用方法

Windows admin 134℃ 1评论

dig工具是一个十分强大的DNS诊断和查询工具,我们可以查询DNS的NS记录,A记录,MX记录等相关记录信息。上篇文章讲了如何在windows环境下安装dig工具以及简单的使用 ,下面我来为大家讲一下dig工具的详细使用方法。

1.查询A记录:

命令格式:dig domain a

example: dig geekeden.net a
C:\Users\jerry>dig geekeden.net a

; <<>> DiG 9.11.2 <<>> geekeden.net a
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47267
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;geekeden.net.                  IN      A

;; ANSWER SECTION:
geekeden.net.           599     IN      A       148.66.136.214

;; Query time: 125 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Aug 31 09:32:12 China Standard Time 2017
;; MSG SIZE  rcvd: 57

2.查询NS记录

dig geekeden.net ns

C:\Users\jerry>dig geekeden.net ns

; <<>> DiG 9.11.2 <<>> geekeden.net ns
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50179
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;geekeden.net.                  IN      NS

;; ANSWER SECTION:
geekeden.net.           3599    IN      NS      ns14.domaincontrol.com.
geekeden.net.           3599    IN      NS      ns13.domaincontrol.com.

;; Query time: 93 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Aug 31 09:34:53 China Standard Time 2017
;; MSG SIZE  rcvd: 96

3.查询MX邮件记录

dig geekeden.net mx

C:\Users\jerry>dig geekeden.net mx

; <<>> DiG 9.11.2 <<>> geekeden.net mx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29377
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;geekeden.net.                  IN      MX

;; ANSWER SECTION:
geekeden.net.           3599    IN      MX      0 smtp.secureserver.net.
geekeden.net.           3599    IN      MX      10 mailstore1.secureserver.net.

;; Query time: 78 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Aug 31 09:35:38 China Standard Time 2017
;; MSG SIZE  rcvd: 102

4.查询所有DNS记录

dig geekeden.net ANY

C:\Users\jerry>dig geekeden.net ANY

; <<>> DiG 9.11.2 <<>> geekeden.net ANY
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16925
;; flags: qr rd ra; QUERY: 1, ANSWER: 7, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;geekeden.net.                  IN      ANY

;; ANSWER SECTION:
geekeden.net.           599     IN      A       148.66.136.214
geekeden.net.           3599    IN      NS      ns13.domaincontrol.com.
geekeden.net.           3599    IN      NS      ns14.domaincontrol.com.
geekeden.net.           599     IN      SOA     ns13.domaincontrol.com. dns.jomax.net. 2017082414 28800 7200 604800 600
geekeden.net.           3599    IN      MX      0 smtp.secureserver.net.
geekeden.net.           3599    IN      MX      10 mailstore1.secureserver.net.
geekeden.net.           3599    IN      TXT     "v=spf1 a mx ptr include:secureserver.net ~all"

;; Query time: 187 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Aug 31 09:36:15 China Standard Time 2017
;; MSG SIZE  rcvd: 277

5.查询IPv6 AAAA记录

dig geekeden.net AAAA

C:\Users\jerry>dig geekeden.net AAAA

; <<>> DiG 9.11.2 <<>> geekeden.net AAAA
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62247
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;geekeden.net.                  IN      AAAA

;; AUTHORITY SECTION:
geekeden.net.           599     IN      SOA     ns13.domaincontrol.com. dns.jomax.net. 2017082414 28800 7200 604800 600

;; Query time: 78 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Aug 31 09:37:05 China Standard Time 2017
;; MSG SIZE  rcvd: 109

6.查询反向记录

已知ip地址,查询该IP绑定的域名,反向解析都是IP的实际所有者即一级运营商来做,与域名注册商、DNS服务提供商无关。
命令格式:dig -x ip

例:dig  -x 114.114.114.114 (查询114.114.114.114.114的域名)
C:\Users\jerry>dig -x 114.114.114.114

; <<>> DiG 9.11.2 <<>> -x 114.114.114.114
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37196
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;114.114.114.114.in-addr.arpa.  IN      PTR

;; ANSWER SECTION:
114.114.114.114.in-addr.arpa. 482 IN    PTR     public1.114dns.com.

;; Query time: 48 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Aug 31 11:01:06 China Standard Time 2017
;; MSG SIZE  rcvd: 89

大家可能会发现一个问题,每次使用dig命令时就会有很多的输出信息,可以使用以下命令“+short”来精简的输出dig查询结果:

C:\Users\jerry>dig geekeden.net ns +short
ns14.domaincontrol.com.
ns13.domaincontrol.com.

指定查询DNS服务器

前一篇文章中介绍了指定域名查询DNS服务器的设置方法(通过添加resolv.conf文件的方式),今天介绍另外一种方式:在dig命令中添加“@server”字段来快速指定查询DNS服务器
命令格式:dig @server domain any

例:dig @114.114.114.114 geekeden.net any //强制指定查询DNS服务器为114.114.114.114 C:\Users\jerry>dig @114.114.114.114 geekeden.net any

; <<>> DiG 9.11.2 <<>> @114.114.114.114 geekeden.net any
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58269
;; flags: qr rd ra; QUERY: 1, ANSWER: 7, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: f92ebc1b0dfa7661 (echoed)
;; QUESTION SECTION:
;geekeden.net.                  IN      ANY

;; ANSWER SECTION:
geekeden.net.           3594    IN      TXT     "v=spf1 a mx ptr include:secureserver.net ~all"
geekeden.net.           3594    IN      MX      10 mailstore1.secureserver.net.
geekeden.net.           3594    IN      MX      0 smtp.secureserver.net.
geekeden.net.           594     IN      SOA     ns13.domaincontrol.com. dns.jomax.net. 2017082414 28800 7200 604800 600
geekeden.net.           594     IN      A       148.66.136.214
geekeden.net.           3594    IN      NS      ns13.domaincontrol.com.
geekeden.net.           3594    IN      NS      ns14.domaincontrol.com.

;; Query time: 16 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: Thu Aug 31 10:43:06 China Standard Time 2017
;; MSG SIZE  rcvd: 289

©声明:本站原创文章采用 BY-NC-SA 创作共用协议,转载时请标明原文地址。
©转载请注明:
极客乐园 » DNS诊断工具dig的详细使用方法

喜欢 (0)or分享 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(1)个小伙伴在吐槽
  1. 评论测试,头像测试,效果测试
    admin2017-09-01 23:55 回复

极客乐园 —— 网络技术学习分享的伊甸园

感谢又拍云赞助图片加速又拍云