在文件C:\WINDOWS\system32\drivers\etc\hosts我只有以下行
192.168.0.23 computername.domain.com computername
当我跑
InetAddress localhost = InetAddress.getLocalHost();
System.out.println("getLocalHost:" + localhost);
我希望输出是
getLocalHost:computername/192.168.0.23
但结果是
getLocalHost:computername/192.168.0.107
关于为什么会发生这种情况的任何想法?是否应该(也)在其他文件中进行配置?
编辑
InetAddress.getByName('computername')
产生相同的IP getLocalHost()
。