我有一些主机返回InetAddress.getLocalHost().getCanonicalHostName()(Documented here)的非限定名称,例如"foo“而不是"foo.example.com”。是什么导致了这个问题?我该如何修复它?
在命令行上运行"hostname -f“将返回完全限定的域名,短名称上的nslookup也将返回完全限定的域名。
CentOS 7.7.1908
JRE 1.8.0_231-b11
发布于 2020-02-05 08:02:44
您能粘贴/etc/hosts文件的内容吗?
或cat /etc/hosts | grep localhost的输出
问题很可能出在那里,因为它没有为127.0.0.1定义FQDN
发布于 2020-02-12 05:16:55
这很可能是你的机器的配置。检查该域的DNS是否正确解析,以及是否存在域设置。
Java将在/etc/hosts中查找,或者使用您的操作系统工具来执行名称地址到名称解析。
由于您正在寻找localhost,您可能需要一种特定于主机的机制来解决它。
此外,您的机器可能有许多接口,并不是所有接口都可以解析为相同的FQDN。
枚举所有网络接口以查看问题所在可能会有所帮助:
final Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while(networkInterfaces.hasMoreElements())
{
final NetworkInterface iface = networkInterfaces.nextElement();
System.out.println("Interface: " + iface.getDisplayName());
final Enumeration<InetAddress> inetAddresses = iface.getInetAddresses();
while (inetAddresses.hasMoreElements())
{
final InetAddress addr = inetAddresses.nextElement();
System.out.println(addr.getCanonicalHostName());
}
}https://stackoverflow.com/questions/59996747
复制相似问题