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:
then JBoss resolves localhost to the external IP. If the /etc/hosts file contains:
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
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");
and it returned:
Thank you for any help.
I'd love if someone could shed some light on this please.