Can someone explain to me what I need to check to resolve an apparent DNS issue? I am using Java's InetAddress class to determine the host name of the machine the program is running on. It is returning an incorrect machine name. My guess is that a former employee configured something on this machine which is causing this issue. I'm just not sure what he could have done.
The server is a Windows 2003 server. The machine name is set correctly as far as I can tell. I verified this two ways:
- Open Windows Explorer, right click on "My Computer", navigate to Properties > Computer Name. This screen shows the correct computer name like this: "computer1.examplecompany.com. Under "Full Computer Name" it shows Domain: "examplecompany.com".
- Open a command prompt and type the "hostname" command. This returns the same machine name in the prior step without the domain. In this example, it would be just "computer1" without "examplecompany.com".
Now when I attempt to use a Java program to get the host name, here is the relevant code fragment I am using:
InetAddress localhost = InetAddress.getLocalHost();
localhost = InetAddress.getByName(localhost.getHostAddress());
System.out.println("Hostname: " + localhost.getHostName());
The hostname that gets output to the console is completely different from the computer name. In fact, if I perform an nslookup on the name that the Java program output, I get this response: "Non-existent domain".
I don't know if this is relevant or not, but the name that the java program is returning is also in the "hosts" file with the same IP as the local machine (the IP is the company wide IP address, not 127.0.0.1). I thought maybe that was the problem, so I changed the hosts file to use a different name, and this appeared to have no effect even after flushing the DNS cache.
So what else can I check to see why this Java program is returning the wrong name?