Building a lab environment to simulate certain scenarios or get hands-on experience with technology can be really useful.
Years ago we used to invest in physical lab environments for home use, but these days you can use Azure as that lab environment. And with nested virtualization capabilities building a Hyper-V lab is feasible.
Below I walk you through the process of setting up the networking within your Azure virtual machine for that nested virtualisation scenario.
- Windows Server 2022 build 20348 or later
- Enabled Hyper-V Role
Setup Hyper-V NAT Switch
The first step is to create a new Hyper-V virtual switch. The virtual switch allows virtual machines created on Hyper-V hosts to communicate with other computers. The following PowerShell command will create the virtual switch.
New-VMSwitch –SwitchName “NATSwitch” –SwitchType Internal
Now we have the virtual switch set up we need to configure the virtual network adapter. The virtual network adapter enables communications between virtual machines through the virtual switch. The following PowerShell command will set up the virtual network adapter.
New-NetIPAddress –IPAddress 192.168.0.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"
The next step is to create the Network Address Translation (NAT) on our switch. The NAT translates an internal network address to an external network address. Allowing the networking inside our Hyper-V setup to communicate with the external world. We use the following PowerShell command to create the NAT:
New-NetNat –Name NATNetwork –InternalIPInterfaceAddressPrefix 192.168.0.0/24
Configure virtual machines
Now that you have the networking set up with your host machine you can configure the networking inside your virtual machines.
You can set your virtual machines with an address in the range 192.168.0.1-192.168.0.254.
Here is an example of what one of my virtual machines IP configuration looks like:
For the DNS servers, depending on what my virtual machines are doing I either use the Google DNS servers or I use the Active Directory DNS server I have set up for the lab.
If you are looking for a “ready made” lab you can deploy within Azure, please do check out my "Deploy a lab inside an Azure VM" blog post.