InetAddress java 8没有获取主机名 [英] InetAddress java 8 is not getting the hostname
问题描述
InetAddress.getLocalHost()。getHostName()
不再获取HostName的名称,因为我切换到java 8 ...
InetAddress.getLocalHost().getHostName()
is no more getting the name of the HostName since I switched to java 8 ...
使用jdk1.8 InetAddress.getLocalHost()。getHostName()
返回localhost。之前(当我使用jdk1.6时)它根据网络配置给我正确的主机名(即ACTION03):
with the jdk1.8 the InetAddress.getLocalHost().getHostName()
returns "localhost". Before (when I was using jdk1.6) it gives me the right hostname (which is "ACTION03") according to the network config :
cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=ACTION03
任何帮助?
推荐答案
据我所知,他们更改了默认解决程序。
What I understand is that they changed default resolution process.
他们尊重 /中的配置etc / nsswitch.conf
其中主机配置为 / etc / hosts
,它为名称解析提供了主要优先级。
They honor configuration in /etc/nsswitch.conf
where hosts are configured for /etc/hosts
that gives it main priority for name resolution.
通常 / etc / hosts
有 127.0.0.1 localhost $ c的记录$ c>为主机提供名称
localhost
Usually /etc/hosts
has record for 127.0.0.1 localhost
that provide name for host localhost
这篇关于InetAddress java 8没有获取主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!