Wednesday, January 11, 2017

Setting up a NAT virtual switch in Hyper-V

Below is a quick reference guide to setting up a NAT (Network Address Translation) virtual switch in Hyper-V using PowerShell. This only works on the later builds of Windows 10 and Windows Server 2016. A NAT virtual switch can be useful if you are setting up a virtual lab for example.

In our example, we'll be setting a virtual switch and NAT rule called on subnet

Step 1. Create a "Internal" VM Switch

Start PowerShell as an administrator on your Hyper-V host a create an internal virtual switch with the following command.
New-VMSwitch -Name "" -SwitchType Internal

Step 2. Create a Private IP Network for NAT

Next, define the internal subnet that we are going to be using for NAT.
New-NetNat -Name -InternalIPInterfaceAddressPrefix

Step 3. Assign a Default Gateway IP Address

Finally assign an IP address from the internal subnet that we just defined to be our gateway to the virtual switch we created earlier.
New-NetIPAddress -IPAddress -PrefixLength 24 -InterfaceAlias "vEthernet ("

Note: There are a few things that you'll need to be aware of when NAT is set up. Current builds of Windows 10 and Windows Server 2016 appear to only allow you to have one NAT network. The other thing to note is that NAT switches do not provide DHCP or DNS services to your NAT network. You'll need to setup a virtual machine on that network for those services.

No comments:

Post a Comment