Dubbo: obtain local address incorrectly sometimes in dubbo

Created on 21 Aug 2017  ·  7Comments  ·  Source: apache/dubbo

最近重装了系统(Linux系统)后,发现dubbo在注册中心注册的地址为180.168.41.175,介于之前组内其他人也出现过dubbo所获取的IP为180.168.41.175的问题,于是翻了翻源码,找到了获得IP的出处:InetAddress.getLocalHost()。而Java的这个方法依赖于本地的hostname和hosts文件。而我的系统默认的hosts文件中并不存在hostname所对应的记录,结果InetAddress.getLocalHost()就解析成了180.168.41.175。
我看到QA(http://dubbo.io/faq.html) 中有条和我的情况类似的(第17条,说是Dubbo1.0.7以上版本不会出现这个问题,但是我这里出现了,虽然不是127.0.0.1)。
我有个不成熟的小建议,可否优化一下IP获取的方式,让其更加精准;或则增加一个明显一点的配置说明。毕竟不同的Linux发行版有不同的hosts配置,出现这种问题让新手很是蒙蔽。。
望大神回复。

good first issue help wanted

Most helpful comment

I think the following actions should be made:

  • Add a documentation on how to get ip and register to registry
  • Add this kind to question to FAQ.

Related issue: #560

All 7 comments

@zcap 可以使用dubbo provider的指定host的配置

@Xiaobaxi 这样的话IP就被限定死了。。。对于其他机器来说是有问题的。。。。

在 provider所在的机器,ping下 hostname,看返回的IP是不是180.168.41.175。
如果是的话,请确认hosts文件正确。

I think the following actions should be made:

  • Add a documentation on how to get ip and register to registry
  • Add this kind to question to FAQ.

Related issue: #560

goot suggestion!

我装过 vmware,然后多了两个虚拟网卡。dubbo 把我的VMnet1的ip解析成本机地址了。

netInterfaces = NetworkInterface.getNetworkInterfaces();
然后从中选一个合适的,行吗 ?参考的是elastic-job-lite的实现,可以的话 ,可以PR下

Was this page helpful?
0 / 5 - 0 ratings