jmDNS Ubuntu IP解析地址错误

时间:2018-07-30 18:57:14

标签: java jmdns

我正在Ubuntu 18.04上运行使用jmDNS库进行发现的服务器。初始化它的代码是:

   jmDNS = JmDNS.create(InetAddress.getLocalHost());
        serviceInfo = ServiceInfo.create("_http._tcp.local.", "Service", 65534, "Ready");

但是,当它在另一台计算机上的客户端上解析时,IP地址为127.0.1.1。客户端配置如下:

  jmdns = JmDNS.create(InetAddress.getLocalHost());

当我在非Ubuntu计算机上运行此命令时,IP地址正确。我试图弄清楚是什么原因造成的。

1 个答案:

答案 0 :(得分:0)

编辑/etc/hosts文件

注释以127.0.1.1开头的第二行

因此,您的/etc/hosts文件应如下所示:

127.0.0.1       localhost
#127.0.1.1      your-pc-name

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

参考:https://serverfault.com/questions/363095/why-does-my-hostname-appear-with-the-address-127-0-1-1-rather-than-127-0-0-1-in

相关问题