dig:域名查询工具

xiaohai 2021-07-04 19:05:03 3619人围观 标签: Linux 
简介dig命令是用于域名查询,可以用于测试域名系统的工作是否正常。如果没有dig命令,请使用:yum install bind-utils 进行安装
说明

  dig命令是用于域名查询,可以用于测试域名系统的工作是否正常。如果没有dig命令,请使用:yum install bind-utils 进行安装

格式

  dig [option]

常用参数
  • @<服务器地址>:指定进行域名解析的域名服务器;
  • -b:当主机具有多个IP地址,指定使用本机的哪个IP地址向域名服务器发送域名查询请求;
  • -f<文件名称>:指定dig以批处理的方式运行,指定的文件中保存着需要批处理查询的DNS任务信息;
  • -P:指定域名服务器所使用端口号;
  • -t<类型>:指定要查询的DNS数据类型;
  • -x:执行逆向域名查询;
  • -4:使用IPv4;
  • -6:使用IPv6;
  • +trace:从根域开始跟踪查询结果
示例

1、查询指定域名的IP地址

[root@localhost ~]# dig www.hi917.com

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.hi917.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8463
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.hi917.com.            IN    A

;; ANSWER SECTION:
www.hi917.com.        5    IN    A    39.108.78.191

;; Query time: 123 msec
;; SERVER: 192.168.71.2#53(192.168.71.2)
;; WHEN: Wed Jun 20 05:24:32 EDT 2018
;; MSG SIZE  rcvd: 47

2、反向域名解析例子

[root@localhost ~]# dig -x 39.108.78.191

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> -x 39.108.78.191
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7371
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; MBZ: 0005 , udp: 4096
;; QUESTION SECTION:
;191.78.108.39.in-addr.arpa.    IN    PTR

;; ANSWER SECTION:
191.78.108.39.in-addr.arpa. 5    IN    A    183.221.250.11

;; Query time: 165 msec
;; SERVER: 192.168.71.2#53(192.168.71.2)
;; WHEN: Wed Jun 20 05:25:45 EDT 2018
;; MSG SIZE  rcvd: 71

3、查询MX类型的域名信息

[root@localhost ~]# dig -t MX hi917.com

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> -t MX hi917.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33168
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;hi917.com.            IN    MX

;; ANSWER SECTION:
hi917.com.        5    IN    MX    10 mxbiz2.qq.com.
hi917.com.        5    IN    MX    10 mxbiz1.qq.com.

;; Query time: 158 msec
;; SERVER: 192.168.71.2#53(192.168.71.2)
;; WHEN: Wed Jun 20 05:28:02 EDT 2018
;; MSG SIZE  rcvd: 76

4、显示完整的DNS解析过程

[root@localhost ~]# dig www.hi917.com +trace

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.hi917.com +trace
;; global options: +cmd #下面显示了13个根域名服务器a-m
.            5    IN    NS    a.root-servers.net.
.            5    IN    NS    g.root-servers.net.
.            5    IN    NS    l.root-servers.net.
.            5    IN    NS    c.root-servers.net.
.            5    IN    NS    e.root-servers.net.
.            5    IN    NS    f.root-servers.net.
.            5    IN    NS    b.root-servers.net.
.            5    IN    NS    k.root-servers.net.
.            5    IN    NS    h.root-servers.net.
.            5    IN    NS    d.root-servers.net.
.            5    IN    NS    i.root-servers.net.
.            5    IN    NS    j.root-servers.net.
.            5    IN    NS    m.root-servers.net.
;; Received 228 bytes from 192.168.71.2#53(192.168.71.2) in 5507 ms

com.            172800    IN    NS    a.gtld-servers.net.
com.            172800    IN    NS    j.gtld-servers.net.
com.            172800    IN    NS    i.gtld-servers.net.
com.            172800    IN    NS    g.gtld-servers.net.
com.            172800    IN    NS    m.gtld-servers.net.
com.            172800    IN    NS    h.gtld-servers.net.
com.            172800    IN    NS    l.gtld-servers.net.
com.            172800    IN    NS    b.gtld-servers.net.
com.            172800    IN    NS    f.gtld-servers.net.
com.            172800    IN    NS    k.gtld-servers.net.
com.            172800    IN    NS    e.gtld-servers.net.
com.            172800    IN    NS    d.gtld-servers.net.
com.            172800    IN    NS    c.gtld-servers.net.
com.            86400    IN    DS    30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CF C41A5766
com.            86400    IN    RRSIG    DS 8 1 86400 20180704170000 20180621160000 39570 . O3SBRb8fNL0WJIlosvQGQIUWlQATA4smHlh3Iq70JkhIg5cdfv2HMjI/ V113EBorivRO5PkpUXg/rsgMQmRGopS2O28FlpHyAKpxzmCi2fWbe9S8 RfQX4FmB0vp+f9sYUcXrK3YWSOEYVmlJrvuxEq8O52IOyQleitqgsRNs bZKvzC1C8ZrJit2bT2CyzYBD8inGY6zxVR8LCTSI8Qc1s0WeUdMobrwu RRhau/qHN68KUupV+kq8og8d8+hJZ0FfeLs5qte2MmxBzHOEcErybg+X Ut/PGV7aeCubrxTbv62sTyLcx3pKMq0KaZn52ApZ/GllyzF1Raq17mwA HnLxAw==
;; Received 1173 bytes from 192.112.36.4#53(g.root-servers.net) in 7841 ms

hi917.com.        172800    IN    NS    dns17.hichina.com.
hi917.com.        172800    IN    NS    dns18.hichina.com.
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN NSEC3 1 1 0 - CK0Q1GIN43N1ARRC9OSM6QPQR81H5M9A NS SOA RRSIG DNSKEY NSEC3PARAM
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN RRSIG NSEC3 8 2 86400 20180625044529 20180618033529 36707 com. TuOOv0fIevI+NEl7h4/v6m58ELJDyq5k29agyO2hPIq53fBwKS5FYwEs XryZOQw2/iGal9lZXT8JPL2tPlvWtA2Elht6ti18NHZ0wu9TRzPnJ2Rh 2906RaYuY0wGsBMrFw/ldYrysCr5Sw2ur1X/E1adsPv1nQL755IJ17UC SjE=
FCH60RNM0AAIHVEPUCO8RATL561CPJDV.com. 86400 IN NSEC3 1 1 0 - FCHD11VU5PT8UU6EMESOH6N1A2H27P77 NS DS RRSIG
FCH60RNM0AAIHVEPUCO8RATL561CPJDV.com. 86400 IN RRSIG NSEC3 8 2 86400 20180626050356 20180619035356 36707 com. fgffRLQnjPot9O43Yu7QPJxwFCFV0FnlMNuL3Kzf9lxIQjwLk5ByGGaP 9dO0XntOXsbrVbZtJmUAXrrS8623jw6OQuR6Qt/lpkyYOZ7DH3x7ZcCD 8RGew9cYrLkhwUBfRQ5d85PPZDH1kZt0D6MT8iTOVJGAuXVwQQWBWehO ZNM=
;; Received 831 bytes from 192.42.93.30#53(g.gtld-servers.net) in 685 ms

www.hi917.com.        600    IN    A    39.108.78.191
;; Received 58 bytes from 140.205.41.17#53(dns17.hichina.com) in 45 ms

5、精简输出例子

[root@localhost ~]# dig +nocmd +nocomment +nostat www.hi917.com
;www.hi917.com.            IN    A
www.hi917.com.        5    IN    A    39.108.78.191