linux /etc/hosts 配置问题

在java code中获取本机IP的程序如下:

import java.net.InetAddress;

public class Test
{
  public static void main(String[] paramArrayOfString)
    throws Exception
  {
    InetAddress localInetAddress = InetAddress.getLocalHost();
    System.out.println(localInetAddress.getHostAddress());
  }
}

如果/etc/hosts 配置了

127.0.0.1  <本机的hostname>

上述code打印: 127.0.0.1

所以不应该在hosts中配置127.0.0.1为主机名

posted on 2013-12-18 17:45  lpthread  阅读(336)  评论(0编辑  收藏  举报