Name resolution in .Net - arrrrrggghhhh!

From: Rob Levine (rob_levine_at_hotmail.com)
Date: 01/12/05


Date: 12 Jan 2005 05:08:18 -0800

I have been having some serious problems with System.Net.Dns.Resolve.

The documentation states:

"The Resolve method queries a DNS server for the IP address associated
with a host name or IP address."

"When hostName is a DNS-style host name associated with multiple IP
addresses, only the first IP address that resolves to that host name is
returned."

Both these assertions appear to be incorrect.

The second assertion is quite clearly wrong. This method returns an
IPHostEntry instance, which has an AddressList property. This property
is an array of IPAddress instances. A quick test of this method reveals
that this list will conatin more than one item if the name resolves to
more than one IP address. Black mark number one, unless I have
misunderstood something.

Now to the first assertion. I have a box which has two network
adapters. One of these adapters is to a network with private
non-routable ip addresses and no routing/bridging is allowed between
the networks; the ip address of this NIC is 10.0.0.5. The private
network has no DNS server, and there are no host file entries for hosts
on this private network. The other network card connects to my main
subnet which has all the usual infrastructure such as DNS; the ip
address of this NIC is 192.168.0.2

My machine is called 'terminus'. Terminus has one single entry in the
DNS, which resolves to 192.168.0.2. A quick test with nslookup confirms
that this hostname has a single A record to point to this ip address.

Why then, when I call System.Net.Dns.Resolve ( "terminus" ) do I get
both IP addresses returned? If this method did what it said, I would
only get the 192.168 address returned. I even get them in a perverse,
reverse order where the 10.0.0.5 comes first. The fact of the matter is
that this method does *not* do what it says; or perhaps it does what it
says and then does sdome other things too.

Using

nbtstat -a terminus (on terminus itself)

reveals that the NetBIOS name cache contains both these IP addresses,
and in the order the Resolve call returns them.

I used a reflector to look into how the Resolve method works, and it
just appears to call the Windows Sockets function gethostbyname.
Firstly, this method is quite clearly marked as deprecated in the
documentation (so why is the .Net Framework 1.1 using it), and secondly
even the documentation for this call does not detail what it actually
does!

My feeling is that this function harks back to the NetBT days of NT
when it was preferable to try and resolve names via WINS or NetBIOS
broadcasts as well as IP. However, this is not what the documentation
says the function does, and there appears no way of actually doing a
basic DNS lookup with nothing else.

I have wasted a few days debugging problems that are directly
attributable to this and am pretty cross about it! Have I missed
something obvious, or is this function as misleading as it seems?

Is there a way of *only* doing a DNS lookup, akin to using nslookup?

Has anyone else had similar problems?

All help gratefully received,

Rob Levine
http://roblevine.blogspot.com



Relevant Pages

  • Re: MX-only domains dying?
    ... I've always thought of the www host as being an artifact of the good old days of the web where DNS was used as part of the maintenance methodology - if you needed to service a box you switched the IP in DNS to the hot spare. ... Using service names allows you to have each respective serviceresolve to different address, thus allowing you to spread services across different hosts. ... If you are wondering why I have A records for domainN.tld verses a CNAME record, I have never been able to get CNAME records to co-exist with any other record type for a given name. ...
    (comp.mail.sendmail)
  • DNS Resolver Questions
    ... If my host is on a domain named mydomain.com my primary suffix will be ... Now when I try to resolve a host name my unqualified ... resolve it in dns. ...
    (microsoft.public.win2000.dns)
  • Re: [SLE] SuSE 9.3 DNS Unreliable
    ... spurious and unpredictable failures to resolve ... > host names. ... > ISP-supplied DNS server addresses and a default routing host) on a DSL ... Is it some kind of configuration ...
    (SuSE)
  • Re: postfix allows connection but does not respond
    ... > Does the IP of your mail client resolve to a name (and/or are there any ... > might be a DNS issue attempting to resolve the connecting IP, ... Postfix was receiving mail from a single host and the IP address ... The local resolv.conf only references one host, the local DNS server. ...
    (comp.os.linux.misc)
  • Re: Web Site Mystery
    ... host our own web site at this location. ... So in our DNS setup, there is a pointer to the ip address of the ... Run an ipconfig /all on your server and you'll see the ... www.europacrown.com don't work from our corporate network. ...
    (microsoft.public.windows.server.general)