10.19 dig:域名查询工具

dig命令

是常用的域名查询工具,可以用于测试域名系统的工作是否正常。 

dig命令的参数选项及说明

@<DNS服务器地址>    指定进行城名解析的域名服务器。当不希望使用本机默认的DNS服务器设置时,使用此选项可指定进行线名解析的其他的域名服务器
 
-x             反向域名解析    
-t             指定要查询的DNS数据类型,如A、MX和PTR等。默认的查询类型为A
-b             指定使用本机的哪个IP地址向域名服务器发送域名查询请求
-P             指定域名服务器所使用的端口号。默认情况下,域名服务器使用UDP协议的53端口
+trace         从根域开始跟踪查询结果
+nocmd         不输出dig的版本信息
+short         仅输出最精简的CNAME信息和A记录,其他的都不会输出
+nocomment     不输出dig的详情注释信息
+nostat        不输出最后的统计信息
 

查询指定域名的IP地址 

[root@cs6 ~]# dig www.wenyule.top
 
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6_10.1 <<>> www.wenyule.top
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52108
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 18
 
;; QUESTION SECTION:
;www.wenyule.top.        IN    A
 
;; ANSWER SECTION:
www.wenyule.top.    5    IN    A    213.232.105.22  #<=查询结果。
 
;; AUTHORITY SECTION:
wenyule.top.        5    IN    NS    dns18.hichina.com.
wenyule.top.        5    IN    NS    dns17.hichina.com.
 
;; ADDITIONAL SECTION:
dns17.hichina.com.    5    IN    A    140.205.41.27
dns17.hichina.com.    5    IN    A    140.205.81.17
dns17.hichina.com.    5    IN    A    140.205.81.27
dns17.hichina.com.    5    IN    A    106.11.141.117
dns17.hichina.com.    5    IN    A    106.11.141.127
dns17.hichina.com.    5    IN    A    106.11.211.57
dns17.hichina.com.    5    IN    A    106.11.211.67
dns17.hichina.com.    5    IN    A    140.205.41.17
dns18.hichina.com.    5    IN    A    106.11.211.68
dns18.hichina.com.    5    IN    A    140.205.41.18
dns18.hichina.com.    5    IN    A    140.205.41.28
dns18.hichina.com.    5    IN    A    140.205.81.18
dns18.hichina.com.    5    IN    A    140.205.81.28
dns18.hichina.com.    5    IN    A    106.11.141.118
dns18.hichina.com.    5    IN    A    106.11.141.128
dns18.hichina.com.    5    IN    A    106.11.211.58
dns17.hichina.com.    5    IN    AAAA    2400:3200:2000:36::1
dns18.hichina.com.    5    IN    AAAA    2400:3200:2000:37::1
 
;; Query time: 56 msec              #<=查询时间。
;; SERVER: 10.0.0.2#53(10.0.0.2)    #<=使用默认的DNS服务器。
;; WHEN: Tue May  7 14:35:44 2019
;; MSG SIZE  rcvd: 412   

 

 

反向域名解析例子

完整的域名解析包括正向解析(即范例10-67,将域名解析成IP地址)和反向解析(给定IP地址查询其对应的域名信息)。
[root@cs6 ~]# dig -x 213.232.105.22
 
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6_10.1 <<>> -x 213.232.105.22
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 45496
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
 
;; QUESTION SECTION:
;22.105.232.213.in-addr.arpa.    IN    PTR
 
;; AUTHORITY SECTION:
213.in-addr.arpa.    5    IN    SOA    pri.authdns.ripe.net. dns.ripe.net. 1557371861 3600 600 864000 3600
 
;; Query time: 124 msec
;; SERVER: 10.0.0.2#53(10.0.0.2)
;; WHEN: Tue May  7 14:40:42 2019
;; MSG SIZE  rcvd: 105

 

 

查询MX类型的域名信息 

 [root@cs6 ~]# dig -t MX oldboyedu.com #<=使用-t 选项选择查询的类型
 
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6_10.1 <<>> -t MX oldboyedu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 13697
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
 
;; QUESTION SECTION:
;oldboyedu.com.            IN    MX
 
;; Query time: 5 msec
;; SERVER: 10.0.0.2#53(10.0.0.2)
;; WHEN: Tue May  7 14:42:57 2019
;; MSG SIZE  rcvd: 31
 

 

 

显示完整的DNS解析过程

[root@cs6 ~]# dig @223.5.5.5 www.wenyule.top +trace
 
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6_10.1 <<>> @223.5.5.5 www.wenyule.top +trace
; (1 server found)
;; global options: +cmd
.            195170    IN    NS    g.root-servers.net.
.            195170    IN    NS    j.root-servers.net.
.            195170    IN    NS    c.root-servers.net.
.            195170    IN    NS    f.root-servers.net.
.            195170    IN    NS    m.root-servers.net.
.            195170    IN    NS    i.root-servers.net.
.            195170    IN    NS    d.root-servers.net.
.            195170    IN    NS    e.root-servers.net.
.            195170    IN    NS    a.root-servers.net.
.            195170    IN    NS    b.root-servers.net.
.            195170    IN    NS    h.root-servers.net.
.            195170    IN    NS    k.root-servers.net.
.            195170    IN    NS    l.root-servers.net.    #<=显示全球13个根服务器a-m
;; Received 228 bytes from 223.5.5.5#53(223.5.5.5) in 127 ms
 
top.            172800    IN    NS    a.zdnscloud.com.
top.            172800    IN    NS    b.zdnscloud.com.
top.            172800    IN    NS    c.zdnscloud.com.
top.            172800    IN    NS    d.zdnscloud.com.
top.            172800    IN    NS    f.zdnscloud.com.
top.            172800    IN    NS    g.zdnscloud.com.
top.            172800    IN    NS    i.zdnscloud.com.
top.            172800    IN    NS    j.zdnscloud.com.
;; Received 326 bytes from 192.5.5.241#53(192.5.5.241) in 104 ms
 
wenyule.top.        3600    IN    NS    dns17.hichina.com.
wenyule.top.        3600    IN    NS    dns18.hichina.com.
;; Received 84 bytes from 203.99.27.1#53(203.99.27.1) in 43 ms
 
www.wenyule.top.    600    IN    A    213.232.105.22
;; Received 49 bytes from 106.11.141.128#53(106.11.141.128) in 59 ms 

 

 

精简输出例子

[root@cs6 ~]# dig +nocmd +nocomment +nostat www.wenyule.top
;www.wenyule.top.        IN    A
www.wenyule.top.    5    IN    A    213.232.105.22
top.            5    IN    NS    f.zdnscloud.com.
top.            5    IN    NS    g.zdnscloud.com.
top.            5    IN    NS    b.zdnscloud.com.
top.            5    IN    NS    i.zdnscloud.com.
top.            5    IN    NS    d.zdnscloud.com.
top.            5    IN    NS    j.zdnscloud.com.
top.            5    IN    NS    a.zdnscloud.com.
top.            5    IN    NS    c.zdnscloud.com.
b.zdnscloud.com.    5    IN    A    203.99.25.1
d.zdnscloud.com.    5    IN    A    203.99.27.1
f.zdnscloud.com.    5    IN    A    114.67.46.12
g.zdnscloud.com.    5    IN    A    42.62.2.16
i.zdnscloud.com.    5    IN    AAAA    2401:8d00:1::1
j.zdnscloud.com.    5    IN    AAAA    2401:8d00:2::1
 
[root@cs6 ~]# dig +short www.wenyule.top
213.232.105.22

 

posted @ 2019-05-09 15:44  Fadewalk  阅读(964)  评论(0编辑  收藏  举报