If your computer and a remote device are located on the same IP network, VLAN, or subnet – you will probably notice that if you ping such a device by its hostname it will return an IPv6 address. For example, we will try to ping Windows Server on our network with the command:
Ping srv01 Pinging srv01.contoso.com [fe80::c09::d4e6::189f::f661%3] with 32 bytes of data Reply from fe80::c09::d4e6:189f:f661%3: time<1ms Reply from fe80::c09::d4e6:189f:f661%3: time<1ms
Ping Returning an IPv6 Address Instead of IPv4
The fact is that the IPv6 protocol in Windows Vista and newer is the preferred protocol over IPv4.
If you want to still see an IPv4 address of a remote device in the ping command result, then simply use the command below:
ping hostname -4
Simply add a parameter “-4” after your usual ping command:
Ping srv01 -4 Pinging srv01.contoso.com [192.168.10.21] with 32 bytes of data Reply from 192.168.10.21: bytes=32 time<1ms TTL=128 Reply from 192.168.10.21: bytes=32 time<1ms TTL=128
As you can see, the ping command returned the standard IPv4 address.
How to Force Windows to Use IPv4 over IPv6?
In all versions of Windows starting from Vista, IPv6 unicast addresses are preferred over IPv4 addresses (according to the RFC 3484). Internet Protocol version 6 (IPv6) is a mandatory part of Windows. If you disable it, some Windows components may not work properly. Microsoft recommends using the option “Preferably use IPv4 instead of IPv6” in Windows prefix policies instead of completely disabling IPv6.
If the client tries to access a remote server using an ICMP protocol (ping, telnet, or pathping commands), and it returns the IPv6 address (or there are some problems with the operation of some legacy applications) there is a more advanced solution.
The solution is to increase the priority of the IPv4 over the IPv6 protocol. You can use such a solution without the need to completely disable the IPv6 on a source and the target host.
To display the current policy table on Windows, run the following command:
netsh interface ipv6 show prefixpolicies
The following prefix policy settings are used by default on Windows 10 and Windows Server 2016.
Precedence Label Prefix
———- —– ——————————–
50 0 ::1/128
40 1 ::/0
35 4 ::ffff:0:0/96
30 2 2002::/16
5 5 2001::/32
3 13 fc00::/7
1 11 fec0::/10
1 12 3ffe::/16
1 3 ::/96
The prefix policy table is similar to the routing table, it determines which IP addresses are preferred when establishing a connection.
In this table, the policy “1 ::/0” (Native IPv6) takes precedence over “::ffff:0:0/96” (IPv4). A protocol with a higher Precedence value in this table has a higher priority.
Prefer IPv4 over IPv6 on Windows
The solution doesn’t require a reboot, it takes effect immediately. You need to open an elevated Command Prompt, and run 2 commands:
netsh interface ipv6 set prefix ::/96 60 3 netsh interface ipv6 set prefix ::ffff:0:0/96 55 4
These commands increased the priority of the IPv4 prefix policy and decreased the priority for IPv6. By default, this change is made persistent across reboots.
For example, run these two commands on a clean Windows Server 2016 instance, and perform a ping request again:
Pinging srv01.contoso.com [192.168.10.21] with 32 bytes of data Reply from 192.168.10.21: bytes=32 time<1ms TTL=128 Reply from 192.168.10.21: bytes=32 time<1ms TTL=128
As you can see, the result changed dramatically in the direction we needed. The remote server began to return an IPv4 address (192.168.10.21) instead of an IPv6 address. Now we’ll check that the server is still pinging by its IPv6 address, and we didn’t break anything:
Everything works as it should be.
Print the current prefix priority table:
netsh interface ipv6 show prefixpolicies
As you can see, IPv4 is now used by default when sending the network packets.
You can also change the preferred IP protocol from GUI. To do it, open Control Panel > Network and Internet > Network Connections > Advanced > Advanced Settings.
Select your network connection, and set the IPv4 protocol above IPv6 with the green button. You should perform this operation for all available bindings.
Tip. The “Adapters and Bindings” dialog box is missing in the newest Windows 10 and Windows Server 2016/2019. Another way to change the default TCP/IP stack from IPv6 to IPv4 on these OSs is through the registry. Open the elevated command prompt and run the command:reg.exe add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters /v DisabledComponents /t REG_DWORD /d 0x20 /f
Or you can change the value of the DisabledComponents to 0x20 via the Regedit.exe GUI. This value allows you to prefer an IPv4 protocol over IPv6 by changing entries in the prefix policy table.
After that, IPv6 Functionality will change to “Prefer IPv4 over IPv6” policies. Microsoft recommends using this policy instead of disabling IPv6 on the host.