Skip to Content

Windows 10/11 Hyper-V Default Network IP Address Keeps Changing

Making it challenging to statically assign IP addresses to VM's

Hyper-V Logo

Microsoft Hyper-V is a wonderful thing. A performant Type 1 hypervisor available natively to Windows client operating systems without the overhead of Type 2 hypervisors (VMware Workstation).

The Hyper-V Default Network (Default Switch) available in Windows 10/11 Hyper-V is also a wonderful thing providing DHCP, DNS, and NAT (technically PAT/overload/DIPP) so VM’s can get an IP address and reach the rest of the world through the host’s physical wired/wireless adapter. No special configuration required, it just works.

Hyper-V Default Network

Hyper-V Default Network (Default Switch)

Hyper-V Default Network

What if a static IP address is needed for some of the VM’s on a Windows 10/11 Hyper-V instance?

  • Find the IP address of Hyper-V’s gateway (ipconfig.exe or Get-NetAdapter)
  • Pick an address in the network
  • Use the Hyper-V interface address as the default gateway
  • Pick DNS resolvers (the Hyper-V gateway IP also works)
  • Assign the parameters in the guest OS

Works well… until the Hyper-V host reboots.

Reboot the Windows 10/11 host and find the Hyper-V Default Network (and interface IP address) has changedbreaking connectivity for guest VM’s with static addresses. Guest VM’s using DHCP pick up the change (the nature of DHCP).

No way to disable the behavior on the Hyper-V Default Network (as of 2022-Sep). We have better things to do than re-IP statically assigned guest VM’s every time the host reboots.

Restore Hyper-V Default Network Address

And PowerShell there was. Full GitHub Gist below.

Usage

  1. Find the Config section
  2. Update/change the IPv4Address to preferred IPv4 address of the Hyper-V Default Network interface (which will be the default gateway for VM’s)
  3. Update/change the IPv4PrefixLength to preferred prefix length, CIDR style. Hyper-V defaults to 20. Do not enter in 255.255.240.0 form.
  4. Update/change the InterfaceAlias to Hyper-V Default Network interface name (determined from ipconfig.exe or Get-NetAdapter)
Config Section

Config Section

Config Section

Example

Example

Example run on PowerShell 5.1

Example

Consider

  • Local administrator privileges are required for service restarts. If the local account does not have them, an informative error will be presented.
  • Frequently, the last service restart fails, but the result of the script is an overall success.
  • VM’s do not need to be restarted after the script completes.
  • Run ad-hoc or as a scheduled task on boot.
  • Tested against Windows PowerShell 5.1 and PowerShell 7.2

Et cetera

Other solutions to this challenge exist. Hyper-V supports building additional Internal virtual networks (virtual switches). Unfortunately, the default DHCP and NAT behavior is only possible on one Hyper-V’s network. Many have reported challenges in getting it to work on networks other than the Default Network (Default Switch). Deploying DHCP and NAT by other means on additional Internal networks is more than trivial. It is simpler to apply the desired addressing the Default Network and use its DHCP and NAT capabilities.