Many articles seem to instruct users to create a NAT using the VMSwitch type of NAT. Unfortunately, Microsoft has since removed this type of switch. All commands that follow require the use of PowerShell. Here is how to use NAT with VMs running under Hyper-V currently:
- Create a new Hyper-V Switch
New-VMSwitch -SwitchName "NAT" -SwitchType Internal
- Obtain the ifIndex from the switch that was just created.
- Associate an IP address with the new switch. In this case, I will be using the private IP range of 192.168.128.0/24.
New-NetIPAddress -IPAddress 192.168.128.1 -PrefixLength 24 -ifIndex 21
- Create a NAT rule to forward traffic.
New-NetNat -Name NATNetwork -InternalIPInterfaceAddressPrefix 192.168.128.0/24
You can now associate the NAT switch with any VMs you wish to be NAT’d. There are a few caveats however:
You can only have one NAT network currently.
VM IP addresses need to be configured manually. No DHCP server exists by default.
The connection seems to work with only hardware network connections (wifi, ethernet, etc) and not VPN tunnels.
Now enjoy NAT in Hyper-V!