Windows will normally prefer to use IPv6 instead of IPv4 if the local system has been configured with IPv6 enabled and the system you want to connect with has an IPv6 address assigned in its DNS record. However, there may be situations where you want the system to prioritize IPv4 instead.
Under some circumstances, you may experience problems establishing a connection with sites using IPv6, although a connection to the same site using IPv4 works without any issues. Most commonly, this is experienced as a “connection reset” error, or the connection will time out and fail.
The underlying cause of the problem can be several things, including a misconfigured DNS record, a problem with a router on the local network or an upstream Internet Service Provider (ISP) which is not routing IPv6 traffic correctly.
When this kind of problem occurs, you may be tempted to simply disable IPv6 altogether, and while this will resolve the problem, it is not the recommended solution. The problem may only occur with certain services, and some sites today may only be accessible using IPv6. Instead of disabling IPv6, you can tell Windows you prefer to use IPv4, and to only use IPv6 if there is no IPv4 address available for the server you want to connect with.
To list the default precedence Windows uses when establishing a TCP/IP connection, open an administrative command prompt and enter the following command:
netsh interface ipv6 show prefixpolicies
This will output something which looks like this:
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 precedence value shows the order in which the TCP/IP stack will prioritize connections based on the destination IP address. It’s not necessary to understand what all of those IP address prefixes mean, but the important part is the ::ffff:0:0/96 prefix has a lower priority than ::0 which means IPv6 is preferred over IPv4.
You can temporarily change this priority by changing the precedence value for the ::ffff:0:0/96 prefix to a value higher than 40. This can be done with the following command:
netsh interface ipv6 set prefixpolicy ::ffff:0:0/96 45 4
You can verify the new precedence by using the previous command and checking the output. It should look like this:
Precedence Label Prefix ---------- ----- -------------------------------- 50 0 ::1/128 45 4 ::ffff:0:0/96 40 1 ::/0 30 2 2002::/16 5 5 2001::/32 3 13 fc00::/7 1 11 fec0::/10 1 12 3ffe::/16 1 3 ::/96
Now that you have told Windows you want to prefer IPv4 over IPv6, try establishing a connection with the service you’ve been having a problem with and see if it resolves the issue.
If you want to make this change permanent, you can change or create a registry setting which will tell Windows to always prefer IPv4. Open the registry editor (RegEdit) and navigate to the key:
Look for a value named DisabledComponents and create it if it does not already exist. It should be a DWORD value type with the value 20 (hexadecimal). You could save the following to a registry (.reg) file and import it:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters] "DisabledComponents"=dword:00000020
Despite the implications of the key value, this does not actually disable IPv6, it simply causes Windows to prioritize IPv4 over IPv6. You can revert this change by either setting the DisabledComponents value to 0 or simply deleting the value.
You can learn more about this setting in Microsoft’s documentation for configuring IPv6 in Windows.
Not all applications use the Windows prefix policy configuration to determine whether to prefer IPv6 over IPv4. Microsoft Edge and Google Chrome will use these policy settings, but other browsers (or any other application) may choose to use its own preferences.
One example of this is the Firefox browser, which will automatically attempt to determine if an IPv6 connection is available and will always prefer it unless IPv6 has been explicitly disabled in its settings.
If you find a particular application is still using IPv6 even though you have configured the system to prefer IPv4, check its settings and see if there is an option to either disable IPv6 within the program or switch the priority around so IPv4 is preferred.
Applications created using SocketTools will always prefer IPv4 over IPv6, regardless of how the local system is configured. This was an intentional design choice on our part for backwards compatibility with legacy servers.
You can tell the SocketTools components you prefer to use IPv6 by specifying an option when you connect with the server. For the .NET classes, this option is named optionPreferIPv6 in the options enumeration for the class. There are similar names for the ActiveX controls (e.g.: httpOptionPreferIPv6) and the library APIs (e.g.: HTTP_OPTION_PREFER_IPV6) which all perform the same function.
IPv6 has been adopted widely enough that future versions of SocketTools will start using the prefix policy to determine whether IPv6 should be used by default. If your application stores IP addresses, we recommend you make sure your code is “IPv6 aware” and handles IPv6 formatted IP addresses correctly.