Dns.GetHostEntry错误情况及解决方法
我有一个关于 Dns.GetHostEntry 的非常具体的问题:
服务使用 Dns.GetHostEntry 来检索主机的所有 IP 地址,并使用主机的名称。这一直运作良好。 对于特定客户,Dns.GetHostEntry 在查询特定主机时会抛出“没有已知的主机”错误。仅当尝试解析与安装服务的计算机位于不同域的主机时,才会出现此问题。该服务已经工作了相当长一段时间,但最近停止工作,抛出“没有已知的主机”错误(遗憾的是,没有可用的堆栈跟踪)。 Nslookup 可以工作,没有问题。 该服务是用 VB.NET 编写的,针对 .NET Framwork 2.0。
.NET 3.0 的 MSDN 条目中的注释 (http ://msdn.microsoft.com/en-us/library/ms143998(v=VS.85).aspx 表明主机的反向 DNS 条目可能存在问题,但我无法在测试网络上重现问题,即使删除了所有反向查找区域(其他 .NET 版本还有更多评论,都存在类似问题)[编辑:] 即使故意添加错误的 PTR 记录也不会导致问题发生。 仍然
[EDIT2:] 唯一导致错误的原因是断开网络适配器,从而使 DNS 服务器不可用,尽管由于缓存,转发解析
。
- 有效 GetHostEntry 在哪些条件下会抛出此特定错误?
- 如果我没有记错的话,它使用非托管 WinSock 函数 getnameinfo (http://msdn.microsoft.com/en-us/library/ms738532(v=vs.85).aspx), :“名称解析可以通过域名系统(DNS)、本地主机文件或其他命名机制进行”。
- 任何想法为什么这对于其他域上的计算机突然失败(但不是对于同一域上的机器)?
谢谢并致以最诚挚的问候, 村83
I have a very specific problem concerning Dns.GetHostEntry:
A service uses Dns.GetHostEntry to retrieve all IP Adresses of a host, using the name of of the host. This has always worked fine.
At a specific customer, Dns.GetHostEntry throws the "no such host is known" error when querying specific hosts. The problem only occurs when trying to resolve hosts that are on a different domain than the machine the service is installed on. The service has worked for quite some time, but recently is stopped working, throwing the "no such host is known" error (sadly, no stack trace is available). Nslookup works though, no problems there.
The service in question is written in VB.NET, targetting the .NET Framwork 2.0.
The comments in the MSDN entry for .NET 3.0 (http://msdn.microsoft.com/en-us/library/ms143998(v=VS.85).aspx indictate that there may be a problem with the reverse DNS entries for the hosts, but I was not able to reproduce the problem on a test network, even with all reverse lookup zones deleted (there are more comments for other .NET Versions, all having similiar problems). [EDIT:] Even deliberatly addind a wrong PTR record does not make the problem occur on my test machine.
[EDIT2:] The only thing that made the error come up was disconnecting the network adapter, and thereby making the DNS Server unavailable, even though the forward resolving still worked due to caching.
So, my questions are:
- Under which conditions does GetHostEntry throw this specific error?
- Which resolution methods does it use? If I'm not mistaken it uses the unmanaged WinSock function getnameinfo (http://msdn.microsoft.com/en-us/library/ms738532(v=vs.85).aspx),: "Name resolution can be by the Domain Name System (DNS), a local hosts file, or by other naming mechanisms".
- Any ideas why this suddenly fails for machines on the other domain (but not for machines on the same domain)?
Thanks and best regards,
cun83
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我个人总是使用 Dns.GetHostAddresses。它总是给我一个可靠的结果。
关于为什么 Dns.GetHostEntry 为您提供指定的错误,我认为这是由于 DnsGetHostEntry< /a> 将在返回 IP 地址之前尝试进行反向 DNS 查找。如果反向 DNS 查找失败,则会显示“没有已知的主机”。
据我所知, Dns.GetHostAddresses只返回 IP 地址。
I personally always use Dns.GetHostAddresses. It always gives me a reliable result.
Regarding to why Dns.GetHostEntry gives you the specified error, I think it's due to the fact that DnsGetHostEntry will attempt to do a reverse DNS lookup before returning you the IP address. If reverse DNS lookup fails, it will give you "no such host is known".
As far as I know, Dns.GetHostAddresses just returns the IP address.