How to make java.net use host file?
Hello.
I have an app on one machine (call it local) that tries to connect to another server (call it remote) using java.net, specifically creating a new URL object passing it the host name, port and protocol. I have defined the host name 'remote' in my host file, but we also have another machine with this same name in DNS.
We want to connect to the machine defined in the host file. But when I execute the code and print out the ip address of the host, it's giving me the ip of the machine in DNS.
How can I make it consult the host file first? I thought this was standard behavior. When we do a 'ping' to 'remote' from 'local', it returns the correct ip, the one in our host file. But java.net seems not to use the host file ...
Is this possible?
Thanks,
Bob
[814 byte] By [
syg6a] at [2007-10-3 3:56:22]

After making a change to the local host file, the NIC must reload/import and enable lookup on the basis of the host file.
Otherwise, just use the IP address and not the host address.
That's the quick way.
On Windows, be careful to make sure which file you're using there are many lmhosts and hosts files.
Otherwise, turn off DNS service or create your own DNS server locally and reference the 'real' DNS servers in that, but define the one local entry you want.
That's the long-way around it.
Howdy, thanks for the reply,
Unfortunately this didn't work. We tried restarting the machine, tomcat, network services, you name it. Zilch.
BTW, it's a RedHat 4.0 Linux box. We have edited our hosts, host.conf and nsswitch.conf files correctly. As I said, ping works immediately after editing the hosts file.
Any other ideas?
Bob
syg6a at 2007-7-14 21:54:34 >

The comment about the NIC was not correct. The NIC doesn't know or care about hosts files or hostnames.
ejpa at 2007-7-14 21:54:34 >

We figured it out. We had put the line:
JAVA_OPTS="$JAVA_OPTS "-Dsun.net.spi.nameservice.provider.1=dns,sun
in out catalina.sh (to start Tomcat) so that host resolution would work in JMX when the machine that calls the RMI server and the RMI server itself are on two different boxes. In this case they are on the same box so this line isn't needed. As soon as we took it out JMX started working much quicker and name resolution also started working.
Thanks!
Bob
syg6a at 2007-7-14 21:54:34 >

> The comment about the NIC was not correct. The NIC
> doesn't know or care about hosts files or hostnames.
Basically, yes, though the drivers sometimes refer to these files.
So, yes and no. They never should, but then again should and don't are not always the same.
I yield to your answer!
When does an NIC driver refer to a hosts file? Can you give me (a) an example and (b) a reason?
ejpa at 2007-7-14 21:54:34 >

I've seen some DDK's that interface with the OS to get some dynamic configuration - typically OEM from Intel and IBM.
I think I remember back in the OS/4 days from IBM of their drivers being more software then a communications bridge between the hardware.
This back when, and I saw some from a "low grade" business PC maker, independent, back in '91 or so.
including the 'hosts' file?I can understand getting stuff like whether or not to bridge-route between two logical IP addresses, or that 802.3/SNAP header business which Novell inflicted on us, but not a hosts file.
ejpa at 2007-7-14 21:54:34 >

It was a 'hosts' file as I recall - but I think the one I remember was in the driver's install folder - so my guess is it was something special-use.I'm going back to Windows for Workgroups, Windows 3.11, Windows NT 3.5 era.Ah yes, remember WNT35 and it's great GUI?
Off-topic:
I worked at a "modern" medium-sized business once and their network - all servers were on a shared 10 Mb Intel hub - yes - Intel Hub at only 10 Mb - and this stack included all their workstations, mobile ports for guest users, and a remote access network for their sales dept.
In their back warehouse, their systems ran on Windows NT 3.5