nslookup 可以工作,但 ping 会随机失败并出现 DNS 错误

nslookup 可以工作,但 ping 会随机失败并出现 DNS 错误

我使用的是 Mac OS X 10.6.8。当我尝试 ping 某个特定域时,它返回“未知主机”,但当我在同一台主机上运行 nslookup 时,它立即返回正确的 IP。

Ping 持续抛出 DNS 错误近一分钟,然后自动恢复。

我查看了系统的 /var/log/system.log,发现在发生故障时记录了以下条目。我使用以下命令获取调试日志。

"killall -USR1 mDNSResponder"
"killall -USR2 mDNSResponder"
"killall -INFO mDNSResponder"

失败时的日志条目:

Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Adding FD for uid 501\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceCreateConnection START\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Error socket 30 created 00000000 00000001\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceQueryRecord(5000, 0, api-beta.mydomain.com., Addr) START\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Error socket 30 closed  00000000 00000001 (0)\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceQueryRecord(api-beta.mydomain.com., Addr) ADD    0 api-beta.mydomain.com. Addr \
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Cancel 00000000 00000001\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceQueryRecord(api-beta.mydomain.com., Addr) STOP\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Error socket 30 created 00000000 00000002\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceQueryRecord(5000, 0, api-beta.mydomain.com., Addr) START\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Error socket 30 closed  00000000 00000002 (0)\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceQueryRecord(api-beta.mydomain.com., Addr) ADD    0 api-beta.mydomain.com. Addr \
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Cancel 00000000 00000002\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceQueryRecord(api-beta.mydomain.com., Addr) STOP\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceCreateConnection STOP\
Feb 24 12:50:25 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Removing FD\
Feb 24 12:50:42 Administrators-MacBook-Pro-15 sudo[3675]: administrator : TTY=ttys004 ; PWD=/Users/administrator ; USER=root ; COMMAND=/usr/bin/killall -INFO mDNSResponder\
Feb 24 12:50:42 Administrators-MacBook-Pro-15 mDNSResponder[30]: ---- BEGIN STATE LOG ---- mDNSResponder mDNSResponder-258.21 (May 26 2011 14:40:13)\
Feb 24 12:50:42 Administrators-MacBook-Pro-15 mDNSResponder[30]: Timenow 0x91434D92 (-1857860206)\
Feb 24 12:50:42 Administrators-MacBook-Pro-15 mDNSResponder[30]: ------------ Cache -------------\
Feb 24 12:50:42 Administrators-MacBook-Pro-15 mDNSResponder[30]: Slt Q     TTL if     U Type rdlen\
Feb 24 12:50:42 Administrators-MacBook-Pro-15 mDNSResponder[30]:  28       269 -U-    - AAAA     0 api-beta.mydomain.com. AAAA \
Feb 24 12:50:42 Administrators-MacBook-Pro-15 mDNSResponder[30]:  28        31 -U-    - Addr     0 api-beta.mydomain.com. Addr \

在 DNS 故障恢复一分钟后,会记录以下条目。

成功时的日志条目:

Feb 24 12:52:55 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Adding FD for uid 501\
Feb 24 12:52:55 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceCreateConnection START\
Feb 24 12:52:55 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Error socket 30 created 00000000 00000001\
Feb 24 12:52:55 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceQueryRecord(5000, 0, api-beta.mydomain.com., Addr) START\
Feb 24 12:52:55 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Error socket 30 closed  00000000 00000001 (0)\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]: -- Sent UDP DNS Query (flags 0100) RCODE: NoErr (0) RD ID: 34816 29 bytes from port 62558 to 192.168.1.1:53 --\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  1 Questions\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  0 api-beta.mydomain.com. Addr\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  0 Answers\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  0 Authorities\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  0 Additionals\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]: --------------\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]: -- Received UDP DNS Response (flags 8180) RCODE: NoErr (0) RD RA ID: 34816 45 bytes from 192.168.1.1:53 to 192.168.1.2:62558 --\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  1 Questions\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  0 api-beta.mydomain.com. Addr\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  1 Answers\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  0 TTL      30    4 api-beta.mydomain.com. Addr 172.16.2.176\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  0 Authorities\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  0 Additionals\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]: --------------\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceQueryRecord(api-beta.mydomain.com., Addr) ADD    4 api-beta.mydomain.com. Addr 172.16.2.176\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Cancel 00000000 00000001\
Feb 24 12:52:56 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceQueryRecord(api-beta.mydomain.com., Addr) STOP\
Feb 24 12:52:59 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: DNSServiceCreateConnection STOP\
Feb 24 12:52:59 Administrators-MacBook-Pro-15 mDNSResponder[30]:  29: Removing FD\
Feb 24 12:53:18 Administrators-MacBook-Pro-15 mDNSResponder[30]: ---- BEGIN STATE LOG ---- mDNSResponder mDNSResponder-258.21 (May 26 2011 14:40:13)\
Feb 24 12:53:18 Administrators-MacBook-Pro-15 mDNSResponder[30]: Timenow 0x9145AF41 (-1857704127)\
Feb 24 12:53:18 Administrators-MacBook-Pro-15 mDNSResponder[30]: ------------ Cache -------------\
Feb 24 12:53:18 Administrators-MacBook-Pro-15 mDNSResponder[30]: Slt Q     TTL if     U Type rdlen\
Feb 24 12:53:18 Administrators-MacBook-Pro-15 mDNSResponder[30]:  28       113 -U-    - AAAA     0 api-beta.mydomain.com. AAAA \
Feb 24 12:53:18 Administrators-MacBook-Pro-15 mDNSResponder[30]:  28        17 -U-      Addr     4 api-beta.mydomain.com. Addr 172.16.2.176\

这是随机发生的,我每次都能重现这种情况,但无法理解错误的原因。

有人知道为什么 ping 会失败并出现“未知主机”以及如何解决它吗?

谢谢你!

答案1

您是否知道 mDNS 与普通的常规 DNS 有何不同?我并不是想无礼,而是想指出它们是两个不同的系统,试图解决类似的问题,但重要的是不要混淆这两者。

因此,回答您的问题,您似乎连接到了多个网络,并且通过 mdns 收到冲突或不频繁的响应。具体来说,从您的日志文件中,您收到的 mdns 响应表明 192.168.1.2 接口上的 api-beta.mydomain.com 的响应为 172.16.2.176 - 这似乎没有什么意义。

nslookup 应该直接向 DNS 服务器查询答案,由于您指出它工作正常,我怀疑 mdns 只是混淆了一切。我建议您按照以下 Apple 说明禁用 mdns 单播解析:

http://support.apple.com/kb/HT3789

希望这个方法有用!祝你好运

相关内容