<ul dir="auto">
<li>[√] I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li>[√] I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.4.1</li>
<li>Operating System version: Windows 10 1809 64位专业版</li>
<li>Java version: 1.8.0.191</li>
<li>Nacos version: 1.1.3</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto">前提：<br>
1，Windows 10 专业版启用Hyper-v，安装Docker for windows，但是Docker服务没启动<br>
2，<code class="notranslate">C:\Windows\System32\drivers\etc\hosts</code> 中已设置了: <code class="notranslate">正确IP 主机名</code></p>
<p dir="auto">网卡环境：<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/53243647/68201797-6bafc180-fffd-11e9-8c1d-8a7fdea5d79d.png"><img src="https://user-images.githubusercontent.com/53243647/68201797-6bafc180-fffd-11e9-8c1d-8a7fdea5d79d.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">添加JVM参数“-Djava.net.preferIPv4Stack=true”，然后运行以下代码(从dubbo-2.7.4.1-sources.jar中复制的NetUtils.getLocalAddress()相关的代码)：</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import java.io.IOException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.Optional;
import java.util.regex.Pattern;

public class Test {

    private static final Pattern IP_PATTERN = Pattern.compile(&quot;\\d{1,3}(\\.\\d{1,3}){3,5}$&quot;);

    private static final String ANYHOST_VALUE = &quot;0.0.0.0&quot;;

    private static final String LOCALHOST_VALUE = &quot;127.0.0.1&quot;;

    public static void main(String[] args) throws UnknownHostException {
        
        System.out.println(getIpByHost(getLocalAddress().getHostName()));
        
    }

    public static String getIpByHost(String hostName) {
        try {
            return InetAddress.getByName(hostName).getHostAddress();
        } catch (UnknownHostException e) {
            return hostName;
        }
    }

    public static InetAddress getLocalAddress() {

        InetAddress localAddress = getLocalAddress0();
        return localAddress;
    }

