Hyper-V Virtual NAT Switch Setup

Setting up a virtual NAT network for Hyper-V virtual machines.

Purpose

When setting up virtual machines on a single host that need to be interconnected, it can be extremely useful to have your own virtual network where the machines can have static IP addresses that won't change, even if the host machine is connected to different networks. To accomplish this on Hyper-V, you can create a new virtual switch that uses NAT.

Steps

Launch a new PowerShell session as an administrator.

Create the new virtual switch for an "Internal" network:

New-VMSwitch -SwitchName "NATSwitch" -SwitchType Internal

Assign an IP address to the new switch device:

New-NetIPAddress -IPAddress 192.168.122.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"

Set up NAT:

New-NetNAT -Name "NATNetwork" -InternalIPInterfaceAddressPrefix 192.168.122.0/24

Now, you can attach your virtual machines to the new switch and configure them with static IP addresses. If you used the commands above verbatim, then you can pick any addresses from 192.168.122.2 through 192.168.122.254.

No DHCP or DNS

This virtual NAT network does not have DHCP or DNS services. Unless you set these up separately, you will need to configure static IP addresses and DNS servers on virtual machines attached to this virtual network.