Domain-Name-System

為什麼 host 和 nslookup 可以解析名稱而 dig 不能?

  • June 3, 2021

誰能告訴我為什麼會這樣?我可以使用 host 和/或 nslookup 解析主機名,但正向查找不適用於 dig;反向查找:

musashixxx@box:~$ host someserver
someserver.somenet.internal has address 192.168.0.252
musashixxx@box:~$ host 192.168.0.252
252.0.168.192.in-addr.arpa domain name pointer someserver.somenet.internal.
musashixxx@box:~$ nslookup someserver
Server:     192.168.0.253
Address:    192.168.0.253#53

Name:   someserver.somenet.internal
Address: 192.168.0.252
musashixxx@box:~$ nslookup 192.168.0.252
Server:     192.168.0.253
Address:    192.168.0.253#53

252.0.168.192.in-addr.arpa  name = someserver.somenet.internal.

musashixxx@box:~$ dig someserver

; <<>> DiG 9.8.1-P1 <<>> someserver
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 55306
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;someserver.            IN  A

;; Query time: 0 msec
;; SERVER: 192.168.0.253#53(192.168.0.253)
;; WHEN: Wed Oct  3 15:47:38 2012
;; MSG SIZE  rcvd: 27

musashixxx@box:~$ dig -x 192.168.0.252

; <<>> DiG 9.8.1-P1 <<>> -x 192.168.0.252
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28126
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;252.0.168.192.in-addr.arpa.    IN  PTR

;; ANSWER SECTION:
252.0.168.192.in-addr.arpa. 3600 IN PTR someserver.somenet.internal.

;; Query time: 0 msec
;; SERVER: 192.168.0.253#53(192.168.0.253)
;; WHEN: Wed Oct  3 15:49:11 2012
;; MSG SIZE  rcvd: 86

這是我的 resolv.conf 的樣子:

nameserver 192.168.0.253
search somenet.internal

這種行為正常嗎?有什麼想法嗎?

dig 的預設行為是不使用搜尋選項。

從手冊頁:

   +[no]search
       Use [do not use] the search list defined by the searchlist or
       domain directive in resolv.conf (if any). The search list is not
       used by default.

編輯:只需添加+search以使其工作,例如dig +search myhost.

在我的情況下,這是 Microsoft DNS 伺服器中的一個錯誤,它會為帶有選項集FORMERR的請求返迴響應(請求格式錯誤) 。EDNS Cookie較新版本dig(9.11 及更高版本)預設使用 dns-cookies。這可以通過+nocookie+noedns標誌來防止:

$ dig +nocookie DOMAIN @SERVER

資料來源:https ://kevinlocke.name/bits/2017/01/20/formerr-from-microsoft-dns-server-for-dig/

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