Reading Time: 3 minutes
Share:
Twitter
LinkedIn
Facebook
Reddit
Whatsapp
Follow by Email

In this post, I am going to show you how to create a NAT (network address translation) Virtual Switch for Hyper-V on Windows 10 or Windows Server 2016. A virtual NAT switch enables virtual machines to be isolated behind a single shared IP address on the host server. This is very Handy for Windows Server or Hyper-V Containers.

What is NAT?

Network Address Translation (NAT) is a networking technology that has been designed to conserve IP addresses by mapping an external IP address and port to a much larger set of internal IP addresses. Usually, this will be done with a firewall, but in this guide, we are going to be using a Hyper-V Virtual Switch.

For NAT to work it has to use a flow table with rules. These rules basically point the traffic from an external (host) IP Address and port number to an internal IP address on your network (Virtual Machine, Container, Server…) This is very handy when you need to host multiple applications that use the same internal port by mapping them to unique external ports.

Create A NAT Virtual Switch

[themify_box style=”black warning”] Currently, you can only create one NAT network per host!
[/themify_box]

It is really easy to create a NAT Virtual Switch for Hyper-V. In fact, it is only done via PowerShell and only uses 3 lines of code.

Create Internal Virtual Switch

Open PowerShell with Elevated permissions and type:

New-VMSwitch -SwitchName "NATvSwitch" -SwitchType Internal
view raw New_NAT-vSwitch.ps1 hosted with ❤ by GitHub

Changing the –SwitchName to something you want to use.

Update Virtual NIC

Open PowerShell with Elevated permissions and type:

New-NetIPAddress -IPAddress 10.10.10.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATvSwitch)"
view raw New_NAT-vSwitch.ps1 hosted with ❤ by GitHub

Changing the –IPAddress to something you want to use. This IP Address will become the default gateway for your NAT’ed devices.
You can also change the –InterfaceAlias to something you like also.

Configure NAT network Address

Open PowerShell with Elevated permissions and type:

New-NetNAT -Name "NATvNetwork" -InternalIPInterfaceAddressPrefix 10.10.10.0/24
view raw New_NAT-vSwitch.ps1 hosted with ❤ by GitHub

Changing the –Name to something you want to use. You also need to change -InternalIPInterfaceAddressPrefix to the IP range you are using. But note the IP Address you set in the previous step has to be in this range.

Some things to note are that any virtual machine that runs on the new NAT virtual switch has to use an IP address in the address range you specified. So in this case 10.10.10.0/24. They will either need to be set manually or via a DHCP Service you install, as by default the NAT Virtual Switch does not have DHCP functionality.

To be able to access the new virtual machines remotely we are going to have to create some NAT rules. I will go over this in another article. I will post a link to it here when it’s ready.

Link: https://pixelrobots.co.uk/2017/07/how-to-create-nat-rules-for-hyper-v-virtual-nat-switch/

And that’s it you have now Created a new NAT Virtual Switch and Network.

Share:
Twitter
LinkedIn
Facebook
Reddit
Whatsapp
Follow by Email

Pixel Robots.

I’m Richard Hooper aka Pixel Robots. I started this blog in 2016 for a couple reasons. The first reason was basically just a place for me to store my step by step guides, troubleshooting guides and just plain ideas about being a sysadmin. The second reason was to share what I have learned and found out with other people like me. Hopefully, you can find something useful on the site.

2 Comments

How to create NAT rules for Hyper-V Virtual NAT Switch – Pixel Robots. · July 14, 2017 at 2:06 pm

[…] Before you read this post I highly recommend you read this article first: https://pixelrobots.co.uk/2017/06/create-a-hyper-v-nat-virtual-switch/ […]

How To Setup Nested Virtualization In Microsoft Azure - Pixel Robots. · February 18, 2018 at 10:37 pm

[…] can get past this hurdle by creating a NAT Switch in Hyper-V. You can read more about NAT Switches here or follow the rest of this guide to get yourself up and […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

I agree