Ok, I love Hyper-V. End of blog! Not so fast. I do love how Hyper-V has progressed and now is a serious competitor to various other products… not to mention any names. To be serious, I have nothing against VMWare. They have a very nice product and of course own the market even today. However, for those that have not dived into Hyper-V or tried it out before Windows Server 2012 R2, I think you should give it another look. If not for a production environment at least look at it for a quick way to build a sandbox lab, a pre-prod environment, etc. However, I would tell you to go further and look at it for production as well. I won’t argue the pros/cons of Hyper-V vs. VMware. That can come later if needed. Now, about this blog.
I would like to give credit to the following blog that I am going to steal everything from. :) Before Windows 10 and Windows Server 2016, trying to NAT within Hyper-V, well was a challenge. Specially if you where like me and traveled with a laptop and switched between wireless and wired connections. Not too long ago, I found a good blog on how to actually create a NAT virtual switch within Hyper-V running on Windows 8.1. This process involved VMWare Workstation and using some of the virtual switches VMWare Workstation would create. Why? Dumb yes, but pretty much the only way to truly way you could do this. I will give credit to this process to Thomas Vochten and his blog. Now, this is obsolete. He also has another blog that talks about the new process here. However I followed another blog before I found his new blog.
The blog I am going to copy is Kyle Beckman’s blog over at 4sysops. Native NAT in Windows 10 Hyper-V using a NAT virtual switch, which details pretty much everything you need.
I have not tried this in the newest build of Windows Server 2016 as of yet. I am using the latest branch of Windows 10 1511 (OS Build 10586.104). As Kyle mentions in his blog, these steps are not yet available in the GUI, however, hopefully soon it will be. The following, I have to admit, I have take directly from Kyle’s blog. I did change the Subnet Address but still, all credit goes to Kyle.
Create the NAT switch
This is a two step process. First we create the new VMSwitch and then we will create the new NAT Object. Open a PowerShell session using Admin rights and run the commands:
New–VMSwitch –Name “NAT” –SwitchType NAT –NATSubnetAddress 192.168.10.0/24New–NetNat –Name NAT –InternalIPInterfaceAddressPrefix 192.168.10.0/24
Quick reference on the following commands:
You can use the following commands to verify that the switch was created and the new NAT object was created. Get-VMSwitch and Get-NetNat.
You can also verify and view the newly created switch in the Virtual Switch Manager. As Kyle mentioned, hopefully soon this feature would be available in the GUI, but as for now it has to be enabled via PowerShell. Which to be honest isn’t a bad thing these days. PowerShell is your friend!!!
You will now also have a new vEthernet adapter created in your Network Connections called vEthernet (NAT). If you open the properties and view the IPv4 properties you should see the IP address set to 192.168.10.1 if you used the same subnet I used and a subnet mask of 255.255.255.0.
Configuring your VM’s
Now we are ready to configure our VM’s to use our newly created NAT virtual switch. At this time the built-in NAT switch doesn’t do DHCP. Maybe and hopefully Microsoft will change that in upcoming builds. Kyle has two examples, one that configures the VM’s manually which is what I have done. He also goes into another example of installing DHCP for Windows a small freeware application. I will leave that up to you to research by going to his blog. If this was my personal laptop I would not have an issue with installing DHCP. However this is my work laptop I am currently using and security and compliance would kill me if I ran a DHCP server on my laptop, even if it is configured only for my NAT interface.
It is pretty basic Windows OS networking configuration from here. Open Network and Sharing Center, click on Change adapter settings, select the Microsoft Hyper-V Network Adapter named Ethernet, then right click and select properties. Select IPv4 and click the properties button.
I have added our internal DNS in order for my VM to properly communicate internally. However, if you are just using this for a personal VM, go ahead and put Google DNS or Open DNS IP’s for your Preferred DNS servers. The IP address would be anything above your gateway, I like to start with 10 and go up from there. Gateway would be the NAT Ethernet adapter, mine was 192.168.10.1 and subnet mask was 255.255.255.0.
If you are using the DHCP server that Kyle mentions, you wouldn’t need this step and you are now ready. I have tested this on using both my wired and wireless connection without any issues.
I hope this helps. Looking forward to more progress with Hyper-V, Windows Server 2016, and Windows 10!