Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dns.GetHostEntry error conditions and resolution methods

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:

  1. Under which conditions does GetHostEntry throw this specific error?
  2. 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".
  3. 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

like image 800
cun83 Avatar asked Feb 04 '11 09:02

cun83


People also ask

What is DNS GetHostEntry?

GetHostEntry(IPAddress) Resolves an IP address to an IPHostEntry instance. GetHostEntry(String) Resolves a host name or IP address to an IPHostEntry instance.

What is System Net DNS?

The Dns class is a static class that retrieves information about a specific host from the Internet Domain Name System (DNS).


1 Answers

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.

like image 74
Harvey Kwok Avatar answered Oct 21 '22 01:10

Harvey Kwok