    private static InetAddress getLocalAddress0() {
        InetAddress localAddress = null;
        try {
            localAddress = InetAddress.getLocalHost();
            Optional&lt;InetAddress&gt; addressOp = toValidAddress(localAddress);
            if (addressOp.isPresent()) {
                return addressOp.get();
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }

        try {
            Enumeration&lt;NetworkInterface&gt; interfaces = NetworkInterface.getNetworkInterfaces();
            if (null == interfaces) {
                return localAddress;
            }
            while (interfaces.hasMoreElements()) {
                try {
                    NetworkInterface network = interfaces.nextElement();
                    if (network.isLoopback() || network.isVirtual() || !network.isUp()) {
                        continue;
                    }
                    Enumeration&lt;InetAddress&gt; addresses = network.getInetAddresses();
                    while (addresses.hasMoreElements()) {
                        try {
                            Optional&lt;InetAddress&gt; addressOp = toValidAddress(addresses.nextElement());
                            if (addressOp.isPresent()) {
                                try {
                                    if(addressOp.get().isReachable(100)){
                                        return addressOp.get();
                                    }
                                } catch (IOException e) {
                                    // ignore
                                }
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return localAddress;
    }

    private static Optional&lt;InetAddress&gt; toValidAddress(InetAddress address) {
        if (address instanceof Inet6Address) {
            Inet6Address v6Address = (Inet6Address) address;
            if (isPreferIPV6Address()) {
                return Optional.ofNullable(normalizeV6Address(v6Address));
            }
        }
        if (isValidV4Address(address)) {
            return Optional.of(address);
        }
        return Optional.empty();
    }

    static boolean isPreferIPV6Address() {
        boolean preferIpv6 = Boolean.getBoolean(&quot;java.net.preferIPv6Addresses&quot;);
        if (!preferIpv6) {
            return false;
        }
        return false;
    }

    static InetAddress normalizeV6Address(Inet6Address address) {
        String addr = address.getHostAddress();
        int i = addr.lastIndexOf('%');
        if (i &gt; 0) {
            try {
                return InetAddress.getByName(addr.substring(0, i) + '%' + address.getScopeId());
            } catch (UnknownHostException e) {
                // ignore
                e.printStackTrace();
            }
        }
        return address;
    }

    static boolean isValidV4Address(InetAddress address) {
        if (address == null || address.isLoopbackAddress()) {
            return false;
        }
        String name = address.getHostAddress();
        boolean result = (name != null
                &amp;&amp; IP_PATTERN.matcher(name).matches()
                &amp;&amp; !ANYHOST_VALUE.equals(name)
                &amp;&amp; !LOCALHOST_VALUE.equals(name));
        return result;
    }
}"><pre class="notranslate"><code class="notranslate">import java.io.IOException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.Optional;
import java.util.regex.Pattern;

public class Test {

    private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$");

    private static final String ANYHOST_VALUE = "0.0.0.0";

    private static final String LOCALHOST_VALUE = "127.0.0.1";

    public static void main(String[] args) throws UnknownHostException {
        
        System.out.println(getIpByHost(getLocalAddress().getHostName()));
        
    }

    public static String getIpByHost(String hostName) {
        try {
            return InetAddress.getByName(hostName).getHostAddress();
        } catch (UnknownHostException e) {
            return hostName;
        }
    }

    public static InetAddress getLocalAddress() {

        InetAddress localAddress = getLocalAddress0();
        return localAddress;
    }

    private static InetAddress getLocalAddress0() {
        InetAddress localAddress = null;
        try {
            localAddress = InetAddress.getLocalHost();
            Optional&lt;InetAddress&gt; addressOp = toValidAddress(localAddress);
            if (addressOp.isPresent()) {
                return addressOp.get();
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }

        try {
            Enumeration&lt;NetworkInterface&gt; interfaces = NetworkInterface.getNetworkInterfaces();
            if (null == interfaces) {
                return localAddress;
            }
            while (interfaces.hasMoreElements()) {
                try {
                    NetworkInterface network = interfaces.nextElement();
                    if (network.isLoopback() || network.isVirtual() || !network.isUp()) {
                        continue;
                    }
                    Enumeration&lt;InetAddress&gt; addresses = network.getInetAddresses();
                    while (addresses.hasMoreElements()) {
                        try {
                            Optional&lt;InetAddress&gt; addressOp = toValidAddress(addresses.nextElement());
                            if (addressOp.isPresent()) {
                                try {
                                    if(addressOp.get().isReachable(100)){
                                        return addressOp.get();
                                    }
                                } catch (IOException e) {
                                    // ignore
                                }
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return localAddress;
    }

    private static Optional&lt;InetAddress&gt; toValidAddress(InetAddress address) {
        if (address instanceof Inet6Address) {
            Inet6Address v6Address = (Inet6Address) address;
            if (isPreferIPV6Address()) {
                return Optional.ofNullable(normalizeV6Address(v6Address));
            }
        }
        if (isValidV4Address(address)) {
            return Optional.of(address);
        }
        return Optional.empty();
    }

    static boolean isPreferIPV6Address() {
        boolean preferIpv6 = Boolean.getBoolean("java.net.preferIPv6Addresses");
        if (!preferIpv6) {
            return false;
        }
        return false;
    }

    static InetAddress normalizeV6Address(Inet6Address address) {
        String addr = address.getHostAddress();
        int i = addr.lastIndexOf('%');
        if (i &gt; 0) {
            try {
                return InetAddress.getByName(addr.substring(0, i) + '%' + address.getScopeId());
            } catch (UnknownHostException e) {
                // ignore
                e.printStackTrace();
            }
        }
        return address;
    }

    static boolean isValidV4Address(InetAddress address) {
        if (address == null || address.isLoopbackAddress()) {
            return false;
        }
        String name = address.getHostAddress();
        boolean result = (name != null
                &amp;&amp; IP_PATTERN.matcher(name).matches()
                &amp;&amp; !ANYHOST_VALUE.equals(name)
                &amp;&amp; !LOCALHOST_VALUE.equals(name));
        return result;
    }
}
</code></pre></div>
<p dir="auto">Pls. provide [GitHub address] to reproduce this issue.</p>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">获取的IP应该是在<code class="notranslate">C:\Windows\System32\drivers\etc\hosts</code> 中已设置的正确IP</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">添加“-Djava.net.preferIPv4Stack=true”参数之后，输出的IP是Hyper-V的虚拟网卡<code class="notranslate">vEthernet (Default Switch)</code>的IP，注册到Nacos的也是这个IP</p>
<p dir="auto">去掉“-Djava.net.preferIPv4Stack=true”参数之后，输出的IP才是在<code class="notranslate">C:\Windows\System32\drivers\etc\hosts</code> 中已设置的正确IP</p>
<p dir="auto">调试过程中发现，如果添加“-Djava.net.preferIPv4Stack=true”参数，则调用链是:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;main@1&quot; prio=5 tid=0x1 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
	  at java.net.Inet4AddressImpl.lookupAllHostAddr(Inet4AddressImpl.java:-1)
	  at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
	  at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
	  at java.net.InetAddress.getLocalHost(InetAddress.java:1501)"><pre class="notranslate"><code class="notranslate">"main@1" prio=5 tid=0x1 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
	  at java.net.Inet4AddressImpl.lookupAllHostAddr(Inet4AddressImpl.java:-1)
	  at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
	  at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
	  at java.net.InetAddress.getLocalHost(InetAddress.java:1501)
</code></pre></div>
<p dir="auto">最后获取到的IP是Hyper-V的虚拟网卡的IP</p>
<p dir="auto">如果去掉“-Djava.net.preferIPv4Stack=true”参数，则调用链是:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;main@1&quot; prio=5 tid=0x1 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
	  at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:-1)
	  at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
	  at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
	  at java.net.InetAddress.getLocalHost(InetAddress.java:1501)"><pre class="notranslate"><code class="notranslate">"main@1" prio=5 tid=0x1 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
	  at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:-1)
	  at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
	  at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
	  at java.net.InetAddress.getLocalHost(InetAddress.java:1501)
</code></pre></div>
<p dir="auto">最后获取到的IP是在<code class="notranslate">C:\Windows\System32\drivers\etc\hosts</code> 中已设置的正确IP</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: master分支</li>
<li>Operating System version: windows</li>
<li>Java version: JDK1.8</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>在spi service配置中配置<br>
impl,implMultiName=org.apache.dubbo.common.extension.ext10.impl.Ext10MultiNamesImpl</li>
<li>ExtensionLoaderTest中加测试用例<br>
Ext10MultiNames ext10MultiNames = ExtensionLoader.getExtensionLoader(Ext10MultiNames.class).getExtension("impl");<br>
Assertions.assertNotNull(ext10MultiNames);<br>
3.运行不通过</li>
</ol>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">应该获取到对应的实现</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">获取到空，测试不通过</p>