By default Windows will prefer IPv6 over IPv4. Below you will see how you can change this behavior to prefer IPv4 over IPv6 in Windows.


Default Address Selection for Internet Protocol version 6 (IPv6)
In dual stack implementations, the destination address selection algorithm can consider both IPv4 and IPv6 addresses – depending on the available source addresses, the algorithm might prefer IPv6 addresses over IPv4 addresses, or vice-versa.

Source: https://www.ietf.org/rfc/rfc3484.txt


Windows Vista, Windows Server 2008, and later versions of Windows implement RFC 3484 and use a prefix table to determine which address to use when multiple addresses are available for a Domain Name System (DNS) name.

By default, Windows favors IPv6 global unicast addresses over IPv4 addresses.

It is common for IT administrators to disable IPv6 to troubleshoot networking-related issues such as name resolution issues.

Internet Protocol version 6 (IPv6) is a mandatory part of Windows Vista and Windows Server 2008 and newer versions. We do not recommend that you disable IPv6 or its components. If you do, some Windows components may not function.

We recommend using Prefer IPv4 over IPv6 in prefix policies instead of disabling IPV6.

Source: https://docs.microsoft.com/en-US/troubleshoot/windows-server/networking/configure-ipv6-in-windows



The IPv6 functionality can be configured by modifying the following registry key:

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters

Add the following DWORD to prefer IPv4 over IPv6:
Name: DisabledComponents
Type: REG_DWORD
Min Value: 0x00 (default value)
Max Value: 0xFF (IPv6 disabled)

Prefer IPv4 over IPv6
Decimal 32
Hexadecimal 0x20

You must restart your computer for these changes to take effect.


IPv6 FunctionalityRegistry value and comments
Prefer IPv4 over IPv6Decimal 32
Hexadecimal 0x20
Binary xx1x xxxx

Recommended instead of disabling IPv6.
Disable IPv6Decimal 255
Hexadecimal 0xFF
Binary 1111 1111

See startup delay occurs after you disable IPv6 in Windows if you encounter startup delay after disabling IPv6 in Windows 7 SP1 or Windows Server 2008 R2 SP1.

Additionally, system startup will be delayed for five seconds if IPv6 is disabled by incorrectly, setting the DisabledComponents registry setting to a value of 0xffffffff. The correct value should be 0xff. For more information, see Internet Protocol Version 6 (IPv6) Overview.

The DisabledComponents registry value doesn’t affect the state of the check box. Even if the DisabledComponents registry key is set to disable IPv6, the check box in the Networking tab for each interface can be checked. This is an expected behavior.

You cannot completely disable IPv6 as IPv6 is used internally on the system for many TCPIP tasks. For example, you will still be able to run ping ::1 after configuring this setting.
Disable IPv6 on all nontunnel interfacesDecimal 16
Hexadecimal 0x10
Binary xxx1 xxxx
Disable IPv6 on all tunnel interfacesDecimal 1
Hexadecimal 0x01
Binary xxxx xxx1
Disable IPv6 on all nontunnel interfaces (except the loopback) and on IPv6 tunnel interfaceDecimal 17
Hexadecimal 0x11
Binary xxx1 xxx1
Prefer IPv6 over IPv4Binary xx0x xxxx
Re-enable IPv6 on all nontunnel interfacesBinary xxx0 xxxx
Re-enable IPv6 on all tunnel interfacesBinary xxx xxx0
Re-enable IPv6 on nontunnel interfaces and on IPv6 tunnel interfacesBinary xxx0 xxx0

Source: https://docs.microsoft.com/en-US/troubleshoot/windows-server/networking/configure-ipv6-in-windows


You can also roll out these settings in your network by using a group policy.



Alternatively you can change the IPv6 prefix policies precedence to prefer IPv4 over IPv6. The command will modify the source and destination address selection policy for a specified prefix.

The changes will affect immediately without reboot!

Using SIO_ADDRESS_LIST_SORT
https://docs.microsoft.com/en-us/windows/win32/winsock/using-sio-address-list-sort

Show the actual prefix policy
netsh interface ipv6 show prefixpolicies

Changing precedence for mapped IPv4 addresses
netsh interface ipv6 set prefixpolicy ::ffff:0:0/96 precedence=46 label=4 store=persistent

store
active: Change only lasts until next boot.
persistent: Change is persistent (default).

Adding a prefix policy
netsh interface ipv6 add prefixpolicy ::/0 precedence=40 label=4 store=active

Deleting a prefix policy
netsh interface ipv6 delete prefixpolicy ::/0

You can reset the IPv6 setting by using the following command and reboot your computer afterwards.
netsh interface ipv6 reset

  • Precedence 50 –> IPv6 loopback adapter
  • Precedence 40 –> Arbitrary IPv6 Address
  • Precedence 35 –> IPv4-mapped IPv6 addresses
  • Precedence 30 –> 6to4 tunnel addresses
  • Precedence 5 –> Teredo addresses
  • Precedence 1 –> IPv4 Addresses

Source: https://en.wikipedia.org/wiki/IPv6_address#Special_addresses


Policy table for IPv6 default address selection
https://www.ibm.com/docs/en/zos/2.3.0?topic=selection-policy-table-ipv6-default-address

In the table, IPv4 addresses are represented as IPv4-mapped IPv6 addresses.

IPv4-mapped IPv6 addresses
https://www.ibm.com/docs/en/zos/2.2.0?topic=addresses-ipv4-mapped-ipv6
https://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses



Before changing the precedence from the IPv4 mapped addresses, by default IPv6 is used for internet traffic, because the prefix for the arbitrary IPv6 addresses (::/0) is higher as shown below.


Now I will change the precedence for the IPv4 mapped addresses (::ffff:0:0/96) to be higher than the arbitrary IPv6 addresses (::/0) .

netsh interface ipv6 set prefixpolicy ::ffff:0:0/96 46 4


After changing the precedence for IPv4 mapped addresses (::ffff:0:0/96) to be higher as the arbitrary IPv6 addresses (::/0), Windows will use IPv4 to connect to remote IP addresses.

Unfortunately as you can see in the screenshot above, the nslookup command will still query the IPv6 DNS server instead the IPv4.

The DNS server is dual stacked, meaning that it has both IPv4 and IPv6 addresses. When performing the lookup by specifying the default DNS server as a command line option, nslookup properly loops through the IP addresses starting with IPv6 and ending on IPv4. However when using nslookup interactively, nslookup only tries the first address which is returned by the resolver, which will always be the IPv6 address.

The fix for this is to specify the DNS servers by IP address when using nslookup interactively or use nslookup non-interactively by specifying the default DNS server on the command line.

Source: https://superuser.com/questions/720145/why-does-windows-7-try-to-resolve-dns-against-ipv6-dns-servers


Here you can see that Windows from now on is using IPv4.




Links

Guidance for configuring IPv6 in Windows for advanced users
https://docs.microsoft.com/en-US/troubleshoot/windows-server/networking/configure-ipv6-in-windows

Policy table for IPv6 default address selection
https://www.ibm.com/docs/en/zos/2.3.0?topic=selection-policy-table-ipv6-default-address

Using SIO_ADDRESS_LIST_SORT
https://docs.microsoft.com/en-us/windows/win32/winsock/using-sio-address-list-sort

Netsh commands for Interface IPv6
http://winintro.ru/netsh_technicalreference.en/html/0cb9e1fe-7e43-4d8a-bf43-5352b94beaef.htm

Configuring IPv6 in Windows with NetShell
https://www.admin-magazine.com/Archive/2015/25/Configuring-IPv6-in-Windows-with-NetShell