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

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 127.0.0.1"

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

--------------------------------------------------------------
Hello,

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 127.0.0.1.

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

then JBoss resolves localhost to the external IP. If the /etc/hosts file contains:
    127.0.0.1              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:
127.0.0.1 from server 172.16.0.23 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 127.0.0.1 ?

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:
     getCanonicalHostName()=localhost
     getHostAddress()=127.0.0.1
     getHostName()=localhost
     toString()=localhost/127.0.0.1

Thank you for any help.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/719937#719937]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]

-------------- 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