dig工具

dig 的全称是 Domain Information Groper,意即域名信息挖掘工具。

直接输入dig查询,会显示全球13个DNS根域名服务器信息:

$ dig

; <<>> DiG 9.8.3-P1 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56638
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;.              IN  NS

;; ANSWER SECTION:
.           402014  IN  NS  f.root-servers.net.
.           402014  IN  NS  d.root-servers.net.
.           402014  IN  NS  j.root-servers.net.
.           402014  IN  NS  e.root-servers.net.
.           402014  IN  NS  g.root-servers.net.
.           402014  IN  NS  a.root-servers.net.
.           402014  IN  NS  b.root-servers.net.
.           402014  IN  NS  h.root-servers.net.
.           402014  IN  NS  k.root-servers.net.
.           402014  IN  NS  l.root-servers.net.
.           402014  IN  NS  m.root-servers.net.
.           402014  IN  NS  c.root-servers.net.
.           402014  IN  NS  i.root-servers.net.

;; Query time: 16 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: Thu Dec 22 16:43:01 2016
;; MSG SIZE  rcvd: 228

使用追踪功能(+trace),我们可以查询到每级DNS服务器对域名的解析全过程

$ dig +trace rungame.me

; <<>> DiG 9.8.3-P1 <<>> +trace rungame.me
;; global options: +cmd
.           227759  IN  NS  b.root-servers.net.
.           227759  IN  NS  d.root-servers.net.
.           227759  IN  NS  e.root-servers.net.
.           227759  IN  NS  a.root-servers.net.
.           227759  IN  NS  h.root-servers.net.
.           227759  IN  NS  k.root-servers.net.
.           227759  IN  NS  c.root-servers.net.
.           227759  IN  NS  j.root-servers.net.
.           227759  IN  NS  m.root-servers.net.
.           227759  IN  NS  i.root-servers.net.
.           227759  IN  NS  g.root-servers.net.
.           227759  IN  NS  l.root-servers.net.
.           227759  IN  NS  f.root-servers.net.
;; Received 228 bytes from 114.114.114.114#53(114.114.114.114) in 210 ms

me.         172800  IN  NS  a0.cctld.afilias-nst.info.
me.         172800  IN  NS  a2.me.afilias-nst.info.
me.         172800  IN  NS  b0.cctld.afilias-nst.org.
me.         172800  IN  NS  b2.me.afilias-nst.org.
me.         172800  IN  NS  c0.cctld.afilias-nst.info.
me.         172800  IN  NS  d0.cctld.afilias-nst.org.
me.         172800  IN  NS  ns.nic.me.
me.         172800  IN  NS  ns2.nic.me.
;; Received 486 bytes from 198.97.190.53#53(198.97.190.53) in 1171 ms

rungame.me.     86400   IN  NS  f1g1ns1.dnspod.net.
rungame.me.     86400   IN  NS  f1g1ns2.dnspod.net.
;; Received 82 bytes from 199.249.119.1#53(199.249.119.1) in 281 ms

rungame.me.     600 IN  CNAME   sbxfc.github.io.
rungame.me.     86400   IN  NS  f1g1ns2.dnspod.net.
rungame.me.     86400   IN  NS  f1g1ns1.dnspod.net.
;; Received 121 bytes from 182.140.167.188#53(182.140.167.188) in 50 ms

或者,使用指定的DNS服务器查询A记录

$ dig @8.8.8.8 rungame.me A

; <<>> DiG 9.8.3-P1 <<>> @8.8.8.8 rungame.me A
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63802
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;rungame.me.            IN  A

;; ANSWER SECTION:
rungame.me.     599 IN  CNAME   sbxfc.github.io.
sbxfc.github.io.    3599    IN  CNAME   github.map.fastly.net.
github.map.fastly.net.  11  IN  A   151.101.100.133

;; Query time: 198 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Wed Nov 16 15:45:04 2016
;; MSG SIZE  rcvd: 108

部分参数描述:

参数 描述
+trace 从顶级根域名开始追踪查询过程
+tcp 使用TCP代替默认的UDP查询
-q 逆向查询,可以查询IP到域名的映射
-x 逆向查询,可以查询IP到域名的映射
-t 设置查询类型,默认情况下是A,也可以设置MX等类型
-f dig支持从一个文件里读取内容进行批量查询

Comments