我在特定的 linux rhel 机器上以非 root 用户身份运行调用 InetAddress.getLocalHost 的 java 程序时遇到问题。我尝试在另一台机器上运行该程序而没有任何问题(作为 root 用户或非 root 用户)。
错误:
at java.net.UnknownHostException: thebox: thebox: Temporary failure in name resolution
at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
代码:
public class MyInetAddress {
public static void main(String[] args) throws UnknownHostException {
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
}
}
环境:
# java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (rhel-2.4.7.1.el6_5-x86_64 u55-b13)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
# uname -rmo
2.6.32-279.2.1.el6.x86_64 x86_64 GNU/Linux