问题描述
我打电话给 Inet4Address.getByName("localhost")
,希望看到 127.0.0.1
,但是我看到分配给我的以太网/机场的IP.如果断开以太网/机场的连接,将得到 127.0.0.1
的分辨率,但是一旦我再次连接,它将解析为以太网/机场的IP地址.
I make a call to Inet4Address.getByName("localhost")
expecting to see 127.0.0.1
, but instead I see my IP assigned to my ethernet/airport. If I disconnect my ethernet/airport, I will get the resolution of 127.0.0.1
, but as soon as I connect again it resolves to the IP address of the ethernet/airport.
我正在使用OSX 10.6.7和Java版本"1.6.0_24".我的/etc/hosts文件具有"127.0.0.1 localhost"
.终端中的Ping localhost确实解析为127.0.0.1.
I'm using OSX 10.6.7 and java version "1.6.0_24". My /etc/hosts file has "127.0.0.1 localhost"
. Ping localhost in the terminal does resolve to 127.0.0.1.
我需要这个的原因是我正在GWT开发中,我有一个不同的JVM试图调用GWT托管模式,并且我得到一个ConnectionException:如果本地主机无法解析为127.0,则连接被拒绝.0.1.
The reason I need this is that I'm doing GWT development where I have a different JVM trying to make a call to GWT Hosted Mode, and I get a ConnectionException: connection refused, if localhost doesn't resolve to 127.0.0.1.
谢谢
推荐答案
我遇到了同样的问题,这是因为我的主机名设置为localhost.我对其进行了更改,并解决了该问题.
I had the same issue and it was because my hostname was set to localhost. I changed it and it fixed the issue.
这篇关于本地主机无法解析为127.0.0.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!