0
votes

What I need to accomplish is to have localhost resolve to an IPv4 address rather than an IPv6 address. I'm a ASP.NET developer and our internal web app checks the IP address against a few ranges to make sure you are from an allowed range.

I've tried everything I can think of, even change the hosts file which I don't think I need to do on Windows 10. Look at my screenshot. Can anyone help explain why I'm still getting IPv6?

PowerShell screenshot

2
this belongs on Super UserDaniel A. White
This is a bug in your web app, not a Windows configuration problem. Fixing the web app is the preferred solution.Michael Hampton

2 Answers

0
votes

Look at the Properties of the network adapter, "Change adapter settings" You should see a list of protocols, like "Client for Microsoft Windows", "File and printer sharing" and below those.. "Internet Protocol version 4" AND "Internet Protocol version 6"

To use only IPv4, check it, and uncheck IPv6

Afterwards, look at the properties for IPv4 You may need to specify an IP address, if you have no DHCP servers that allocate Ipv4 IPs. That might look like... 192.168.1.X where X is not in use by another system on your network.

That would typically make the Gateway 192.168.1.1 and netmask of 255.255.255.0

You can also set your DNS there. I suggest using Google's free one 8.8.8.8 and 8.8.4.4

0
votes

Due to a security concern Microsoft since 8.1 has hardwired DNS resolution for localhost to 127.0.0.1 and ::1 for ipv4 and ipv6 respectively. Furthermore it favors IPv6 you can change this preference via the registry but it requires a reboot.

New-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\ -Name DisabledComponents -Value 0x20 -PropertyType DWord

Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\ -Name DisabledComponents -Value 0x20

restart-computer

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

Powershell commands from: https://msunified.net/2016/05/25/how-to-set-ipv4-as-preferred-ip-on-windows-server-using-powershell/

Update: A better way is to use a prefix policy adjustment. That way you don't need to mess with the registry. From an elevated command prompt:

el PS> ping localhost 
Reply from ::1: time<1ms
... 
el PS> netsh interface ipv6 set prefixpolicy ::ffff:0:0/96 precedence=51 label=4 
el PS> ping localhost 
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
... 

To make it persistent: netsh interface ipv6 set prefixpolicy ::ffff:0:0/96 precedence=51 label=4 store=persistent

If it doesn't work run netsh interface ipv6 show prefixpolicies to make sure that the precedence level for the above is higher than the precedence for ::1/128.