dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

dubbo注册服务IP地址总是127.0.0.1而不是内网地址

Open wo8335224 opened this issue 7 years ago • 11 comments

Why are the IP addresses obtained by the registered services all 127.0.0.1 instead of the intranet IP? Can I specify to get the intranet address? eho0?

Tell us your environment dubbo 2.7.1 dubbo-registry-nacos 2.7.1 nacos-client 1.0.0-RC3 image

wo8335224 avatar Apr 25 '19 10:04 wo8335224

Maybe, I also face the same problem

https://github.com/apache/incubator-dubbo/issues/3923

byronzoz avatar Apr 26 '19 07:04 byronzoz

具体的配置文件能否提供一下,我这边测试如下配置<dubbo:protocol name="dubbo"/>,发现注册中心的地址是内网地址。

it-zhouyu avatar May 10 '19 07:05 it-zhouyu

@boomblog 我用的是nacos注册中心,spring boot 整合dubbo com.alibaba.boot nacos-config-spring-boot-starter 0.2.1 org.apache.dubbo dubbo-registry-nacos 2.7.1 com.alibaba.nacos nacos-client 1.0.0-RC3 org.apache.dubbo dubbo-spring-boot-starter 2.7.1

wo8335224 avatar May 14 '19 08:05 wo8335224

Spring boot application

dubbo.registry.address=nacos://192.168.1.214:8848 dubbo.protocol.port=-1

wo8335224 avatar May 14 '19 08:05 wo8335224

对hosts 文件进行配置 1.使用 hostname 命令取得当前的 机器名 2.将机器名和内网 ip 配置进 hosts

VanXD avatar May 15 '19 07:05 VanXD

对hosts 文件进行配置 1.使用 hostname 命令取得当前的 机器名 2.将机器名和内网 ip 配置进 hosts

没用~试过的

wo8335224 avatar May 15 '19 09:05 wo8335224

@boomblog 我用的是nacos注册中心,spring boot 整合dubbo

com.alibaba.boot nacos-config-spring-boot-starter 0.2.1

org.apache.dubbo dubbo-registry-nacos 2.7.1

com.alibaba.nacos nacos-client 1.0.0-RC3

org.apache.dubbo dubbo-spring-boot-starter 2.7.1

private String findConfigedHosts(ProtocolConfig protocolConfig, List registryURLs, Map<String, String> map) { boolean anyhost = false;

    String hostToBind = getValueFromConfig(protocolConfig, Constants.DUBBO_IP_TO_BIND);

    // if bind ip is not found in environment, keep looking up
    if (StringUtils.isEmpty(hostToBind)) {
        hostToBind = protocolConfig.getHost();
        if (provider != null && StringUtils.isEmpty(hostToBind)) {
            hostToBind = provider.getHost();
        }

        if (StringUtils.isEmpty(hostToBind)) {
            anyhost = true;
            **hostToBind = getLocalHost();**

            if (StringUtils.isEmpty(hostToBind)) {
                hostToBind = findHostToBindByConnectRegistries(registryURLs);
            }
        }
    }

    map.put(Constants.BIND_IP_KEY, hostToBind);

    // registry ip is not used for bind ip by default
    String hostToRegistry = getValueFromConfig(protocolConfig, Constants.DUBBO_IP_TO_REGISTRY);
    if (StringUtils.isEmpty(hostToRegistry)) {
        // bind ip is used as registry ip by default
        hostToRegistry = hostToBind;
    }

    map.put(Constants.ANYHOST_KEY, String.valueOf(anyhost));

    return hostToRegistry;
}

这是获取host的源码,你可以先本地测一下调用getLocalHost()这个方法返回的是什么

it-zhouyu avatar May 15 '19 12:05 it-zhouyu

对hosts 文件进行配置 1.使用 hostname 命令取得当前的 机器名 2.将机器名和内网 ip 配置进 hosts

没用~试过的

image 不要重复出现 hostname

VanXD avatar May 22 '19 09:05 VanXD

seam question

wr67542 avatar May 29 '19 12:05 wr67542

这是获取host的源码,你可以先本地测一下调用getLocalHost()这个方法返回的是什么

可以按照这里的步骤尝试先试一下看。

chickenlj avatar Dec 18 '19 12:12 chickenlj

給遇到這個問題的人 我前不久也遇到這個問題

後來發現是我電腦有裝Http Proxy或是VPN的東西 他一直嘗試把我的ip註冊到http proxy的網域

可以用nslookup來查看自己的ip位置是跑到哪裡

Hoxton019030 avatar Sep 27 '24 09:09 Hoxton019030