Linux dig command usage

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的使用就是這樣啦阴汇,是不是很強大,很好用...
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市驮审,隨后出現(xiàn)的幾起案子鲫寄,更是在濱河造成了極大的恐慌,老刑警劉巖疯淫,帶你破解...
    沈念sama閱讀 212,383評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件地来,死亡現(xiàn)場離奇詭異,居然都是意外死亡熙掺,警方通過查閱死者的電腦和手機未斑,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,522評論 3 385
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來币绩,“玉大人蜡秽,你說我怎么就攤上這事±铝停” “怎么了芽突?”我有些...
    開封第一講書人閱讀 157,852評論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長董瞻。 經(jīng)常有香客問我寞蚌,道長,這世上最難降的妖魔是什么钠糊? 我笑而不...
    開封第一講書人閱讀 56,621評論 1 284
  • 正文 為了忘掉前任挟秤,我火速辦了婚禮,結(jié)果婚禮上抄伍,老公的妹妹穿的比我還像新娘艘刚。我一直安慰自己,他們只是感情好截珍,可當(dāng)我...
    茶點故事閱讀 65,741評論 6 386
  • 文/花漫 我一把揭開白布攀甚。 她就那樣靜靜地躺著,像睡著了一般岗喉。 火紅的嫁衣襯著肌膚如雪秋度。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,929評論 1 290
  • 那天沈堡,我揣著相機與錄音,去河邊找鬼燕雁。 笑死诞丽,一個胖子當(dāng)著我的面吹牛鲸拥,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播僧免,決...
    沈念sama閱讀 39,076評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼刑赶,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了懂衩?” 一聲冷哼從身側(cè)響起撞叨,我...
    開封第一講書人閱讀 37,803評論 0 268
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎浊洞,沒想到半個月后牵敷,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,265評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡法希,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,582評論 2 327
  • 正文 我和宋清朗相戀三年枷餐,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片苫亦。...
    茶點故事閱讀 38,716評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡毛肋,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出屋剑,到底是詐尸還是另有隱情润匙,我是刑警寧澤,帶...
    沈念sama閱讀 34,395評論 4 333
  • 正文 年R本政府宣布唉匾,位于F島的核電站孕讳,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏肄鸽。R本人自食惡果不足惜卫病,卻給世界環(huán)境...
    茶點故事閱讀 40,039評論 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望典徘。 院中可真熱鬧蟀苛,春花似錦、人聲如沸逮诲。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,798評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽梅鹦。三九已至裆甩,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間齐唆,已是汗流浹背嗤栓。 一陣腳步聲響...
    開封第一講書人閱讀 32,027評論 1 266
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人茉帅。 一個月前我還...
    沈念sama閱讀 46,488評論 2 361
  • 正文 我出身青樓叨叙,卻偏偏與公主長得像,于是被迫代替她去往敵國和親堪澎。 傳聞我的和親對象是個殘疾皇子擂错,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,612評論 2 350

推薦閱讀更多精彩內(nèi)容