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为主机名

原文地址:https://www.cnblogs.com/lpthread/p/3480789.html