Setting up Internal vSwitch NATing in Hyper-V

Powershell FTW

Being used to VMware Workstation, where NATing is a few GUI clicks away, I couldn’t find a GUI way of configuring it in Hyper-V.

inside local outside hokey pokey; Turn yourself around

I don’t mind the command line and actually prefer it sometimes. The PowerShell equivent didn’t end up being too bad. Not like the first time doing Cisco NAT from the CLI 🙂

Setting up NAT

The first code block is the generic commands from the Microsoft reference document the second one is what I used in my lab.

# Create Internal vSwitch for NAT
New-VMSwitch -SwitchName "SwitchName" -SwitchType Internal
# Configure the NAT gateway
New-NetIPAddress -IPAddress <NAT Gateway IP> -PrefixLength <NAT Subnet Prefix Length> -InterfaceIndex <ifIndex>
# Configure the NAT network
New-NetNat -Name <NATOutsideName> -InternalIPInterfaceAddressPrefix <NAT subnet prefix>

 

New-VMSwitch –SwitchName “NATvSwitch” –SwitchType Internal
New-NetIPAddress –IPAddress 172.143.1.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"
New-NetNat –Name myNATnetwork –InternalIPInterfaceAddressPrefix 172.143.1.0/24

Note

Windows (WinNAT) only supports one internal NAT subnet prefix, trying to create multiple NATs will place the system into an unknown state. 1.

Thanks,

Scott Bollinger / kfalconspb / bollingerusa.com

References
1. https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/setup-nat-network/

2. http://www.thomasmaurer.ch/2016/05/set-up-a-hyper-v-virtual-switch-using-a-nat-network/