Linux command line learning - dig (DNS querier)

  
        

In web development, the http protocol is always familiar, and the first process to start before starting a http is DNS resolution. Simply put, the process of how the domain name finally resolves to the actual server ip.

A powerful tool for studying DNS resolution and troubleshooting DNS resolution problems is dig. There is a more traditional command nslookup corresponding to him, but dig as an updated command, its powerful and concise and customizable output also makes the operation and maintenance of its developers.

Instance 1 (Access the server local DNSserver to query the root domain name 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.< Br>

Instance 2 (Baidu Home DNS Resolution): dig www.baidu.com

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20. P1.el5_8.6 <<>> www.baid U.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

Example 3 (developing a google domain name server to resolve Baidu homepage); 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

Example 4 (use the +trace option to view the process from the root name server to the final resolution to 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

Description: Get several root name servers from the local DNS 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 Description: Select f.root-servers.net root domain name server to query com domain name server baidu.com. 172800 IN NS dns.baidu.com. baidu.com. 172800 IN NS ns2.baidu.com. baidu.com. 172800 IN NS Nb3.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 Description: Select the com domain name server of a.gtld-servers.net to resolve the domain name server of 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.co Mashifen.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

Description: resolve to www.baidu.com as www.adu.com by choosing to access the dns.baidu.com domain name server Alias ​​of .shifen.com;

So we dig down www.a.shifen.com.

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

Copyright © Windows knowledge All Rights Reserved