How to set IPv4 as preferred IP on Windows Server using PowerShell

IPv6 InternetSometimes working with Lync and Skype for Business I see that the services are trying to contact other servers or localhost which returns an IPv6 address. If the service is set to run only on IPv4 the service will fail and not find the listening interface since it is not listening on IPv6. In these cases I do not disable IPv6 but prefer IPv4. This needs to be done in registry and a reboot is required after the change. Do not disable IPv6 on the network card because that will not work.

Here is a simple way to do it using PowerShell

Break #In case you paste this in to PowerShell ISE and press run script:)
#Check if IPv4 IP address is preferred
ping $env:COMPUTERNAME
#If the reply is IPv6 address, run following registry setting to just prefer ipv4 and reboot
New-ItemProperty “HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\” -Name “DisabledComponents” -Value 0x20 -PropertyType “DWord”
#If DisabledComponents exists, use the set cmdlet
Set-ItemProperty “HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\” -Name “DisabledComponents” -Value 0x20
#You need to reboot the computer in order for the changes to take effect
Restart-Computer

Check the values below for other options

  1. Type 0 to re-enable all IPv6 components (Windows default setting).
  2. Type 0xff to disable all IPv6 components except the IPv6 loopback interface. This value also configures Windows to prefer using IPv4 over IPv6 by changing entries in the prefix policy table. For more information, see Source and destination address selection.
  3. Type 0x20 to prefer IPv4 over IPv6 by changing entries in the prefix policy table.
  4. Type 0x10 to disable IPv6 on all nontunnel interfaces (both LAN and Point-to-Point Protocol [PPP] interfaces).
  5. Type 0x01 to disable IPv6 on all tunnel interfaces. These include Intra-Site Automatic Tunnel Addressing Protocol (ISATAP), 6to4, and Teredo.
  6. Type 0x11 to disable all IPv6 interfaces except for the IPv6 loopback interface.

Reference:

https://support.microsoft.com/en-us/kb/929852

3 thoughts on “How to set IPv4 as preferred IP on Windows Server using PowerShell

  1. This is the easy but “wrong” solution.
    The correct solution today, is to educate companies on how to adopt IPV6 and deploy a minimum, working configuration :$

    • Hehe, true, but not something you want to start with if you encounter this mid deployment. That is why disabling IPv6 is not a good approach, just prefer IPv4 and your problems goes away :)

    • Do you know someone who wants to pay for new routers to support IPv6? The “correct” solution in our case is exactly the procedure above to prefer IPv4. If you can’t do IPv6 from end to end, then don’t do it at all.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.