Windows 10 – Hyper-V and NAT [Quick Guide]

7:40 pm January 2, 20176144

I. introduction

If you use a virtual environment to make your models, you probably made a choice of product between Microsoft, Vmware , Virtualbox, or another…

You probably also know that since Windows 8, Edition PRO and higher, Microsoft offers a variation of Hyper-V for client computers (included in the Windows PRO and Enterprise license).

Usually, as a trainer systems and networks, I tend to advocate Virtualbox, less ‘silo’, free and therefore more accessible to neophytes. If you have a few dollars to spend, the vmware Workstation solution is an excellent investment (as long as you are not resistant to the language of Shakespeare)

in fact, historically Hyper-V is a hypervisor ‘comparable’ to the famous Vmware ESX for which you must ensure yourself, the service networks or other functions copy and paste between virtual machines and the “rest of the world.”

Well, now that I wanted to share with you is a new ability appeared on Windows 10 ≥ 1511-1607, certainly via Powershell, whose Hyper-V can take full advantage. This is to declare a network virtual type “NAT”, intended to offer “Internet” access to your expensive VMS to be isolated, without connecting them directly to an external network, or share the connection.

w10-hv-nat01

ICS

II. Implementation and configuration of the NAT

some operations could be performed via the GUI, but let’s make the essential command-line:-D. So in the first place, open a Powershell console mode Administrator

A. creating a new Hyper-V virtual switch

enter the following command:

 New-VMSwitch - Name "NAT - VM" - SwitchType NAT - NATSubnetAddress 192.168.10.0/24

Si you open the Hyper-V management console at the same time, you will see the emergence of a new type virtual switch “ internal”

w10-hv-nat02

switch virtual Hyper-V : Type ‘Internal’

reminder, this type of connection “ internal network” allows to connect the host (physical machine) to virtual machines that are connected.

[

(B) activating the feature of NAT gateway

now enter this famous ‘magical’ next command:

 New-NetNat - Name NAT - VM - InternalIPInterfaceAddressPrefix 192.168.10.0/24

w10-hv-nat03a

If you look on the side of the network configuration, you will see interface “ vEthernet (NAT – VM) ‘ now for an IP (the first of the specified addressing scheme)

w10-hv-nat04a

optional : To change the address of the NAT gateway, it is possible to use the following command:

 New-NetIPAddress - IPAddress 192.168.10.1 - PrefixLength 24 - InterfaceAlias "vEthernet (NAT - VM)" 

this information is visible and editable in the properties of the corresponding interface to the virtual switch we just declare

w10-hv-nat05a

C. Configuration of virtual machines

w10-hv-nat06a

assignment of a NAT network to a new machine virtual

w10-hv-nat07b

Configuration IP of a virtual machine

at this stage, your NAT router is ready, but it lacks a DHCP service. Which requires you to manually configure your virtual machines by stipulating an IP 192.168.10.x / 255.255.255.0 and default gateway on each 192.168.10.1

make sure that Internet accessibility is available.

alternative: Installation of a DHCP on Windows 10 service

Microsoft offers no solution for its customers but you versions can opt for the following small application:

http://www.dhcpserver.de/cms/download/

the installation of this program is relatively simple. To do this, simply download archive and unlock the .zip file:

w10-hv-nat08

release of ADS

then do an extraction of the contents to a folder any such as “ C:OutilsDHCP-Server

w10-hv-nat09

content of archive

run the configuration wizard “ dhcpwiz.exe ‘ then click on ‘ according to

w10-hv-nat10

different network interfaces are then displayed. The column ‘ DHCP “indicates the networks on which the automatic configuration via DHCP is already active.

w10-hv-nat11

Select the corresponding interface to your previously configured NAT router and then click on “ next “. ”

As mentioned, be careful not to select an interface on which a DHCP service would already be active (Enabled) at the risk of disrupting a production infrastructure.

this program provides a basic DHCP service, but can also support the functions of web server, TFTP and DNS redirector.

w10-hv-nat12

Initially, we will not activate these features (you can return to it later on). Click on “ in “. ”

However, if you have a virtual domain controller, you can already enter its IP address in the DNS of this interface field or later state this at the level of DHCP options.

The next screen is one of the most important for the topic that interests us. Namely, the configuration of the address range and this DHCP service options.

w10-hv-nat13

At a minimum, you need to define / confirm the desired range under “ IP-Pool “. ” The other settings and DHCP options are intended for specialists.

To set the main options, click on the button “ Advanced…”. “

w10-hv-nat14

minimum, enter the address of the default gateway (Option ‘ 03 / Router ‘) stipulating the leg of your NAT router” 192.168.10.1 “, then click on” OK

you can then validate these settings which will be entered in a text along .ini file.” (Easily changed afterwards).

w10-hv-nat15

Possibly check the values, click on ‘ Write INI file ‘ then click on ‘ according to “.”

Click on the button “ Admin ” in order to elevate privileges for the execution of the DHCP service during this phase of Setup.

w10-hv-nat16

Click on “ Install ‘ (to install this program as a permanent service)

w10-hv-nat17

then click on” Start

w10-hv-nat18

the status of the service” Status “must mention” Running

then click on the button ‘ Configure ‘ area ‘ Firewall exceptions “.»»
w10-hv-nat19

The status of the firewall “ Status ” must mention “ Configured “. ”

For the curious, you can open the advanced firewall Manager (wf.msc) and see that this action generates rules on the program dchpsrv.exe 6/TCP and UDP/17 on each profile, either 6 new rules altogether.

w10-hv-nat20

Click on “ Exit” to return to the wizard.

Click on ‘ complete w10-hv-nat21

click on ‘ Exit

w10-hv-nat22

this tool works as a Windows service and you can act on needed .ini configuration file. ” However, for better ease of use, you can store a control icon in the notification area.

w10-hv-nat23

You can now take advantage of DHCP in your virtual environment and test its operation. If your host for in Internet access, the VMs should be able to benefit also.

w10-hv-nat24a

D. Configuration (optional) the NAT rules

you probably know that by default, a NAT router is a “bulwark” against the incoming connections. To access a service, such as a Web server, located on the side ‘Private’, (in this case, a virtual machine), it is necessary to “publish” an external port.

For this, we will again use Powershell. Just imagine that a Web server is installed on our machine “192.168.10.10”, simply enter the following command:

 Add-NetNatStaticMapping - NatName "NAT - VM" - Protocol TCP - ExternalIPAddress 0.0.0.0 - 192.168.10.10 - 80 - ExternalPort 80 InternalPort InternalIPAddress 

Notes:

  • 0.0.0.0 – indicates that all external addresses are allowed to borrow this port.
  • The internal and external port, 80, may be different.

You can set up as many rules as you like but remember to also enable firewall on virtual machines concerned 🙂 incoming rules.

and here, a nice prototyping environment offered to you

good luck to all.

Christophe