Create NAT Virtual Switch on Hyper-V

Hyper-V Virtual Switch using NAT Configuration

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on TumblrShare on RedditEmail this to someone

Update:

This blog post is blog post is for older Windows 10 builds, for newer Windows 10 and Windows Server 2016 builds please follow this blog post:

Set up a Hyper-V Virtual Switch using a NAT Network

In the latest Windows 10 build 10586 (Threshold 2) and Windows Server 2016 Technical Preview 4, Microsoft included a great new feature which is NAT mode for the Hyper-V Virtual Switch. This was mostly build for Windows Containers scenarios, but also has great value for Client Hyper-V. As of today Hyper-V had 3 different VMSwitch types called, Internal, Private and External. With the latest releases of the Windows 10 and Windows Server 2016 Technical Preview 4, Microsoft included a new VM Switch Type called NAT, which allows Virtual Machines to have a Internal Network and connect to the external world and internet using NAT. This feature right now is not included in the UI but you can use PowerShell to create the NAT Virtual Switch.

Create a new Virtual Switch using NAT:

Create NAT Virtual Switch on Hyper-V

Setup the NAT configuration:

This will create a new VM Network Adapter on the host using the 172.29.92.1 IP Address. You can now use the NATSwitch to connect Virtual Machines. You can now set IP Addresses inside Virtual Machines to the 172.29.92.0/24 subnet and add 172.29.92.1 as the default gateway and you are good to go.

Hyper-V Virtual Switch NAT Configuration

Create a new NAT forwarding

To forward specific ports from the Host to the guest VMs you can use the following commands.

This example creates a mapping between port 80 of the host to port 80 of a Virtual Machine with an IP address of 172.29.91.2.

This example creates a mapping between port 82 of the Virtual Machine host to port 80 of a Virtual Machine with an IP address of 172.29.91.3.

This also works with Windows and Hyper-V Containers.

Update – 4/27/2016 #1

As many of the people mentioned, the option of the SwitchType NAT is gone in the latest Windows Insider Preview builds of Windows 10. If you have created a NAT Switch in Windows 10 before the upgrade to a Windows 10 insider build, the switch is still working. There is no comment at the moment from Microsoft on this. But Microsoft announced Hyper-V Container support for Windows 10, and since the NAT Switch makes totally sense when you are using containers, I guess the SwitchType for NAT will be coming back.

Update – 4/27/2016 #2

With the latest Windows 10 Insider Build 14332, I saw some Container Network PowerShell cmdlets, which maybe will replace the Hyper-V Switch NAT cmdlet options for the future. But this is just guessing.

Container Network PowerShell

Update – 5/3/2016

Here is a updated version how you can configure the Hyper-V NAT Switch in newer Windows 10 and Windows Server 2016 builds.

Have fun and enjoy! Thanks to Ben Armstrong (Microsoft VirtualPCGuy) for the info.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on TumblrShare on RedditEmail this to someone