Localhost does not allow 127.0.0.1

I call Inet4Address.getByName("localhost") , expecting to see 127.0.0.1 , but instead I see my IP address assigned to my ethernet / airport. If I disconnect my ethernet / airport, I will get permission 127.0.0.1 , but as soon as I reconnect it will resolve the ethernet / airport IP address.

I am using OSX 10.6.7 and the java version is "1.6.0_24". My / etc / hosts file has "127.0.0.1 localhost" . Ping localhost in the terminal does allow 127.0.0.1.

I need this because I am developing a GWT where I have another JVM trying to call GWT Hosted Mode and I get a ConnectionException: the connection is rejected if localhost does not allow 127.0. 0.1.

thanks

+4
source share
3 answers

I had the same problem, and that was because my hostname was set to localhost. I changed it and it fixed the problem.

+1
source

I also saw this behavior on MacOS (v10.9) when the hostname is not set. Go to "System Preferences" → "Sharing" and make sure that the computer name is filled in.

Note that using 127.0.0.1 is a workaround, but you probably want to sort it correctly, as localhost should be 127.0.0.1, and if not, other things (like connecting to a database, etc.) may break.

0
source

Tangentially relevant for those who come after:

It may also be useful to confirm that you are requesting the correct port!

Pinging may work fine, but if you don’t have a web server that listens on port: 80, then you won’t get a response in the browser ... Monday morning gotchas, and XD

0
source

All Articles