Dig命令模仿迭代
導讀 | 頂級域名伺服器告訴我們,fasionchan.com 這個域應該去找 f1g1ns1.dnspod.net. 或 f1g1ns2.dnspod.net. 來解析。這二者就是 fasionchan.com 的 權威域名伺服器。 |
DNS伺服器的工作原理,它們可以分為很多個角色:
根域名伺服器 頂級域名伺服器 權威域名伺服器 遞迴解析器(DNS快取伺服器)
於此同時,我們還了解了域名迭代解析的過程。本節我們趁熱打鐵,安排一次實驗——按步驟迭代解析域名test.fasionchan.com ,以此加深理解。
迭代解析從 根域名伺服器 開始,根伺服器列表可以從 root-servers.org 上獲取,也可以透過 dig 查詢:
root@netbox [ ~ ] ➜ dig . NS ; <<>> DiG 9.16.1-Ubuntu <<>> @10.2.66.66 . NS ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42791 ;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 8 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4000 ;; QUESTION SECTION: ;. IN NS ;; ANSWER SECTION: . 1700 IN NS k.root-servers.net. . 1700 IN NS m.root-servers.net. . 1700 IN NS l.root-servers.net. . 1700 IN NS b.root-servers.net. . 1700 IN NS g.root-servers.net. . 1700 IN NS f.root-servers.net. . 1700 IN NS d.root-servers.net. . 1700 IN NS e.root-servers.net. . 1700 IN NS i.root-servers.net. . 1700 IN NS a.root-servers.net. . 1700 IN NS h.root-servers.net. . 1700 IN NS j.root-servers.net. . 1700 IN NS c.root-servers.net. ;; ADDITIONAL SECTION: k.root-servers.net. 3282 IN A 193.0.14.129 g.root-servers.net. 2845 IN A 192.112.36.4 d.root-servers.net. 118 IN A 199.7.91.13 e.root-servers.net. 494 IN A 192.203.230.10 a.root-servers.net. 1771 IN A 198.41.0.4 j.root-servers.net. 3197 IN A 192.58.128.30 c.root-servers.net. 1830 IN A 192.33.4.12 ;; Query time: 14 msec ;; SERVER: 10.2.66.66#53(10.2.66.66) ;; WHEN: Thu Apr 08 09:01:17 CST 2021 ;; MSG SIZE rcvd: 364
根域名伺服器總共有 13 臺,編號從 A 到 M 。我們可以從中選擇一臺,比如 A ,它的 IP 地址是 198.41.0.4 。
接下來,我們執行 dig ,向根域名伺服器 A 發起域名解析請求:
root@netbox [ ~ ] ➜ dig @198.41.0.4 test.fasionchan.com ; <<>> DiG 9.16.1-Ubuntu <<>> @198.41.0.4 test.fasionchan.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44843 ;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27 ;; WARNING: recursion requested but not available ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1472 ;; QUESTION SECTION: ;test.fasionchan.com. IN A ;; AUTHORITY SECTION: 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. ;; ADDITIONAL SECTION: a.gtld-servers.net. 172800 IN A 192.5.6.30 b.gtld-servers.net. 172800 IN A 192.33.14.30 c.gtld-servers.net. 172800 IN A 192.26.92.30 d.gtld-servers.net. 172800 IN A 192.31.80.30 e.gtld-servers.net. 172800 IN A 192.12.94.30 f.gtld-servers.net. 172800 IN A 192.35.51.30 g.gtld-servers.net. 172800 IN A 192.42.93.30 h.gtld-servers.net. 172800 IN A 192.54.112.30 i.gtld-servers.net. 172800 IN A 192.43.172.30 j.gtld-servers.net. 172800 IN A 192.48.79.30 k.gtld-servers.net. 172800 IN A 192.52.178.30 l.gtld-servers.net. 172800 IN A 192.41.162.30 m.gtld-servers.net. 172800 IN A 192.55.83.30 a.gtld-servers.net. 172800 IN AAAA 2001:503:a83e::2:30 b.gtld-servers.net. 172800 IN AAAA 2001:503:231d::2:30 c.gtld-servers.net. 172800 IN AAAA 2001:503:83eb::30 d.gtld-servers.net. 172800 IN AAAA 2001:500:856e::30 e.gtld-servers.net. 172800 IN AAAA 2001:502:1ca1::30 f.gtld-servers.net. 172800 IN AAAA 2001:503:d414::30 g.gtld-servers.net. 172800 IN AAAA 2001:503:eea3::30 h.gtld-servers.net. 172800 IN AAAA 2001:502:8cc::30 i.gtld-servers.net. 172800 IN AAAA 2001:503:39c1::30 j.gtld-servers.net. 172800 IN AAAA 2001:502:7094::30 k.gtld-servers.net. 172800 IN AAAA 2001:503:d2d::30 l.gtld-servers.net. 172800 IN AAAA 2001:500:d937::30 m.gtld-servers.net. 172800 IN AAAA 2001:501:b1f9::30 ;; Query time: 169 msec ;; SERVER: 198.41.0.4#53(198.41.0.4) ;; WHEN: Fri Apr 09 08:38:10 CST 2021 ;; MSG SIZE rcvd: 843
其中,@ 指定目標 DNS 伺服器的地址。
從 dig 命令的輸出可以看到,根域名伺服器告訴我們 .com 域名應該去找 a.gtld-servers.net. 等伺服器。這些伺服器都是 .com 的 頂級域名伺服器 ,根域名伺服器把它們的地址一併告訴我們了。
我們可以從這些頂級域名伺服器中選擇一臺,比如 a.gtld-servers.net. ,它的 IP 地址是 192.5.6.30 。然後,再次指定 dig 命令,向它發起域名解析請求:
root@netbox [ ~ ] ➜ dig @192.5.6.30 test.fasionchan.com ; <<>> DiG 9.16.1-Ubuntu <<>> @192.5.6.30 test.fasionchan.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7836 ;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 2, ADDITIONAL: 1 ;; WARNING: recursion requested but not available ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;test.fasionchan.com. IN A ;; AUTHORITY SECTION: fasionchan.com. 172800 IN NS f1g1ns1.dnspod.net. fasionchan.com. 172800 IN NS f1g1ns2.dnspod.net. ;; Query time: 212 msec ;; SERVER: 192.5.6.30#53(192.5.6.30) ;; WHEN: Fri Apr 09 08:38:58 CST 2021 ;; MSG SIZE rcvd: 101
頂級域名伺服器告訴我們,fasionchan.com 這個域應該去找 f1g1ns1.dnspod.net. 或 f1g1ns2.dnspod.net. 來解析。這二者就是 fasionchan.com 的 權威域名伺服器 。
但這次 .com 域名沒有告訴我們 f1g1ns1.dnspod.net. 或 f1g1ns2.dnspod.net. 的 IP 地址。因此,我們必須先自己動手,將它們的域名解析成 IP 地址。
我們可以直接執行 dig 命令,一鍵完成解析:
root@netbox [ ~ ] ➜ dig f1g1ns1.dnspod.net. ; <<>> DiG 9.16.1-Ubuntu <<>> f1g1ns1.dnspod.net. ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6244 ;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;f1g1ns1.dnspod.net. IN A ;; ANSWER SECTION: f1g1ns1.dnspod.net. 15 IN A 58.247.212.36 f1g1ns1.dnspod.net. 15 IN A 61.151.180.44 f1g1ns1.dnspod.net. 15 IN A 129.211.176.187 f1g1ns1.dnspod.net. 15 IN A 162.14.25.230 f1g1ns1.dnspod.net. 15 IN A 183.192.164.118 ;; Query time: 13 msec ;; SERVER: 192.168.65.1#53(192.168.65.1) ;; WHEN: Fri Apr 09 08:39:38 CST 2021 ;; MSG SIZE rcvd: 116
如果 dig 命令未指定 DNS 伺服器,它預設會到本地的 遞迴解析器 ,也就是 DNS快取伺服器 上去查詢。DNS快取伺服器會幫我們做迭代解析,再把結果告訴我們。
如果親不厭其煩,可以自己進行迭代解析。具體步驟也是類似的,附在本文後半部分。
得到權威域名伺服器的 IP 地址後,我們就可以向它發起解析請求:
root@netbox [ ~ ] ➜ dig @58.247.212.36 test.fasionchan.com ; <<>> DiG 9.16.1-Ubuntu <<>> @58.247.212.36 test.fasionchan.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42646 ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1 ;; WARNING: recursion requested but not available ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;test.fasionchan.com. IN A ;; ANSWER SECTION: test.fasionchan.com. 600 IN A 10.0.0.1 ;; AUTHORITY SECTION: fasionchan.com. 600 IN NS f1g1ns2.dnspod.net. fasionchan.com. 600 IN NS f1g1ns1.dnspod.net. ;; Query time: 57 msec ;; SERVER: 58.247.212.36#53(58.247.212.36) ;; WHEN: Fri Apr 09 08:55:47 CST 2021 ;; MSG SIZE rcvd: 128
瞧,我們成功解析域名 test.fasionchan.com ,得到它對應的 IP 地址 10.0.0.1 !
迭代解析 f1g1ns1.dnspod.net.
如果不想透過遞迴解析器,可以自行執行迭代解析,查詢 f1g1ns1.dnspod.net. 的 IP 地址。
首先,向 根域名伺服器 發起解析請求:
root@netbox [ ~ ] ➜ dig @198.41.0.4 f1g1ns1.dnspod.net. ; <<>> DiG 9.16.1-Ubuntu <<>> @198.41.0.4 f1g1ns1.dnspod.net. ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49636 ;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27 ;; WARNING: recursion requested but not available ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1472 ;; QUESTION SECTION: ;f1g1ns1.dnspod.net. IN A ;; AUTHORITY SECTION: net. 172800 IN NS a.gtld-servers.net. net. 172800 IN NS b.gtld-servers.net. net. 172800 IN NS c.gtld-servers.net. net. 172800 IN NS d.gtld-servers.net. net. 172800 IN NS e.gtld-servers.net. net. 172800 IN NS f.gtld-servers.net. net. 172800 IN NS g.gtld-servers.net. net. 172800 IN NS h.gtld-servers.net. net. 172800 IN NS i.gtld-servers.net. net. 172800 IN NS j.gtld-servers.net. net. 172800 IN NS k.gtld-servers.net. net. 172800 IN NS l.gtld-servers.net. net. 172800 IN NS m.gtld-servers.net. ;; ADDITIONAL SECTION: a.gtld-servers.net. 172800 IN A 192.5.6.30 b.gtld-servers.net. 172800 IN A 192.33.14.30 c.gtld-servers.net. 172800 IN A 192.26.92.30 d.gtld-servers.net. 172800 IN A 192.31.80.30 e.gtld-servers.net. 172800 IN A 192.12.94.30 f.gtld-servers.net. 172800 IN A 192.35.51.30 g.gtld-servers.net. 172800 IN A 192.42.93.30 h.gtld-servers.net. 172800 IN A 192.54.112.30 i.gtld-servers.net. 172800 IN A 192.43.172.30 j.gtld-servers.net. 172800 IN A 192.48.79.30 k.gtld-servers.net. 172800 IN A 192.52.178.30 l.gtld-servers.net. 172800 IN A 192.41.162.30 m.gtld-servers.net. 172800 IN A 192.55.83.30 a.gtld-servers.net. 172800 IN AAAA 2001:503:a83e::2:30 b.gtld-servers.net. 172800 IN AAAA 2001:503:231d::2:30 c.gtld-servers.net. 172800 IN AAAA 2001:503:83eb::30 d.gtld-servers.net. 172800 IN AAAA 2001:500:856e::30 e.gtld-servers.net. 172800 IN AAAA 2001:502:1ca1::30 f.gtld-servers.net. 172800 IN AAAA 2001:503:d414::30 g.gtld-servers.net. 172800 IN AAAA 2001:503:eea3::30 h.gtld-servers.net. 172800 IN AAAA 2001:502:8cc::30 i.gtld-servers.net. 172800 IN AAAA 2001:503:39c1::30 j.gtld-servers.net. 172800 IN AAAA 2001:502:7094::30 k.gtld-servers.net. 172800 IN AAAA 2001:503:d2d::30 l.gtld-servers.net. 172800 IN AAAA 2001:500:d937::30 m.gtld-servers.net. 172800 IN AAAA 2001:501:b1f9::30 ;; Query time: 172 msec ;; SERVER: 198.41.0.4#53(198.41.0.4) ;; WHEN: Fri Apr 09 08:40:49 CST 2021 ;; MSG SIZE rcvd: 840
根域名伺服器告訴我們,.net 應該去找 a.gtld-servers.net. 等伺服器,伺服器地址附在後面的附加節。
我們選擇 a.gtld-servers.net. 這臺 頂級域名伺服器 ,它的地址是 192.5.6.30 。然後向它發起解析請求:
root@netbox [ ~ ] ➜ dig @192.5.6.30 f1g1ns1.dnspod.net. ; <<>> DiG 9.16.1-Ubuntu <<>> @192.5.6.30 f1g1ns1.dnspod.net. ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53457 ;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 2, ADDITIONAL: 7 ;; WARNING: recursion requested but not available ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;f1g1ns1.dnspod.net. IN A ;; AUTHORITY SECTION: dnspod.net. 172800 IN NS v6ns3.dnsv2.net. dnspod.net. 172800 IN NS v6ns4.dnsv2.com. ;; ADDITIONAL SECTION: v6ns3.dnsv2.net. 172800 IN A 129.211.176.248 v6ns3.dnsv2.net. 172800 IN A 162.14.24.245 v6ns3.dnsv2.net. 172800 IN A 183.192.164.118 v6ns3.dnsv2.net. 172800 IN A 223.166.151.17 v6ns3.dnsv2.net. 172800 IN AAAA 2402:4e00:1430:1102:0:9136:2b2f:bf6b v6ns3.dnsv2.net. 172800 IN A 61.129.8.141 ;; Query time: 213 msec ;; SERVER: 192.5.6.30#53(192.5.6.30) ;; WHEN: Fri Apr 09 08:41:27 CST 2021 ;; MSG SIZE rcvd: 210
頂級域名伺服器告訴我們,dnspod.net. 這個域應該去找 v6ns3.dnsv2.net. 或者 v6ns4.dnsv2.com. 。這兩者就是所謂的 權威域名伺服器 。這次,頂級域名伺服器已經在附加節中,附上了它們的 IP 地址。
我們從中挑選一個,比如 129.211.176.248 ,繼續發起解析請求:
root@netbox [ ~ ] ➜ dig @129.211.176.248 f1g1ns1.dnspod.net. ; <<>> DiG 9.16.1-Ubuntu <<>> @129.211.176.248 f1g1ns1.dnspod.net. ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23542 ;; flags: qr aa rd; QUERY: 1, ANSWER: 5, AUTHORITY: 2, ADDITIONAL: 1 ;; WARNING: recursion requested but not available ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;f1g1ns1.dnspod.net. IN A ;; ANSWER SECTION: f1g1ns1.dnspod.net. 172800 IN A 183.192.164.118 f1g1ns1.dnspod.net. 172800 IN A 162.14.25.230 f1g1ns1.dnspod.net. 172800 IN A 58.247.212.36 f1g1ns1.dnspod.net. 172800 IN A 61.151.180.44 f1g1ns1.dnspod.net. 172800 IN A 129.211.176.187 ;; AUTHORITY SECTION: dnspod.net. 86400 IN NS v6ns3.dnsv2.net. dnspod.net. 86400 IN NS v6ns4.dnsv2.com. ;; Query time: 34 msec ;; SERVER: 129.211.176.248#53(129.211.176.248) ;; WHEN: Fri Apr 09 08:42:07 CST 2021 ;; MSG SIZE rcvd: 185
最終,我們成功解析到 f1g1ns1.dnspod.net. 對應的 IP 地址,總共有 5 個。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69955379/viewspace-2773098/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- dig 命令
- dig的命令除錯除錯
- dig 命令的基本用法(轉)
- Linux基礎命令---dig工具Linux
- linux dig 命令使用方法Linux
- 使用 dig 命令挖掘域名解析資訊
- 如何使用dig命令挖掘域名解析資訊
- 常用網路命令 dig 詳解及使用示例
- dig 簡明教程
- DNS 解析除錯(dig & nslookup)DNS除錯
- 為什麼把 dig 遷移到 wire
- 模仿Google News的TabLayoutGoTabLayout
- 使用 Flutter 模仿美團 AppFlutterAPP
- 如何模仿MX抽獎
- 利用 uber-go/dig 庫管理依賴Go
- HDU 5067 Harry And Dig Machine:TSP(旅行商)Mac
- HDU 5067 Harry And Dig Machine(狀壓dp)Mac
- 模仿實驗樓專案
- Swift 4 - 模仿今日頭條Swift
- 模仿京東選擇地址器
- 從迭代器模式到迭代協議模式協議
- Python迭代和迭代器詳解Python
- 可迭代物件、迭代器、生成器物件
- Iterator與Iterable(迭代器與可迭代)
- 分解uber依賴注入庫dig-使用篇依賴注入
- 迭代器
- Jacobi迭代、Gauss_Seidel迭代和最佳因子SOR迭代的比較IDE
- Python可迭代的物件與迭代器Python物件
- 迭代器,迭代器塊和資料管道
- 用Java optional模仿Kotlin? - WelshJavaKotlin
- iOS 模仿淘寶的首頁UIiOSUI
- MySQL-模仿陣列使用方式MySql陣列
- Android 模仿微信啟動動畫Android動畫
- Dig101: Go之靈活的sliceGo
- Dig101: Go 之靈活的 sliceGo
- Dig101:Go之string那些事Go
- Linux系統中nslookup和dig安裝使用Linux
- 分解uber依賴注入庫dig-原始碼分析依賴注入原始碼