1 Reply Latest reply on Feb 29, 2012 6:04 AM by petal1

    JNDI not resolving localhost to

    petal1 Newbie



      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:


          <external-ip-not-shown>  MYHOSTNAME


      then JBoss resolves localhost to the external IP. If the /etc/hosts file contains:


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