linux命令--dig

dig,和nslookup作用有些类似,都是DNS查询工具,但是却比nslookup强大

dig,其实是一个缩写,即Domain Information Groper。

【我想用google-DNS来查baidu.com的A记录】

wangkongming@Vostro ~ $ dig @8.8.8.8 www.baidu.com A

; <<>> DiG 9.9.5-3ubuntu0.3-Ubuntu <<>> @8.8.8.8 www.baidu.com A
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5863
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.baidu.com.            IN    A

;; ANSWER SECTION:
www.baidu.com.        489    IN    CNAME    www.a.shifen.com.
www.a.shifen.com.    122    IN    A    220.181.111.188
www.a.shifen.com.    122    IN    A    220.181.112.244

;; Query time: 180 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Fri Sep 11 16:28:06 CST 2015
;; MSG SIZE  rcvd: 101

【跟踪dig全过程】

wangkongming@Vostro ~ $ dig +trace www.baidu.com

; <<>> DiG 9.9.5-3ubuntu0.3-Ubuntu <<>> +trace www.baidu.com
;; global options: +cmd
.            62424    IN    NS    d.root-servers.net.
.            62424    IN    NS    g.root-servers.net.
.            62424    IN    NS    k.root-servers.net.
.            62424    IN    NS    e.root-servers.net.
.            62424    IN    NS    l.root-servers.net.
.            62424    IN    NS    m.root-servers.net.
.            62424    IN    NS    i.root-servers.net.
.            62424    IN    NS    a.root-servers.net.
.            62424    IN    NS    f.root-servers.net.
.            62424    IN    NS    h.root-servers.net.
.            62424    IN    NS    c.root-servers.net.
.            62424    IN    NS    j.root-servers.net.
.            62424    IN    NS    b.root-servers.net.
;; Received 239 bytes from 127.0.1.1#53(127.0.1.1) in 477 ms

com.            172800    IN    NS    a.gtld-servers.net.
com.            172800    IN    NS    b.gtld-servers.net.
com.            172800    IN    NS    c.gtld-servers.net.
com.            172800    IN    NS    d.gtld-servers.net.
com.            172800    IN    NS    e.gtld-servers.net.
com.            172800    IN    NS    f.gtld-servers.net.
com.            172800    IN    NS    g.gtld-servers.net.
com.            172800    IN    NS    h.gtld-servers.net.
com.            172800    IN    NS    i.gtld-servers.net.
com.            172800    IN    NS    j.gtld-servers.net.
com.            172800    IN    NS    k.gtld-servers.net.
com.            172800    IN    NS    l.gtld-servers.net.
com.            172800    IN    NS    m.gtld-servers.net.
com.            86400    IN    DS    30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CF C41A5766
com.            86400    IN    RRSIG    DS 8 1 86400 20150921050000 20150911040000 1518 . BF33r0rrYVfJvYYYCBD0stzm5pDjCBxNIQeGHyduK4Xku56XLs4MRfXc 44HpmzuWvBU4IOKRVXbjh236Eh3rbARbxYIqHx5sKFKI6KVZg0d6K8+7 xTbBCJkpaUAXxoE9lz2mOFEdON/cSxAQyKyT+A/ZLPkZw8QpnaQgn2Nw qYM=
;; Received 737 bytes from 199.7.83.42#53(l.root-servers.net) in 410 ms

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.
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN NSEC3 1 1 0 - CK0Q1GIN43N1ARRC9OSM6QPQR81H5M9A NS SOA RRSIG DNSKEY NSEC3PARAM
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN RRSIG NSEC3 8 2 86400 20150915212106 20150908201106 35864 com. PSL/fLCxFV7fdwY4LWjH/vcj7S7legHC05t1lEnb2sKGmXrUqoe3RZVg 9iWUm6aWxwCuEBre8s/fJzyDfYImR2fE6YB5p+GCouWkkSaxZKjNGLDa W01HoGoHOAnS1BOF6DdwODGgVuPGtx3KtB1AIKjQI2VXhOcaIAmE16hs OZQ=
HPVV2B5N85O7HJJRB7690IB5UVF9O9UA.com. 86400 IN NSEC3 1 1 0 - HPVV9UNFR23OVV2EH3NNTJ1A7JE3ETFH NS DS RRSIG
HPVV2B5N85O7HJJRB7690IB5UVF9O9UA.com. 86400 IN RRSIG NSEC3 8 2 86400 20150915044155 20150908033155 35864 com. cNpdZgm+VNI2KKPP6CsWTm4gSzR4AlvkjrdzTr8csBNTbFfhQMQ2S6wE m4hRe/AqkuefUEg3Df7aSwgcNMnDZm/SxU9PVpVYzuWqrdA+JU+jkd60 8S0xzxQBOQ9jkoHU9LzJb5SyuwT5BMbt0ty2h7LztvLhd7JfkrQPDnby Two=
;; Received 697 bytes from 192.26.92.30#53(c.gtld-servers.net) in 509 ms

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    ns2.a.shifen.com.
a.shifen.com.        1200    IN    NS    ns5.a.shifen.com.
a.shifen.com.        1200    IN    NS    ns4.a.shifen.com.
a.shifen.com.        1200    IN    NS    ns1.a.shifen.com.
;; Received 239 bytes from 119.75.219.82#53(ns7.baidu.com) in 58 ms

wangkongming@Vostro ~ $ 

【精简dig输出】

1 使用+nocmd的话,可以节省输出dig版本信息。

2 使用+short的话,仅会输出最精简的CNAME信息和A记录,其他都不会输出。就像这样:

wangkongming@Vostro ~ $ dig +short www.baidu.com
www.a.shifen.com.
180.97.33.108
180.97.33.107

 

3 使用+nocomment的话,可以节省输出dig的详情注释信息。

4 使用+nostat的话,最后的统计信息也不会输出。当+nocmd、+nocomment和+nostat都是用上,是这样:

wangkongming@Vostro ~ $ dig +nocmd +nocomment +nostat www.baidu.com
;www.baidu.com.            IN    A
www.baidu.com.        1141    IN    CNAME    www.a.shifen.com.
www.a.shifen.com.    257    IN    A    180.97.33.108
www.a.shifen.com.    257    IN    A    180.97.33.107

 

参考文章:http://roclinux.cn/?p=2449

 

posted @ 2015-09-11 16:34  KoMiles  阅读(1573)  评论(0编辑  收藏  举报