Domain-Name-System

NAT 後面的 DNS 伺服器

  • November 17, 2020

我有一個位於 NAT 防火牆後面的 Bind 9 DNS 伺服器,假設面向 Internet 的 IP 是 1.2.3.4

傳出流量沒有限制,埠 53 (TCP/UDP) 從 1.2.3.4 轉發到內部 DNS 伺服器 (10.0.0.1)。VPS 或內部 Bind 9 伺服器上沒有 IP 表規則。

從位於網際網路其他地方的遠端 Linux VPS,nslookup 工作正常

# nslookup foo.example.com 1.2.3.4
Server:    1.2.3.4
Address:   1.2.3.4#53

Name:      foo.example.com
Addresss:  9.9.9.9

但是,在host遠端 VPS 上使用該命令時,我收到以下輸出:

# host foo.example.com 1.2.3.4
;; reply from unexpected source: 1.2.3.4#13731, expected 1.2.3.4#53
;; reply from unexpected source: 1.2.3.4#13731, expected 1.2.3.4#53
;; connection timed out; no servers could be reached.

從 VPS,我可以建立到 1.2.3.4:53 的連接(使用 telnet)

從內部 DNS 伺服器 (10.0.0.1),主機命令似乎沒問題:

# host foo.example.com 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

foo.example.com has address 9.9.9.9

關於為什麼我的 VPS 上的主機命令抱怨從另一個埠返回的回复的任何建議,我能做些什麼來解決這個問題?


更多資訊:

從網路外部的 Windows 主機

>nslookup foo.example.com 1.2.3.4
DNS request timeout
   timeout was 2 seconds
Server: UnKnown
Address: 1.2.3.4

DNS request timed out.
   timeout was 2 seconds
DNS request timed out.
   timeout was 2 seconds
DNS request timed out.
   timeout was 2 seconds
DNS request timed out.
   timeout was 2 seconds
*** Request to UnKnown timed-out

這是 Ubuntu 12.04 LTS 的預設綁定安裝,配置了大約 11 個區域。

$ named -v
BIND 9.8.1-P1

來自內部 DNS 伺服器的 TCP 轉儲(過濾)

20:36:29.175701 IP pc.external.com.57226 > dns.example.com.domain: 1+ PTR? 4.3.2.1.in-addr.arpa. (45)
20:36:29.175948 IP dns.example.com.domain > pc.external.com.57226: 1 Refused- 0/0/0 (45)
20:36:31.179786 IP pc.external.com.57227 > dns.example.com.domain: 2+[|domain]
20:36:31.179960 IP dns.example.com.domain > pc.external.com.57227: 2 Refused-[|domain]
20:36:33.180653 IP pc.external.com.57228 > dns.example.com.domain: 3+[|domain]
20:36:33.180906 IP dns.example.com.domain > pc.external.com.57228: 3 Refused-[|domain]
20:36:35.185182 IP pc.external.com.57229 > dns.example.com.domain: 4+ A? foo.example.com. (45)
20:36:35.185362 IP dns.example.com.domain > pc.external.com.57229: 4*- 1/1/1 (95)
20:36:37.182844 IP pc.external.com.57230 > dns.example.com.domain: 5+ AAAA? foo.example.com. (45)
20:36:37.182991 IP dns.example.com.domain > pc.external.com.57230: 5*- 0/1/0 (119)

查詢期間來自客戶端的 TCP 轉儲

21:24:52.054374 IP pc.external.com.43845 > dns.example.com.53: 6142+ A? foo.example.com. (45)
21:24:52.104694 IP dns.example.com.29242 > pc.external.com.43845: UDP, length 95

總結一下之前在評論中寫的內容,並提供一些進一步的解釋:

看起來有點像你的 UDP NAT 規則被破壞了。一個指示是錯誤消息reply from unexpected source: 1.2.3.4#13731, expected 1.2.3.4#53和從響應看起來像的客戶端獲取的跟踪dns.example.com.29242 > pc.external.com.43845: UDP, length 95。響應數據包的源埠應該是 53,它在從 DNS 伺服器獲取的轉儲中是正確的(domain為了顯示目的解析為)。

雖然一些(尤其是歷史悠久的)解析器可能會接受來自不同埠/IP 的 DNS 響應,但大多數不會——主要是出於安全原因,以阻止DNS 欺騙和記憶體中毒攻擊

無論如何,對於無連接的 UDP NAT 流量,您的路由器應該保留先前收到的 UDP DNS 查詢數據包的狀態數據,並將響應數據包的 IP:port 元組重新映射回 1.2.3.4:53 - 它顯然沒有. 這可能是路由器處理埠轉發案例的 UDP 狀態表的方式中的配置錯誤或錯誤 - 所以最好的辦法是打開製造商客戶支持的案例(已將程式碼升級到最新/最好的事先 - 這樣的問題很可能已經被其他使用者注意到,因此很可能已經得到修復)。

引用自:https://serverfault.com/questions/426023