[jboss-user] [JNDI and Naming] - JNDI not resolving localhost to

petal1 do-not-reply at jboss.com
Mon Feb 27 11:48:35 EST 2012

petal1 [https://community.jboss.org/people/petal1] created the discussion

"JNDI not resolving localhost to"

To view the discussion, visit: https://community.jboss.org/message/719937#719937


I have an Amazon EC2 instance (could be any cloud server, or even any server I guess) running Open SuSE. I am running JBoss 4.0.4GA on there. When I do a JNDI lookup with a provider URL of "localhost:1099", I may get an error depending on what is in /etc/hosts.
What I don't understand is why JBoss is not resolving localhost to

When /etc/hosts contains:              localhost
    <external-ip-not-shown>  MYHOSTNAME

then JBoss resolves localhost to the external IP. If the /etc/hosts file contains:              localhost
    <internal-ip-not-shown> MYHOSTNAME

then JBoss resolves localhost to the internal IP.

So clearly /etc/hosts is involved in JBoss’s resolution of names. But when I do:
 dig localhost +short +identify
It returns: from server in 80 ms.

Apparently Amazon EC2 instances don't have any awareness of their external IP, so the /etc/hosts should reference only the internal IP address. Indeed my application works fine when the /etc/hosts file contains only the internal IP but my issue is why JBoss does not resolve localhost to ?

Just as a bit of extra info, I executed the code below:
    InetAddress ina= InetAddress.getByName("localhost");
   System.out.println("getCanonicalHostName()=" +ina.getCanonicalHostName());
   System.out.println("getHostAddress()=" +ina.getHostAddress());
   System.out.println("getHostName()=" +ina.getHostName());
   System.out.println("toString()=" +ina.toString());

and it returned:

Thank you for any help.

Reply to this message by going to Community

Start a new discussion in JNDI and Naming at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120227/2a30f5eb/attachment.html 

More information about the jboss-user mailing list