Nested virtualization is a feature that allows you to run Hyper-V inside a Hyper-V virtual machine.
In other words, with nested virtualization, a Hyper-V host itself can be virtualized.
- A Hyper-V host running Windows Server 2016 or Windows 10 Anniversary Update.
- A Hyper-V VM running Windows Server 2016 or Windows 10 Anniversary Update.
- A Hyper-V VM with configuration version 8.0 or greater.
- An Intel processor with VT-x and EPT technology.
Configure Nested Virtualization
- Create a virtual machine. See the prerequisites above for the required OS and VM versions.
We used Windows 2016 OS.
2. While the virtual machine is in the OFF state, run the following command on the physical HyperV host. This enables nested virtualization for the virtual machine.
Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true
Start virtual machine.
Disable Nested Virtualization
You can disable nested virtualization for a stopped virtual machine using the following PowerShell command:
Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $false
Install Hyper-V role and features in virtual machine.
Open PowerShell and run below command:
Install-WindowsFeature Hyper-v –IncludeManagementTools
After reboot, you can use HyperV manager for creating and managing a virtual machine.
Create a new virtual machine under your nestedvm.
Now you can use new VM2.
There are two options for networking with nested virtual machines: MAC address spoofing and NAT mode.
MAC Address Spoofing
For routing network packets through two virtual switches, MAC address spoofing needs to enabled on the virtual switch’s first level. This is done through the following PowerShell command:
Get-VMNetworkAdapter -VMName <VMName> | Set-VMNetworkAdapter -MacAddressSpoofing On
Network Address Translation
The second option is via network address translation (NAT). This approach is ideal for cases where MAC address spoofing cannot be done, like in a public cloud environment.
First, a virtual NAT switch must be created in the host virtual machine (the “middle” VM). Note that the IP addresses below are taken for the purpose of an example, and will vary across environments:
New-VMSwitch -Name VmNAT -SwitchType Internal
New-NetNat –Name LocalNAT –InternalIPInterfaceAddressPrefix “192.168.1.0/24”
Next, assign an IP address to the net adapter:
Get-NetAdapter “vEthernet (VmNat)” | New-NetIPAddress -IPAddress 192.168.1.1 -AddressFamily IPv4 -PrefixLength 24
Each nested virtual machine must have an IP address and gateway assigned to it. Note that the gateway IP must point to the NAT adapter from the previous step. You may also want to assign a DNS server:
Get-NetAdapter “Ethernet” | New-NetIPAddress -IPAddress 192.168.1.2 -DefaultGateway 192.168.1.1 -AddressFamily IPv4 -PrefixLength 24
Netsh interface ip add dnsserver “Ethernet” address=<my DNS server>
That’s all for now!
Hyper-V powers a lot of cloud and VPS services. Like, ZNetLive leverages it in Cloud Windows VPS and Microsoft Azure Private Cloud.
In case you have any query regarding nested virtualization, you can get in touch with me via comments section. I will be happy to help.
Services ZNetLive offer:
Umesh, Team Lead – Technical, is a Microsoft products’ expert with enviable certifications like RHCE, MCPS, MCSA and MCSE. An excellent team player, he utilizes his expertise of over 7 years in the technical sphere to handle technical issues brilliantly and dedicatedly value adds to the system administration and management fields. He can be seen drawing or playing chess in free time.