I have a domain joined computer with a literal computername of "mycomputername". It has a DHCP entry and DNS record with literal name "mydnsname". Yes, the local computername and DNS are different.
When I query our DNS servers using reverse NSLOOKUP, the expected name of "mydnsname" is returned.
However, if I use C# code below on the local machine, the local name "mycomputername" is returned.
string ipaddress="123.456.789.123"; //but my Real network IP
IPHostEntry hostEntry = Dns.GetHostEntry(ipaddress);
Console.WriteLine hostEntry.HostName;
This is unexpected. As far as I am aware, it should query DNS?
I made sure I named my computer something that has never been in DNS, so I know DNS cache is not getting in the way at this stage. If I locally rename the computer, restart, and run the code again - the updated computername is returned.
If I modify DNS, that modified DNS name is never returned - when run on the local machine. If I run the code on a different machine, but query the same IP, it returns the expected DNS entry.
I have attempted to flush the cache, but this has no effect: Is there a way to flush the DNS cache from a C# WPF app? (on XP, Vista, Win7)
NSLOOKUP command returns the correct name.