首页 » 信息技术 »

用dig命令查询DNS信息

2017年8月5日 / 116次阅读
DNS

Linux下的dig命令(Domain Information Groper),可以用来进行DNS信息的查询。

dig命令与Win系统下的nslookup命令相似,它是Linux下默认安装的工具,而且dig比nslookup要强大不少。

dig 命令是常用的域名查询工具,可以用来测试域名系统工作是否正常。域名服务器(DNS)有助于将 URL 解析为一组应用程序服务器。然而,你会发现有些 URL 不能被解析,这会导致应用程序的连接问题。例如,假如你尝试从应用程序的主机访问你的数据库。你收到一个"不能解析"的错误。要进行故障排查,你尝试使用 dig来确定应用程序似乎无法解析数据的原因。

查询一个域名:

[xinlin@lamptest ~]$ dig www.maixj.net

; <<>> DiG 9.9.4-RedHat-9.9.4-74.el7_6.1 <<>> www.maixj.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54316
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; MBZ: 0005 , udp: 512
;; QUESTION SECTION:
;www.maixj.net.                 IN      A

;; ANSWER SECTION:
www.maixj.net.          5       IN      A       114.215.183.12

;; Query time: 456 msec
;; SERVER: 192.168.75.2#53(192.168.75.2)
;; WHEN: Sun Jul 28 19:07:05 CST 2019
;; MSG SIZE  rcvd: 58

dig命令,默认就是查询域名的A记录。返回的信息能够看到查询所花费的时间,这个信息是nslookup没有的。

指定域名服务器,指定查询类型:

[xinlin@lamptest ~]$ dig @8.8.8.8 qq.com MX

; <<>> DiG 9.9.4-RedHat-9.9.4-74.el7_6.1 <<>> @8.8.8.8 qq.com MX
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23394
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

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

;; ANSWER SECTION:
qq.com.                 7199    IN      MX      20 mx2.qq.com.
qq.com.                 7199    IN      MX      30 mx1.qq.com.
qq.com.                 7199    IN      MX      10 mx3.qq.com.

;; Query time: 374 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Jul 28 19:10:04 CST 2019
;; MSG SIZE  rcvd: 95

用Google DNS 8.8.8.8,查询qq.com的MX记录。

跟踪域名解析的全过程:

[xinlin@lamptest ~]$ dig +trace www.pynote.net

; <<>> DiG 9.9.4-RedHat-9.9.4-74.el7_6.1 <<>> +trace www.pynote.net
;; global options: +cmd
.                       5       IN      NS      e.root-servers.net.
.                       5       IN      NS      h.root-servers.net.
.                       5       IN      NS      l.root-servers.net.
.                       5       IN      NS      i.root-servers.net.
.                       5       IN      NS      a.root-servers.net.
.                       5       IN      NS      d.root-servers.net.
.                       5       IN      NS      c.root-servers.net.
.                       5       IN      NS      b.root-servers.net.
.                       5       IN      NS      j.root-servers.net.
.                       5       IN      NS      k.root-servers.net.
.                       5       IN      NS      g.root-servers.net.
.                       5       IN      NS      m.root-servers.net.
.                       5       IN      NS      f.root-servers.net.
.                       5       IN      RRSIG   NS 8 0 518400 20190808050000 20190726040000 59944 . WJMZTyduj8nxjmFDuGEI1J7rrGVqpxIsz/7RwvuehGMfzv/Lsz74nrSR 7cpctJns+9QVmO+FH3aIvGdtbEu5zDHW7ch1Tre1C5j+RC31TToo6dSd n9TpEtv0B4Ll3IlQXdiF7Ir75IysFdWVrmg9P3Rp1z6HO/iqVuW5P2nJ wom2SbRA/LFsG1qoySgA/Wt0stxI1e4e6UZuqRQtXqqoAqKIRcvFY+dS H2Woi4FzCcVeLZhelOeTV60he2FNJAtvpkYnkhgIpRsWEJLyfNdeWsb0 lZEFmXCNk8cJaRneqfjk1zo+6psWYnIeYZfY3dp0th5vq/5Dc8zmhacH 1CqLRg==
;; Received 525 bytes from 192.168.75.2#53(192.168.75.2) in 5588 ms

