DIG(Domain Information Groper)域名信息挖掘真屯,是Linux上一個用來查詢域名信息的很有用的命令笼踩。下面對DIG的用法舉例如下:
1.簡單用法
$dig apple.com
如果簡單的dig一個域名,默認會查詢該域名對應(yīng)的A記錄琳钉,也就是相應(yīng)的IPV4的地址信息势木,如下在(ANSWER SECTION)所示,apple.com相關(guān)聯(lián)的A記錄有三條歌懒。
$ dig apple.com
; <<>> DiG 9.8.3-P1 <<>> apple.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32044
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;apple.com. IN A
;; ANSWER SECTION:
apple.com. 2583 IN A 17.172.224.47
apple.com. 2583 IN A 17.178.96.59
apple.com. 2583 IN A 17.142.160.59
;; Query time: 51 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Wed Apr 12 11:32:12 2017
;; MSG SIZE rcvd: 75
DIG命令的輸出分析:
- HEADER: 顯示dig命令的版本信息啦桌,全局選項,和一些額外的頭部信息
- QUESTION SECTION: 顯示我們向DNS(域名系統(tǒng))發(fā)出的請求及皂,就是我們向DNS發(fā)出的提問
- ANSWER SECTION: 顯示域名系統(tǒng)給我們響應(yīng)輸出甫男,就是DNS給我們的回答
- AUTHORITY SECTION: 顯示有權(quán)限回應(yīng)此次請求的域名服務(wù)器自身的域名
- ADDITIONAL SECTION: 顯示域名解析服務(wù)器的IP地址
- STATS SECTION: 顯示此次查詢的一些數(shù)據(jù)信息,例如验烧,時間戳板驳,耗時等
2.只顯示ANSWER SECTION內(nèi)容
如果只想顯示ANSWER SECTION的內(nèi)容,你可以通過添加一些參數(shù)把其他的信息關(guān)掉
+nocomments – Turn off the comment lines
+noauthority – Turn off the authority section
+noadditional – Turn off the additional section
+nostats – Turn off the stats section
+noanswer – Turn off the answer section
下面的查詢只顯示ANSWER SECTION:
$ dig apple.com +nocomments +noquestion +noauthority +noadditional +nostats
; <<>> DiG 9.8.3-P1 <<>> apple.com +nocomments +noquestion +noauthority +noadditional +nostats
;; global options: +cmd
apple.com. 2027 IN A 17.142.160.59
apple.com. 2027 IN A 17.172.224.47
apple.com. 2027 IN A 17.178.96.59
你也可以通過反選的方式碍拆,指定只想顯示的信息:
$ dig apple.com +noall +answer
; <<>> DiG 9.8.3-P1 <<>> apple.com +noall +answer
;; global options: +cmd
apple.com. 1952 IN A 17.142.160.59
apple.com. 1952 IN A 17.172.224.47
apple.com. 1952 IN A 17.178.96.59
3.只查詢某條記錄
如果只想查詢MX記錄若治,可以通過下面兩種方式:
$ dig apple.com MX +noall +answer
; <<>> DiG 9.8.3-P1 <<>> apple.com MX +noall +answer
;; global options: +cmd
apple.com. 2460 IN MX 10 ma1-aaemail-dr-lapp02.apple.com.
apple.com. 2460 IN MX 10 ma1-aaemail-dr-lapp01.apple.com.
apple.com. 2460 IN MX 10 nwk-aaemail-lapp03.apple.com.
apple.com. 2460 IN MX 10 nwk-aaemail-lapp02.apple.com.
apple.com. 2460 IN MX 10 nwk-aaemail-lapp01.apple.com.
apple.com. 2460 IN MX 10 ma1-aaemail-dr-lapp03.apple.com.
$ dig -t MX apple.com +noall +answer
; <<>> DiG 9.8.3-P1 <<>> -t MX apple.com +noall +answer
;; global options: +cmd
apple.com. 2246 IN MX 10 nwk-aaemail-lapp03.apple.com.
apple.com. 2246 IN MX 10 nwk-aaemail-lapp02.apple.com.
apple.com. 2246 IN MX 10 nwk-aaemail-lapp01.apple.com.
apple.com. 2246 IN MX 10 ma1-aaemail-dr-lapp03.apple.com.
apple.com. 2246 IN MX 10 ma1-aaemail-dr-lapp02.apple.com.
apple.com. 2246 IN MX 10 ma1-aaemail-dr-lapp01.apple.com.
4.查詢NS記錄
如果只想查詢NS記錄,可以通過下面兩種方式:
$ dig apple.com NS +noall +answer
; <<>> DiG 9.8.3-P1 <<>> apple.com NS +noall +answer
;; global options: +cmd
apple.com. 79319 IN NS nserver6.apple.com.
apple.com. 79319 IN NS nserver5.apple.com.
apple.com. 79319 IN NS adns1.apple.com.
apple.com. 79319 IN NS adns2.apple.com.
apple.com. 79319 IN NS nserver4.apple.com.
apple.com. 79319 IN NS nserver.apple.com.
apple.com. 79319 IN NS nserver3.apple.com.
apple.com. 79319 IN NS nserver2.apple.com.
$ dig -t NS apple.com +noall +answer
; <<>> DiG 9.8.3-P1 <<>> -t NS apple.com +noall +answer
;; global options: +cmd
apple.com. 71342 IN NS nserver6.apple.com.
apple.com. 71342 IN NS nserver5.apple.com.
apple.com. 71342 IN NS adns1.apple.com.
apple.com. 71342 IN NS adns2.apple.com.
apple.com. 71342 IN NS nserver4.apple.com.
apple.com. 71342 IN NS nserver.apple.com.
apple.com. 71342 IN NS nserver3.apple.com.
apple.com. 71342 IN NS nserver2.apple.com.
5.查詢所有的DNS記錄
如果要查詢所有的DNS記錄(A,MX,NS,AAAA等)感混,可以用下面的方法:
$ dig apple.com ANY +noall +answer
;; Truncated, retrying in TCP mode.
; <<>> DiG 9.8.3-P1 <<>> apple.com ANY +noall +answer
;; global options: +cmd
apple.com. 2108 IN A 17.142.160.59
apple.com. 2108 IN A 17.172.224.47
apple.com. 2108 IN A 17.178.96.59
apple.com. 2108 IN TXT "v=spf1 ip4:17.0.0.0/8 -all"
apple.com. 2108 IN TXT "google-site-verification=K-60dwNhM3vJSf7VklDuQvAynXRiw9yAdV10rpsWT4E"
apple.com. 84908 IN NS nserver2.apple.com.
apple.com. 84908 IN NS nserver6.apple.com.
apple.com. 84908 IN NS adns1.apple.com.
apple.com. 84908 IN NS nserver4.apple.com.
apple.com. 84908 IN NS nserver5.apple.com.
apple.com. 84908 IN NS nserver.apple.com.
apple.com. 84908 IN NS nserver3.apple.com.
apple.com. 84908 IN NS adns2.apple.com.
apple.com. 84908 IN NAPTR 90 50 "se" "SIP+D2T" "" _sip._tcp.apple.com.
apple.com. 84908 IN NAPTR 50 50 "se" "SIPS+D2T" "" _sips._tcp.apple.com.
apple.com. 84908 IN NAPTR 100 50 "se" "SIP+D2U" "" _sip._udp.apple.com.
apple.com. 2108 IN MX 10 nwk-aaemail-lapp03.apple.com.
apple.com. 2108 IN MX 10 nwk-aaemail-lapp02.apple.com.
apple.com. 2108 IN MX 10 nwk-aaemail-lapp01.apple.com.
apple.com. 2108 IN MX 10 ma1-aaemail-dr-lapp03.apple.com.
apple.com. 2108 IN MX 10 ma1-aaemail-dr-lapp02.apple.com.
apple.com. 2108 IN MX 10 ma1-aaemail-dr-lapp01.apple.com.
apple.com. 84908 IN SOA gridmaster-ib.apple.com. hostmaster.apple.com. 2010101622 900 900 2016000 86500```
#### 6.查詢short信息(僅IP地址)
$ dig apple.com +short
17.142.160.59
17.172.224.47
17.178.96.59
當(dāng)然你也可以指定要查詢的記錄類型
$ dig apple.com NS +short
nserver6.apple.com.
nserver5.apple.com.
adns1.apple.com.
adns2.apple.com.
nserver4.apple.com.
nserver.apple.com.
nserver3.apple.com.
nserver2.apple.com.
#### 7.查詢IP對應(yīng)的域名信息
$ dig -x 17.142.160.59
;; Truncated, retrying in TCP mode.
; <<>> DiG 9.8.3-P1 <<>> -x 17.142.160.59
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22425
;; flags: qr rd ra; QUERY: 1, ANSWER: 47, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;59.160.142.17.in-addr.arpa. IN PTR
;; ANSWER SECTION:
59.160.142.17.in-addr.arpa. 3599 IN PTR ripmixburn.com.
59.160.142.17.in-addr.arpa. 3599 IN PTR yessql.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR webobjects.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR ubnw.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR skyvines.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR shopdifferent.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR sherlock.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR quicktimetv.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR quicktimelive.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR powermac.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR powerbook.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR macosx.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR appleshare.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR applescript.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR applepaysupplies.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR applepaymerchantsupplies.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR applepay.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR applemasters.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR appleexpo.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR applecomputerinc.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR applecentre.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR airtunes.info.
59.160.142.17.in-addr.arpa. 3599 IN PTR apple.by.
59.160.142.17.in-addr.arpa. 3599 IN PTR apples-msk.ru.
59.160.142.17.in-addr.arpa. 3599 IN PTR icloud.se.
59.160.142.17.in-addr.arpa. 3599 IN PTR icloud.es.
59.160.142.17.in-addr.arpa. 3599 IN PTR icloud.om.
59.160.142.17.in-addr.arpa. 3599 IN PTR icloudo.com.
59.160.142.17.in-addr.arpa. 3599 IN PTR icloud.ch.
59.160.142.17.in-addr.arpa. 3599 IN PTR icloud.fr.
59.160.142.17.in-addr.arpa. 3599 IN PTR icloude.com.
59.160.142.17.in-addr.arpa. 3599 IN PTR camelspaceeffect.com.
59.160.142.17.in-addr.arpa. 3599 IN PTR camelphat.com.
59.160.142.17.in-addr.arpa. 3599 IN PTR alchemysynth.com.
59.160.142.17.in-addr.arpa. 3599 IN PTR openni.org.
59.160.142.17.in-addr.arpa. 3599 IN PTR swell.am.
59.160.142.17.in-addr.arpa. 3599 IN PTR appleweb.net.
59.160.142.17.in-addr.arpa. 3599 IN PTR apple.com.
59.160.142.17.in-addr.arpa. 3599 IN PTR pv-apple-com.apple.com.
59.160.142.17.in-addr.arpa. 3599 IN PTR ipad.host.
59.160.142.17.in-addr.arpa. 3599 IN PTR iphone.host.
59.160.142.17.in-addr.arpa. 3599 IN PTR chomp.com.
59.160.142.17.in-addr.arpa. 3599 IN PTR itunes.earth.
59.160.142.17.in-addr.arpa. 3599 IN PTR mac.one.
59.160.142.17.in-addr.arpa. 3599 IN PTR imac.one.
59.160.142.17.in-addr.arpa. 3599 IN PTR ipadpro.buzz.
59.160.142.17.in-addr.arpa. 3599 IN PTR airport.brussels.
;; Query time: 78 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Wed Apr 12 12:57:40 2017
;; MSG SIZE rcvd: 1207
我的皮皮蝦都驚呆了端幼,大廠的域名就是多呀
#### 8.指定域名服務(wù)器進行查詢
當(dāng)然你也可以在指定的域名服務(wù)器上面進行查詢,你高興就好:
先查一下APPLE有些什么域名服務(wù)器:
$ dig apple.com NS +short
nserver6.apple.com.
nserver5.apple.com.
adns1.apple.com.
adns2.apple.com.
nserver4.apple.com.
nserver.apple.com.
nserver3.apple.com.
nserver2.apple.com.
再選取其中一個弧满,進行后續(xù)的查詢:
$ dig adns1.apple.com. apple.com +short
17.151.0.151
17.172.224.47
17.178.96.59
17.142.160.59
#### 9.查詢多個域名
你可以把要查詢的信息寫到文件里面婆跑,注意分行哦,然后執(zhí)行dig -f <filename> [option] 來進行查詢:
$ vi domains.txt
apple.com
centos.org
接下來執(zhí)行dig -f,就可以一次查詢多個域名了庭呜,是不是很爽
$ dig -f domains.txt +noall +answer
apple.com. 114 IN A 17.172.224.47
apple.com. 114 IN A 17.178.96.59
apple.com. 114 IN A 17.142.160.59
centos.org. 43 IN A 85.12.30.226
當(dāng)然你也可以這樣寫:
$ dig -f domains.txt MX +noall +answer
apple.com. 3178 IN MX 10 nwk-aaemail-lapp03.apple.com.
apple.com. 3178 IN MX 10 nwk-aaemail-lapp02.apple.com.
apple.com. 3178 IN MX 10 nwk-aaemail-lapp01.apple.com.
apple.com. 3178 IN MX 10 ma1-aaemail-dr-lapp03.apple.com.
apple.com. 3178 IN MX 10 ma1-aaemail-dr-lapp02.apple.com.
apple.com. 3178 IN MX 10 ma1-aaemail-dr-lapp01.apple.com.
centos.org. 1794 IN MX 20 mail2.centos.org.
centos.org. 1794 IN MX 10 mail.centos.org.
這樣寫:
$ dig apple.com MX +noall +answer centos.org NS +short
10 nwk-aaemail-lapp03.apple.com.
10 nwk-aaemail-lapp02.apple.com.
10 nwk-aaemail-lapp01.apple.com.
10 ma1-aaemail-dr-lapp03.apple.com.
10 ma1-aaemail-dr-lapp02.apple.com.
10 ma1-aaemail-dr-lapp01.apple.com.
ns4.centos.org.
ns3.centos.org.
ns1.centos.org.
#### 10.增加$HOME/.digrc文件存儲默認查詢選項
如果你的用戶目錄下面沒有.digrc文件滑进,新建一個犀忱,輸入+noall +answer,相當(dāng)于每次查詢的時候都加上這兩個參數(shù),這樣使用起來是不是清新爽朗的多了....
$ dig apple.com
apple.com. 3213 IN A 17.172.224.47
apple.com. 3213 IN A 17.178.96.59
apple.com. 3213 IN A 17.142.160.59
$ dig apple.com MX
apple.com. 3028 IN MX 10 nwk-aaemail-lapp03.apple.com.
apple.com. 3028 IN MX 10 nwk-aaemail-lapp02.apple.com.
apple.com. 3028 IN MX 10 nwk-aaemail-lapp01.apple.com.
apple.com. 3028 IN MX 10 ma1-aaemail-dr-lapp03.apple.com.
apple.com. 3028 IN MX 10 ma1-aaemail-dr-lapp02.apple.com.
apple.com. 3028 IN MX 10 ma1-aaemail-dr-lapp01.apple.com.
#### 好啦扶关,DIG的使用就是這樣啦阴汇,是不是很強大,很好用...