dig命令使用详解|使用dig命令挖掘域名解析信息
Dig命令主要用来从 DNS 域名服务器查询主机地址信息
1. 查询域名的A记录
dig qq.com #查询qq.com的A记录
root@xg:~# dig qq.com
; <<>> DiG 9.11.5-P1-1-Debian <<>> qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28913
;; 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 A
;; ANSWER SECTION:
qq.com. 273 IN A 61.129.7.47
qq.com. 273 IN A 123.151.137.18
qq.com. 273 IN A 183.3.226.35
;; Query time: 35 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: 三 1月 27 00:32:21 CST 2021
;; MSG SIZE rcvd: 83
2. 在指定的服务器上查询域名的解析A记录
#在8.8.8.8谷歌DNS服务器上查询qq.com的A记录
dig -t A qq.com @8.8.8.8#在114.114.114.114DNS服务器上查询qq.com的所有解析记录
dig @114.114.114.114 qq.com any
root@xg:~# dig -t A qq.com @8.8.8.8
; <<>> DiG 9.11.5-P1-1-Debian <<>> -t A qq.com @8.8.8.8
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40077
;; 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 A
;; ANSWER SECTION:
qq.com. 599 IN A 123.151.137.18
qq.com. 599 IN A 61.129.7.47
qq.com. 599 IN A 183.3.226.35
;; Query time: 549 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: 三 1月 27 00:47:20 CST 2021
;; MSG SIZE rcvd: 83
root@xg:~# dig @114.114.114.114 qq.com any
; <<>> DiG 9.11.5-P1-1-Debian <<>> @114.114.114.114 qq.com any
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37833
;; flags: qr rd ra; QUERY: 1, ANSWER: 10, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;qq.com. IN ANY
;; ANSWER SECTION:
qq.com. 1660 IN MX 30 mx1.qq.com.
qq.com. 1660 IN MX 20 mx2.qq.com.
qq.com. 1660 IN MX 10 mx3.qq.com.
qq.com. 284 IN A 61.129.7.47
qq.com. 284 IN A 123.151.137.18
qq.com. 284 IN A 183.3.226.35
qq.com. 75049 IN NS ns4.qq.com.
qq.com. 75049 IN NS ns2.qq.com.
qq.com. 75049 IN NS ns1.qq.com.
qq.com. 75049 IN NS ns3.qq.com.
;; Query time: 259 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: 三 1月 27 00:52:13 CST 2021
;; MSG SIZE rcvd: 21
3. 使用-x 参数 IP 反查域名 (必须域名有PTR解析)
#查询 209.132.183.81的域名
dig -x 209.132.183.81
root@xg:~# dig -x 209.132.183.81
; <<>> DiG 9.11.5-P1-1-Debian <<>> -x 209.132.183.81
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62797
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;81.183.132.209.in-addr.arpa. IN PTR
;; ANSWER SECTION:
81.183.132.209.in-addr.arpa. 599 IN PTR www.redhat.com.
;; Query time: 297 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: 三 1月 27 01:18:18 CST 2021
;; MSG SIZE rcvd: 84
4. 使用dig批量查询域名
#查询 domains.txt文件内所有域名的任何解析记录 +noall +answer 表示不是全部显示,只显示响应
dig -f domains.txt any +noall +answer
root@xg:~# echo baidu.com > domains.txt
root@xg:~# echo qq.com >> domains.txt
root@xg:~# echo csdn.com >> domains.txt
root@xg:~# echo 163.com >> domains.txt
root@xg:~# dig -f domains.txt any +noall +answer
baidu.com. 34 IN MX 20 mx1.baidu.com.
baidu.com. 34 IN MX 15 mx.n.shifen.com.
baidu.com. 34 IN MX 20 mx50.baidu.com.
baidu.com. 34 IN MX 20 jpmx.baidu.com.
baidu.com. 34 IN MX 10 mx.maillb.baidu.com.
baidu.com. 337 IN A 39.156.69.79
baidu.com. 337 IN A 220.181.38.148
baidu.com. 86387 IN NS ns7.baidu.com.
baidu.com. 86387 IN NS ns3.baidu.com.
baidu.com. 86387 IN NS dns.baidu.com.
baidu.com. 86387 IN NS ns2.baidu.com.
baidu.com. 86387 IN NS ns4.baidu.com.
qq.com. 5485 IN MX 10 mx3.qq.com.
qq.com. 5485 IN MX 30 mx1.qq.com.
qq.com. 5485 IN MX 20 mx2.qq.com.
qq.com. 34 IN A 61.129.7.47
qq.com. 34 IN A 183.3.226.35
qq.com. 34 IN A 123.151.137.18
qq.com. 10374 IN NS ns4.qq.com.
qq.com. 10374 IN NS ns3.qq.com.
qq.com. 10374 IN NS ns1.qq.com.
qq.com. 10374 IN NS ns2.qq.com.
csdn.com. 599 IN MX 10 mxbiz2.qq.com.
csdn.com. 599 IN MX 5 mxbiz1.qq.com.
csdn.com. 350 IN A 47.95.164.112
csdn.com. 1231 IN NS dns13.hichina.com.
csdn.com. 1231 IN NS dns14.hichina.com.
163.com. 17720 IN MX 10 163mx02.mxmail.netease.com.
163.com. 17720 IN MX 50 163mx00.mxmail.netease.com.
163.com. 17720 IN MX 10 163mx03.mxmail.netease.com.
163.com. 17720 IN MX 10 163mx01.mxmail.netease.com.
163.com. 421 IN A 123.58.180.8
163.com. 421 IN A 123.58.180.7
163.com. 29162 IN NS ns8.166.com.
163.com. 29162 IN NS ns3.nease.net.
163.com. 29162 IN NS ns6.nease.net.
163.com. 29162 IN NS ns4.nease.net.
163.com. 29162 IN NS ns2.166.com.
163.com. 29162 IN NS ns1.nease.net.
163.com. 29162 IN NS ns5.nease.net.
5. 使用dig查询dns服务器版本信息
#查询ns3.dnsv4.com的版本信息
dig txt chaos VERSION.BIND @ns3.dnsv4.com
root@xg:~# dig txt chaos VERSION.BIND @ns3.dnsv4.com
;; Warning: query response not set
;; Warning: Message parser reports malformed message packet.
; <<>> DiG 9.11.5-P1-1-Debian <<>> txt chaos VERSION.BIND @ns3.dnsv4.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44766
;; flags: rd ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;VERSION.BIND. CH TXT
;; ANSWER SECTION:
VERSION.BIND. 0 CH TXT "DNSPod AUTHORITY DNS 5.1.2011.00"
;; Query time: 69 msec
;; SERVER: 162.14.25.247#53(162.14.25.247)
;; WHEN: 三 1月 27 01:42:49 CST 2021
;; MSG SIZE rcvd: 75
6.使用dig +trace 查看解析过程
#查看百度的解析过程
dig baidu.com +trace +short @114.114.114.114
root@xg:~# dig baidu.com +trace +short @114.114.114.114
NS f.root-servers.net. from server 114.114.114.114 in 44 ms.
NS i.root-servers.net. from server 114.114.114.114 in 44 ms.
NS b.root-servers.net. from server 114.114.114.114 in 44 ms.
NS c.root-servers.net. from server 114.114.114.114 in 44 ms.
NS j.root-servers.net. from server 114.114.114.114 in 44 ms.
NS l.root-servers.net. from server 114.114.114.114 in 44 ms.
NS a.root-servers.net. from server 114.114.114.114 in 44 ms.
NS d.root-servers.net. from server 114.114.114.114 in 44 ms.
NS h.root-servers.net. from server 114.114.114.114 in 44 ms.
NS g.root-servers.net. from server 114.114.114.114 in 44 ms.
NS e.root-servers.net. from server 114.114.114.114 in 44 ms.
NS k.root-servers.net. from server 114.114.114.114 in 44 ms.
NS m.root-servers.net. from server 114.114.114.114 in 44 ms.
A 220.181.38.148 from server 220.181.33.31 in 45 ms.
A 39.156.69.79 from server 220.181.33.31 in 45 ms.