Windows Server 2016 – Create a NAT network using the Hyper-V switch

In Windows Server 2016 (TP4) and Windows 10 1511 it is possible to create a Hyper-V Switch with NAT functionality, including publishing rules. The purpose is to run containers, but it can of course be used to run normal virtual machines. This means that you can very easy build an infrastructure environment with access to Internet and reverse without having a virtual router or firewall, pretty neat IMHO. Currently, the only way to create the switch is using PowerShell, but hey, I don’t mind…

Create the Switch

The following command will create a VM Switch for NAT usage with a subnet of The net result will be a switch and an Internal network adapter with the IP address

New-VMSwitch -Name ViaMonstraNAT -SwitchType NAT -NATSubnetAddress

Create the NAT rule to get out

The following command will create a NAT rule for all machines connected to the Switch that uses the default gateway to get out.

New-NetNat -Name ViaMonstraNAT -InternalIPInterfaceAddressPrefix

Create a publishing rule

The following rule will open the “firewall” and redirect traffic on the hyper-v host port tcp/80 to the machine on the VM Switch with the IP address to tcp/80

Add-NetNatStaticMapping -NatName ViaMonstraNAT -Protocol TCP -ExternalPort 80 -InternalIPAddress -InternalPort 80 -ExternalIPAddress

Check if it works

You can use the following PowerShell commandlets to see the configuration after it has been done.

Get-VMSwitch will show you the switch with SwitchType NAT.

Get-NetNat will show you the NAT configuration bound to the switch.

Get-NetNatStaticMapping will show you the publishing rule.

Get-NetNatSession will show you current NAT sessions.


3 replies »

      • Darn. Yeah, when I tell it the switch -Switchtype the only options are external, Internal, and private now. This was on my personal laptop that is running Professional not Enterprise so not sure if that can be the case. I will spin up a VM and test later. It works for my work laptop without a problem. Then again, I am still on 1511 right now. Looking forward to seeing you out here in the oven of Phoenix in a few weeks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.