How To Fix Slow DNS Response and Page Loading with Hyper-V Default Switch

How To Fix Slow DNS Response and Page Loading with Hyper-V Default Switch

In my move away from VMware workstation I’ve been using Hyper-V more and more for virtual machines but I’ve come across a problem only recently. DNS resolution and internet browsing is noticeably slower with many pages not being able to be viewed at all. So after much frustration I decided to tackle this problem today and I found something unexpected.

Along with the new Fall Creators Update released at the tail end of 2017 is a new Hyper-V NAT switch called Hyper-V (Default Switch). This switch by default takes up an IP address on the 172. network (in my case 172.28.111.0/28) and provides a DHCP service to virtual machines connected to it. So no more static IP configuration. A big plus.

If you only want the solution, then jump to here.

Slow DNS resolution and page response

I started looking at this issue after I got fed up with the long waits while the browser was resolving URL’s and displaying pages. I initially thought it was a DNS issue (understandably) so I used nslookup:

PS> nslookup
DNS request timed out.
    timeout was 2 seconds.
Default Server:  UnKnown
Address:  172.28.112.33

The timeout was unexpected and the IP address show was odd address of my workstation is in the 10.0.0.0/24 subnet. Why is my default IP address 172.28.112.33?:

PS> Get-NetIPAddress -IPAddress 172.28.112.33 | Select IPAddress, InterfaceIndex, InterfaceAlias

IPAddress     InterfaceIndex InterfaceAlias
---------     -------------- --------------
172.28.112.33             20 vEthernet (Default Switch)

So it looks like the Hyper-V (Default Switch) adapter is being used over my normal LAN adapter. I looked at a list of the adapters and their priorities:

PS> Get-NetIPInterface | Sort InterfaceMetric

ifIndex InterfaceAlias                  AddressFamily NlMtu(Bytes) InterfaceMetric Dhcp     ConnectionState PolicyStore
------- --------------                  ------------- ------------ --------------- ----     --------------- -----------
20      vEthernet (Default Switch)      IPv6                  1500              15 Enabled  Connected       ActiveStore
20      vEthernet (Default Switch)      IPv4                  1500              15 Enabled  Connected       ActiveStore
17      vEthernet (LAN)                 IPv4                  1500              25 Enabled  Connected       ActiveStore
17      vEthernet (LAN)                 IPv6                  1500              25 Enabled  Connected       ActiveStore
10      Bluetooth Network Connection 2  IPv6                  1500              65 Disabled Disconnected    ActiveStore
10      Bluetooth Network Connection 2  IPv4                  1500              65 Enabled  Disconnected    ActiveStore
1       Loopback Pseudo-Interface 1     IPv4            4294967295              75 Disabled Connected       ActiveStore
6       Teredo Tunneling Pseudo-Inte... IPv6                  1280              75 Enabled  Disconnected    ActiveStore
1       Loopback Pseudo-Interface 1     IPv6            4294967295              75 Disabled Connected       ActiveStore

The lower the InterfaceMetric the higher the adapter priority. By default all traffic from the host, in this case my workstation, goes through the vEthernet (Default Switch). Having this adapter being used first doesn’t make much sense on a workstation which is used day to day.

So how do we fix this?

There are two solutions to this that I discovered - the first requires a re-prioritising of the network adapters on my workstation, and was the solution I used. The second requires you adding a DNS server to the settings on the Hyper-V (Default Switch).

Re-prioritise the network adapters

As we have the Hyper-V (Default Switch) as the first adapter being used on the workstation, we need to change it’s priority so that we use the vEthernet (LAN) switch instead. Take note of the InterfaceMetric of this switch and the one after it (in our case Bluetooth Network Connection 2) and use a priority somewhere in the middle (we are going to use 45). We do this through an elevated PowerShell command line of course:

PS> Get-NetIPInterface -InterfaceAlias '*(Default Switch)' | `
	Set-NetIPInterface -InterfaceMetric 45 -Passthru | Sort InterfaceMetric

ifIndex InterfaceAlias                  AddressFamily NlMtu(Bytes) InterfaceMetric Dhcp     ConnectionState PolicyStore
------- --------------                  ------------- ------------ --------------- ----     --------------- -----------
17      vEthernet (LAN)                 IPv4                  1500              25 Enabled  Connected       ActiveStore
17      vEthernet (LAN)                 IPv6                  1500              25 Enabled  Connected       ActiveStore
20      vEthernet (Default Switch)      IPv4                  1500              45 Enabled  Connected       ActiveStore
20      vEthernet (Default Switch)      IPv6                  1500              45 Enabled  Connected       ActiveStore
10      Bluetooth Network Connection 2  IPv4                  1500              65 Enabled  Disconnected    ActiveStore
10      Bluetooth Network Connection 2  IPv6                  1500              65 Disabled Disconnected    ActiveStore
1       Loopback Pseudo-Interface 1     IPv4            4294967295              75 Disabled Connected       ActiveStore
6       Teredo Tunneling Pseudo-Inte... IPv6                  1280              75 Enabled  Disconnected    ActiveStore
1       Loopback Pseudo-Interface 1     IPv6            4294967295              75 Disabled Connected       ActiveStore

Now using nslookup immediately shows:

PS> nslookup

Default Server:  dns.mynetwork.local
Address:  10.0.0.1

No timeout. I’ve tested virtual machines network connectivity after making this change and there is no issue. And most importantly of all, it survives a reboot. Whether it will survive a future update remains to be seen.

Add DNS servers to the Hyper-V Default Switch

This one requires you to add your DNS server to the Hyper-V (Default Switch). Again using an elevated PowerShell command line:

PS> Get-NetIpInterface -InterfaceAlias '*(Default Switch)' | `
	Set-DnsClientServerAddress -ServerAddresses '10.0.0.1' -Validate -Passthru

InterfaceAlias               Interface Address ServerAddresses
                             Index     Family
--------------               --------- ------- ---------------
vEthernet (Default Switch)          20 IPv4    {10.0.0.1}
vEthernet (Default Switch)          20 IPv6    {}
vEthernet (Default Switch)          20 IPv6    {}
vEthernet (Default Switch)          20 IPv4    {10.0.0.1}

Easy. But this doesn’t resolve the issue of the LAN adapter not being the priority in communicating with the network.

Summary

The new NAT network switch, Hyper-V (Default Switch), is a really welcome addition that has been requested for some time. When moving from VMware Workstation to Hyper-V it was the one feature that had me scratching my head on why it was missing. But I’m unsure why Microsoft decided to make it the primary adapter for network communication. But hopefully this resolution will stop some frustration.