Nslookup Debug Mode
2025-03-18
筆記說明 Nslookup 搭配 Debug 進行網域解析
說明
Nslookup 啟用 debug 模式後,會顯示查詢的標頭(header)、問題(questions)、答案(answers)以及權威記錄(authority records),這些資訊對於理解 DNS 運作至關重要。
使用 nslookup
的實用技巧
- 輸入 FQDN:FQDN 必須包含最終的句點(例如:
example.com.
),減少尾綴自動添加的查詢錯誤。 - 啟用 Debug 模式:使用
nslookup -debug
獲取查詢與回應的詳細資訊。 - 檢查
auth. answer
:此標誌顯示回應是否為authority 。 - 觀察 TTL 值:整數 TTL(如 3600 秒)通常表示權威回應,逐漸減少的 TTL 則可能來自於快取回應。
- 分析權威記錄:若回應包含 SOA 或 NS 記錄指向其他伺服器,則查詢已被轉發。
什麼是「Authority 」?
Authority 表示該 DNS 伺服器擁有該域名記錄的原始、最可靠資料,而不是從其他地方轉發或快取的二手資訊。
Primary Name Server 是什麼?
負責儲存和管理特定網域名稱的 DNS 記錄的伺服器,管理者可以直接進行建立、修改予刪除 DNS 記錄,並且用於回應 DNS 查詢。
透過 nslookup -Type=NS
查詢網域的 Primary Name Server。
Authority Name Server 是什麼?
Authority Name Server 是指對於特定的網域名稱(或 DNS 區域)擁有 最終且正確 的 DNS 記錄的伺服器。當一個遞迴 DNS 伺服器(例如:你的 ISP 的 DNS 伺服器)需要解析一個網域名稱時,它最終會查詢該網域的權威名稱伺服器以獲取正確的 IP 位址或其他 DNS 記錄。
查詢 1:PTR 記錄查詢
首先,我們對 dns1.foo.bar
的 IP 地址(假設為 192.168.0.1
)進行 PTR(反向查詢)記錄查詢,目標是將 IP 轉換回主機名。這意味著查詢的是 1.0.168.192.in-addr.arpa
,預期結果應為 dns1.foo.bar
。
查詢與回應
------------
SendRequest(), len 43
HEADER:
opcode = QUERY, id = 1, rcode = NOERROR
header flags: query, want recursion
questions = 1, answers = 0, authority records = 0, additional = 0
QUESTIONS:
1.0.168.192.in-addr.arpa, type = PTR, class = IN
------------
------------
Got answer (74 bytes):
HEADER:
opcode = QUERY, id = 1, rcode = NOERROR
header flags: response, auth. answer, want recursion, recursion avail.
questions = 1, answers = 1, authority records = 0, additional = 0
QUESTIONS:
1.0.168.192.in-addr.arpa, type = PTR, class = IN
ANSWERS:
-> 1.0.168.192.in-addr.arpa
type = PTR, class = IN, dlen = 19
name = dns1.foo.bar
ttl = 1200 (20 mins)
------------
Server: dns1.foo.bar
Address: 192.168.0.1
分析
- 標誌(Flags):回應中包含
auth. answer
,表示這是一個權威回應。 - 答案(Answer):PTR 記錄指向
dns1.foo.bar
,TTL(生存時間)為 1200 秒(20 分鐘)。 - 結論:由於這是
dns1.foo.bar
自己的 IP 地址,它直接提供權威回應,無需轉發查詢。
查詢 2:A 記錄查詢
接著,我們查詢 app.sub.foo.bar
的 A 記錄(IPv4 地址)。由於 sub.foo.bar
由 dns2.baz.com
管理,dns1.foo.bar
可能需要轉發查詢或從快取中回應。
查詢與回應
------------
SendRequest(), len 37
HEADER:
opcode = QUERY, id = 2, rcode = NOERROR
header flags: query, want recursion
questions = 1, answers = 0, authority records = 0, additional = 0
QUESTIONS:
app.sub.foo.bar, type = A, class = IN
------------
------------
Got answer (53 bytes):
HEADER:
opcode = QUERY, id = 2, rcode = NOERROR
header flags: response, want recursion, recursion avail.
questions = 1, answers = 1, authority records = 0, additional = 0
QUESTIONS:
app.sub.foo.bar, type = A, class = IN
ANSWERS:
-> app.sub.foo.bar
type = A, class = IN, dlen = 4
internet address = 172.16.0.1
ttl = 1539 (25 mins 39 secs)
------------
分析
- 標誌(Flags):回應中沒有
auth. answer
,表示這不是權威回應。 - 答案(Answer):A 記錄返回 IP 地址
172.16.0.1
,TTL 為 1539 秒。 - TTL 值:TTL 不是整數(如 3600 或 1200),這暗示答案可能來自快取,因為 TTL 已從原始值減少。
- 結論:
dns1.foo.bar
可能從快取中回答,或者將查詢轉發給dns2.baz.com
(sub.foo.bar
的權威伺服器)後返回結果。由於沒有auth. answer
,這更像是快取回應。
查詢 3:AAAA 記錄查詢
最後,我們查詢 app.sub.foo.bar
的 AAAA 記錄(IPv6 地址)。同樣,sub.foo.bar
由 dns2.baz.com
管理,因此 dns1.foo.bar
應會轉發此查詢。
查詢與回應
------------
SendRequest(), len 37
HEADER:
opcode = QUERY, id = 3, rcode = NOERROR
header flags: query, want recursion
questions = 1, answers = 0, authority records = 0, additional = 0
QUESTIONS:
app.sub.foo.bar, type = AAAA, class = IN
------------
------------
Got answer (102 bytes):
HEADER:
opcode = QUERY, id = 3, rcode = NOERROR
header flags: response, want recursion, recursion avail.
questions = 1, answers = 0, authority records = 1, additional = 0
QUESTIONS:
app.sub.foo.bar, type = AAAA, class = IN
AUTHORITY RECORDS:
-> sub.foo.bar
type = SOA, class = IN, dlen = 53
ttl = 62 (1 min 2 secs)
primary name server = dns2.baz.com
responsible mail addr = admin.sub.foo.bar
serial = 483
refresh = 900 (15 mins)
retry = 600 (10 mins)
expire = 86400 (1 day)
default TTL = 3600 (1 hour)
------------
分析
- 標誌(Flags):回應中沒有
auth. answer
,表示這不是dns1.foo.bar
的權威回應。 - 答案(Answer):答案部分沒有 AAAA 記錄。
- 權威記錄(Authority Records):回應包含
sub.foo.bar
的 SOA 記錄,指向dns2.baz.com
作為主要名稱伺服器。 - TTL 值:SOA 記錄的 TTL 為 62 秒,非常短,可能是快取資料。
- 結論:
dns1.foo.bar
對sub.foo.bar
沒有 authority ,它將查詢轉發給dns2.baz.com
(或從快取中提取 SOA),並返回權威資訊。SOA 記錄表明dns2.baz.com
是該子域的權威伺服器。
總結與結論
通過分析這三個查詢的回應,我們可以推斷 dns1.foo.bar
在不同情境下的角色:
權威回應(查詢 1):
auth. answer
標誌確認dns1.foo.bar
對自己的 PTR 記錄具有 authority。- TTL 為整數(1200 秒),符合權威回應的特徵。
快取或轉發回應(查詢 2):
- 缺少
auth. answer
且 TTL 為非整數(1539 秒),表明dns1.foo.bar
可能從快取中回答,或將查詢轉發給dns2.baz.com
後返回。
轉發查詢與權威資訊(查詢 3):
- 無答案但包含指向
dns2.baz.com
的權威記錄,顯示dns1.foo.bar
將查詢轉發至權威伺服器。