While trying to get apache jserv to work, I kept getting errors about not being able to resolve the hostname "localhost". Thus I went browsing and found a few simple programs, none of which I could get to work properly. Here is the one that I found most useful: import java.net.*; class HostCheck { public static void main(String argv[]) { String hostname = argv[0]; try { System.out.println(InetAddress.getByName(hostname)); } catch(Exception e) { System.out.println("Exception caught: " + e.toString()); } } } And here are the results I had from running this program: production:~/projects/inet>java HostCheck www.blackdown.org www.blackdown.org/192.41.21.66 production:~/projects/inet>java HostCheck production Exception caught: java.net.UnknownHostException: production production:~/projects/inet>java HostCheck localhost Exception caught: java.net.UnknownHostException: localhost It seems like the java runtime is not trying to resolve the name via /etc/hosts, but is instead going directly to the DNS! I have included an attachment file which details my routing and name resolution information. Some other messages I found revealed that users were able to get this progam to run properly: /* * Program: GetName.java * @author: Qusay H. Mahmoud * @version: Oct 29, 1996 */ import java.net.*; public class GetName { public static void main(String argv[]) throws Exception { InetAddress host = null; host = InetAddress.getLocalHost(); System.out.println(host.getHostName()); } } However the result fails on my machine: production:~/projects/inet>java GetName java.net.UnknownHostException: production at java.net.InetAddress.getAllByName0(InetAddress.java) at java.net.InetAddress.getAllByName(InetAddress.java) at java.net.InetAddress.getLocalHost(InetAddress.java) at GetName.main(GetName.java:12) The result here also seems like the java runtime is trying to resolve the name with DNS instead of /etc/hosts. Does anyone know the solution to this problem or know where to start looking? --shawn
Note that some of the ip address has been taken out for security reasons. AAA.AAA.AAA.AAA = The IP Address of this machine BBB.BBB.BBB.BBB = The network address of this machine CCC.CCC.CCC.CCC = The default gateway of this machine Script started on Sat Oct 2 17:28:07 1999 production:~/projects/inet>cat /etc/host.conf order hosts, bind multi on production:~/projects/inet>cat /etc/hosts # # hosts This file describes a number of hostname-to-address # mappings for the TCP/IP subsystem. It is mostly # used at boot time, when no name servers are running. # On small systems, this file can be used instead of a # "named" name server. Just add the names, addresses # and any aliases to this file... # # By the way, Arnt Gulbrandsen <[EMAIL PROTECTED]> says that 127.0.0.1 # should NEVER be named with the name of the machine. It causes problems # for some (stupid) programs, irc and reputedly talk. :^) # # The name of this host AAA.AAA.AAA.AAA production # For loopbacking. 127.0.0.1 localhost production:~/projects/inet>route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface localhost * 255.255.255.255 UH 0 0 0 lo BBB.BBB.BBB.BBB * 255.255.255.248 U 0 0 0 eth0 BBB.BBB.BBB.BBB * 255.255.255.248 U 0 0 0 eth0 default CCC.CCC.CCC.CCC 0.0.0.0 UG 1 0 0 eth0 production:~/projects/inet>hostname production production:~/projects/inet>ping localhost PING localhost (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=0.2 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=255 time=0.0 ms --- localhost ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.0/0.1/0.2 ms production:~/projects/inet>ping production PING production (209.198.147.146): 56 data bytes 64 bytes from AAA.AAA.AAA.AAA: icmp_seq=0 ttl=255 time=0.2 ms 64 bytes from AAA.AAA.AAA.AAA: icmp_seq=1 ttl=255 time=0.0 ms --- production ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.0/0.1/0.2 ms production:~/projects/inet>uname -a Linux production 2.2.12 #10 SMP Wed Sep 29 18:48:37 CDT 1999 i686 unknown production:~/projects/inet>^Dexit Script done on Sat Oct 2 17:30:37 1999