linux命令行学习-dig(DNS查询器)

Posted yutingliuyl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux命令行学习-dig(DNS查询器)相关的知识,希望对你有一定的参考价值。

在web开发中。总要熟悉的就是http协议。而发起一个http開始前最先要经历的一个过程就是DNS解析。简单说就是域名怎样终于解析到实际serverip的过程。

而在研究DNS解析和排除DNS解析类故障问题的时候一个强大的工具就是dig。

和他相应的有个比較传统的命令nslookup,只是dig作为更新的命令,其强大而简洁可定制的输出也使得运维其开发者使用。

 实例1(訪问server本地DNSserver查询根域名server):  ~#: dig

 ; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5_8.6 <<>>
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39027
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13


;; QUESTION SECTION:
;. IN NS

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



实例2(百度首页DNS解析): dig www.baidu.com 

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5_8.6 <<>> www.baidu.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15372
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

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

;; ANSWER SECTION:
www.baidu.com. 641 IN CNAME www.a.shifen.com.
www.a.shifen.com. 110 IN A 180.97.33.107
www.a.shifen.com. 110 IN A 180.97.33.108

;; Query time: 1 msec
;; SERVER: 192.168.100.52#53(192.168.100.52)
;; WHEN: Wed Aug 13 22:33:59 2014
;; MSG SIZE  rcvd: 90 


实例3(制定使用google域名server解析百度首页); dig @8.8.8.8 www.baidu.com

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5_8.6 <<>> @8.8.8.8 www.baidu.com
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44033
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

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


;; ANSWER SECTION:
www.baidu.com. 557 IN CNAME www.a.shifen.com.
www.a.shifen.com. 299 IN A 180.76.3.151


;; Query time: 615 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Wed Aug 13 22:36:36 2014
;; MSG SIZE  rcvd: 74


实例4(使用+trace选项查看从根域名server到终于解析到ip的过程): dig www.baidu.com +trace

. 84899 IN NS f.root-servers.net.
. 84899 IN NS d.root-servers.net.
. 84899 IN NS e.root-servers.net.
. 84899 IN NS b.root-servers.net.
. 84899 IN NS c.root-servers.net.
. 84899 IN NS m.root-servers.net.
. 84899 IN NS k.root-servers.net.
. 84899 IN NS i.root-servers.net.
. 84899 IN NS j.root-servers.net.
. 84899 IN NS h.root-servers.net.
. 84899 IN NS g.root-servers.net.
. 84899 IN NS a.root-servers.net.
. 84899 IN NS l.root-servers.net.
;; Received 509 bytes from 192.168.100.52#53(192.168.100.52) in 1 ms

说明:从本地DNSserver得到若干各根域名server


com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
;; Received 503 bytes from 192.5.5.241#53(f.root-servers.net) in 39 ms
说明:选取f.root-servers.net根域名server查询com域名server

baidu.com. 172800 IN NS dns.baidu.com.
baidu.com. 172800 IN NS ns2.baidu.com.
baidu.com. 172800 IN NS ns3.baidu.com.
baidu.com. 172800 IN NS ns4.baidu.com.
baidu.com. 172800 IN NS ns7.baidu.com.
;; Received 201 bytes from 192.5.6.30#53(a.gtld-servers.net) in 360 ms
说明:选取a.gtld-servers.net的com域名server解析baidu.com的域名server

www.baidu.com. 1200 IN CNAME www.a.shifen.com.
a.shifen.com. 1200 IN NS ns3.a.shifen.com.
a.shifen.com. 1200 IN NS ns5.a.shifen.com.
a.shifen.com. 1200 IN NS ns1.a.shifen.com.
a.shifen.com. 1200 IN NS ns4.a.shifen.com.
a.shifen.com. 1200 IN NS ns2.a.shifen.com.
;; Received 228 bytes from 202.108.22.220#53(dns.baidu.com) in 206 ms

说明:通过选择訪问dns.baidu.com域名server解析到www.baidu.com作为www.a.shifen.com的别名;


于是我们再dig下www.a.shifen.com.

[[email protected] JakQuan]# dig www.a.shifen.com +short
180.97.33.108
180.97.33.107

















































































































以上是关于linux命令行学习-dig(DNS查询器)的主要内容,如果未能解决你的问题,请参考以下文章

dig命令详解

Linux 命令(197)—— dig 命令

如何在Linux中通过命令查看域名对应的IP

Linux dig命令

linux dig 命令

linux dig命令 转