Latest posts by Kyle Beckman (see all)
- Managing shared mailboxes in Office 365 with PowerShell - Thu, May 5 2016
- Managing shared mailboxes in Office 365 with the GUI - Wed, May 4 2016
- Installing and configuring the Enhanced Mitigation Experience Toolkit (EMET) - Wed, Mar 16 2016
Setting up NAT in Windows 10 has always been one of the shortcomings of Hyper-V on the Windows desktop OS when compared to other virtualization products such as VMware Workstation and Oracle VirtualBox. In the past, it was necessary to set up Internet connection sharing or use a VM running Windows Server with two NICs to share your computer’s Internet connection under NAT.
In previous versions of Hyper-V, three types of virtual switches exist: External, Internal, and Private. In Windows 10 Fall Update, a fourth switch, the NAT switch, is included. As of today, the NAT switch type can only be created using PowerShell. But, it’s pretty safe to assume it will make it into the GUI eventually.
Create the NAT switch ^
Creating the NAT switch is a two-part process. You’ll first need to create the switch and then configure the NAT object in the host OS. To create the virtual switch, open a PowerShell window with Admin rights and run the following command:
New-VMSwitch -Name "NAT" -SwitchType NAT -NATSubnetAddress 10.0.75.0/24
The -Name parameter sets the name of the new virtual switch. The –SwitchType parameter (which needs to be set to NAT) is what selects NAT as the switch type. The –NATSubnetAddress parameter sets the subnet that will be used on the NAT network. The virtual NIC that is created on the host computer will use the top address, .1, as its IP. In the example subnet I used, the virtual NIC will use 10.0.75.1.
Next, you’ll need to create the NAT object on the host system. In the same PowerShell window, run the following command:
New-NetNat –Name NAT –InternalIPInterfaceAddressPrefix 10.0.75.0/24
The -Name parameter sets the name for the NAT object. The –InternalIPInterfaceAddressPrefix parameter sets the subnet that NAT will use; it should be the same subnet that you used in the last command.
View the switch in the Virtual Switch Manager ^
In Hyper-V Manager, go to Virtual Switch Manager to see your new virtual switch named “NAT.” The GUI doesn’t recognize the new switch type and shows it as an Internal switch. An Internal switch allows the VMs on the host system to communicate with each other as well as with the host system. So, it makes sense that it would see the switch this way—at least until the GUI is updated.
View the new vEthernet adapter ^
The process of adding the new NAT switch will also create a new vEthernet adapter on the system. If you open the properties of the virtual NIC, it should show the IP address 10.0.75.1. This address can be used as the default gateway on VMs connected to the switch.
Configure the VM manually ^
After you configure a VM to use the NAT virtual switch, you will need to manually configure the network settings for the VM. Unfortunately, the built-in NAT switch doesn’t include a DHCP server for automatic network configuration. In my example VM below, I’ve configured the gateway to 10.0.75.1 and used 10.0.75.10 as the IP address of the VM. For a DNS server, I’ve used Google’s public DNS server, 184.108.40.206.
Manually configuring the Hyper-V VM
Obviously, you’re not going to want to manually configure all of your VMs that use the NAT switch. One option if you’re already running a small lab on your Windows 10 system is to use DHCP on a Windows Server. If you don’t want to run a full server for DHCP, I’ve found one other option.
DHCP Server for Windows ^
You can use a small, freeware, DHCP server called DHCP Server for Windows for providing DHCP to your NAT network in Hyper-V. After you download the software, extract it and run the dhcpwiz.exe utility to configure the server.
First, select the network interface vEthernet (NAT). Good news: the GUI does a good job of warning you about setting up a DHCP server on a NIC that is already receiving an IP address through DHCP.
Set the pool of IP addresses you want to use as well as a lease time. When you’re done, make sure you click the Advanced… button.
In Advanced Configuration, you’ll need to configure your gateway (10.0.75.1) and DNS servers.
In the final screen of the wizard, click the Write INI file button to save your settings to an .ini file and then click Next.
Once you’re done, the control application, dhcpsrv.exe, should run automatically. If it doesn’t, the executable is in the same folder as the setup wizard.
You’ll first need to click the Admin… button to run the executable with Admin rights (if you didn’t already). In this utility, you can set the Windows Firewall rules necessary to run the DHCP server. You can also install the executable as a service and start/stop it from running. After you’ve installed it as a service and started the service, you’re ready to start using NAT with your VMs on Hyper-V.