net.                    172800  IN      NS      m.gtld-servers.net.
net.                    172800  IN      NS      b.gtld-servers.net.
net.                    172800  IN      NS      g.gtld-servers.net.
net.                    172800  IN      NS      e.gtld-servers.net.
net.                    172800  IN      NS      k.gtld-servers.net.
net.                    172800  IN      NS      j.gtld-servers.net.
net.                    172800  IN      NS      f.gtld-servers.net.
net.                    172800  IN      NS      l.gtld-servers.net.
net.                    172800  IN      NS      c.gtld-servers.net.
net.                    172800  IN      NS      h.gtld-servers.net.
net.                    172800  IN      NS      d.gtld-servers.net.
net.                    172800  IN      NS      a.gtld-servers.net.
net.                    172800  IN      NS      i.gtld-servers.net.
net.                    86400   IN      DS      35886 8 2 7862B27F5F516EBE19680444D4CE5E762981931842C465F00236401D 8BD973EE
net.                    86400   IN      RRSIG   DS 8 1 86400 20190810050000 20190728040000 59944 . onHoKL6X1pqPaBu7QcSfEBLYDk0XFFGYEJs1Hh4ZKU6gWXro6D/dRB9o VHP5ewUDc3JkzGmc8tb++uvuh6DotWFcb/LV7At2pIcIZqycEqzlx6fE qUCPpHFabPqpnnjdFqMQKB0vvYAi5R8QTina1Sd9XVktMsKcZYGStnjX py+hqomDtFUZUmzQYi0SwPdpdelaIyrl2b2fskAdR73YIwEQpwClts5J oF9iBekRKC57wVt7E3RRLwyeh48rx5Z/OGrBMiUUSg8wc5KvngPHcIZh GtuqiWFIx8DWXl7DNovqpJDu0ockeb9IoDVqShTV2I2W9pgqRYSDotvB URSvQw==
;; Received 1171 bytes from 202.12.27.33#53(m.root-servers.net) in 12723 ms

pynote.net.             172800  IN      NS      ns23.domaincontrol.com.
pynote.net.             172800  IN      NS      ns24.domaincontrol.com.
A1RT98BS5QGC9NFI51S9HCI47ULJG6JH.net. 86400 IN NSEC3 1 1 0 - A1RUUFFJKCT2Q54P78F8EJGJ8JBK7I8B NS SOA RRSIG DNSKEY NSEC3PARAM
A1RT98BS5QGC9NFI51S9HCI47ULJG6JH.net. 86400 IN RRSIG NSEC3 8 2 86400 20190803055607 20190727044607 59540 net. koZ7rViD+jzqni0gJFi31/b0KKvEJ9NIu3ueT5NFEk83uHPKB2EcmcZR Nthxn+BvZb3DY8k+WO/myrfNdjmv+uJK9e6ftTJh6W6oI2Eh88UFlHkL PHjvtMLI2BnLH1dCGeG67rOH52BrMAYQ+/4UKWI6ZngJ+81vvnVtvwal nQlUlxxFKqgEDP8kluFVRGQjNaDkdA4sFNq6ajLyFxTAYw==
3TINTEUQR17QECLIUOSHOUSUGJ131BTR.net. 86400 IN NSEC3 1 1 0 - 3TJ0M01OODPCGAMB6E8VOJ14EUJFQHV1 NS DS RRSIG
3TINTEUQR17QECLIUOSHOUSUGJ131BTR.net. 86400 IN RRSIG NSEC3 8 2 86400 20190804054648 20190728043648 59540 net. onyorKeE9byXdXacubhONbNqHAM1gemAc42kXhkhXDaEbQueIc3eJjd1 QYqgeg7zZenlxbWlXfcWhzzwE1HavgX5zSmJNUEKjTw6w7+St/tyWIxL /bNiW0czgue4lNXQ5WSsjDLGEL/SJ84LSOwffXTA5SeEad5sDCVobbg4 dQWUv9dVeq9vZutPYSEi5eoxkcu8tH6QtGpXGnMI0knkaw==
;; Received 647 bytes from 192.54.112.30#53(h.gtld-servers.net) in 1240 ms

www.pynote.net.         86400   IN      CNAME   pynote.net.
pynote.net.             86400   IN      A       43.248.8.57
pynote.net.             3600    IN      NS      ns23.domaincontrol.com.
pynote.net.             3600    IN      NS      ns24.domaincontrol.com.
;; Received 128 bytes from 173.201.69.12#53(ns24.domaincontrol.com) in 233 ms

好复杂,反正看到最后找到了pynote.net的原始解析服务器了。

dig工具很强大,以上就做简要介绍,至少基本会用了。

本文链接:https://www.maixj.net/ict/dig-dns-16113

相关文章

留言区


前一篇:
后一篇:

栏目精选

云上小悟,麦新杰的独立博客

Ctrl+D 收藏本页

栏目


©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号:苏ICP备14045477号-1。云上小悟网站部分内容来源于网络,转载目的是为了整合信息,收藏学习,服务大家,有些转载内容也难以判断是否有侵权问题,如果侵犯了您的权益,请及时联系站长,我会立即删除。

网站二维码
go to top