歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

linux命令行學習-dig(DNS查詢器)

在web開發中,總要熟悉的就是http協議,而發起一個http開始前最先要經歷的一個過程就是DNS解析。簡單說就是域名如何最終解析到實際服務器ip的過程。

而在研究DNS解析和排除DNS解析類故障問題的時候一個強大的工具就是dig。和他對應的有個比較傳統的命令nslookup,不過dig作為更新的命令,其強大而簡潔可定制的輸出也使得運維其開發人員使用。

實例1(訪問服務器本地DNSserver查詢根域名服務器): ~#: 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域名服務器解析百度首頁); 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選項查看從根域名服務器到最終解析到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

說明:從本地DNS服務器得到若干各根域名服務器


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根域名服務器查詢com域名服務器

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域名服務器解析baidu.com的域名服務器

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域名服務器解析到www.baidu.com作為www.a.shifen.com的別名;

於是我們再dig下www.a.shifen.com.

[root@local200-65 JakQuan]# dig www.a.shifen.com +short
180.97.33.108
180.97.33.107

Copyright © Linux教程網 All Rights Reserved