Skip to content

obtain local address incorrectly sometimes in dubbo #538

Closed

Description

@zcap

最近重装了系统(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配置,出现这种问题让新手很是蒙蔽。。
望大神回复。

Activity

  1. FangOba commented on Aug 23, 2017

    @FangOba

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

  2. zcap commented on Sep 11, 2017

    @zcap
    Author

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

  3. jacarrichan commented on Sep 13, 2017

    @jacarrichan

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

  4. ralf0131 commented on Jul 16, 2018

    @ralf0131
    Contributor

    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

  5. added
    help wanted
    on Jul 16, 2018
  6. luyuanwan commented on Jul 16, 2018

    @luyuanwan
    Contributor

    goot suggestion!

  7. huduku commented on Jul 18, 2018

    @huduku

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

  8. cnn112002 commented on Jul 24, 2018

    @cnn112002

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

  9. added this to the 2.7.1 milestone on Mar 4, 2019
  10. changed the title [-]关于dubbo中获取本机IP的问题[/-] [+]obtain local address incorrectly sometimes in dubbo[/+] on Mar 14, 2019
  11. added a commit that references this issue on Mar 26, 2019
    897b80d
  12. added a commit that references this issue on Apr 26, 2019
    b8d9f76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions