Quick Tip: Run Hyper-V Inside of A Virtual Machine

You may find yourself needing to simulate a small network or create a lab environment to run tests in. One way to do this is to run Hyper-V inside of an existing virtual machine. In this quick tip I’ll show you how to enable the features required to do so.

In order to run Hyper-V inside of an existing VM you must enable Nested Virtualization. Inside of your physical host fire up an elevated PowerShell session. Make sure the virtual machine is powered off and run the following cmdlet:

Set-VMProcessor -VMName -ExposeVirtualizationExtensions $true

In order to set up networking you must configure the settings to either spoof the the MAC address that is attached to your VM’s virtual switch or use NAT. Run the following command on the first level virtual machine to turn on MAC address spoofing

Get-VMNetworkAdapter -VMName | Set-VMNetworkAdapter -MacAddressSpoofing On

Alternatively, you can configure the VMs to communicate using NAT (Network Address Translation). This method should only be used if it’s not possible to spoof your MAC address.

First we create a vSwitch on the first level VM (the “middle” vm).
New-VMSwitch -Name VmNAT -SwitchType Internal

New-NetNat –Name LocalNAT –InternalIPInterfaceAddressPrefix “”

Next give your network adapter an IP address
Get-NetAdapter "vEthernet (VmNat)" | New-NetIPAddress -IPAddress -AddressFamily IPv4 -PrefixLength 24

Now we need to assign each VM an IP address and a gateway. The net adapter we created in the last step should be used for our gateway. We also assign a DNS server using netsh.

Get-NetAdapter "Ethernet" | New-NetIPAddress -IPAddress -DefaultGateway -AddressFamily IPv4 -PrefixLength 24

Netsh interface ip add dnsserver “Ethernet” address=YourDNSserver


Note: Keep in mind when you enable Nested Virtualization your first and second level VMs will not be able to use the Dynamic Memory feature.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: