How to setup an isolated Hyper-V lab with internet access
Published June 03, 2023 by Danny Moran
Table of Contents
Introduction
Learn how to setup Hyper-V so that you can use it to create a test lab environment. In this example, I show you how to setup pfSense and virtual switches so that the lab virtual machines can only communicate with other test lab virtual machines but also still reach the internet.
Video
Prerequisites
- Windows 11 or Windows 10 operating system (Professional, Enterprise, or Education Edition)
- pfSense Virtual Firewall Installation ISO - Download link
- Windows Server 2022 Installation ISO - Download link
Installing Hyper-V
PowerShell
The easiest way to install Hyper-V is by using PowerShell. Open PowerShell and run the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
GUI
If you don’t want to use PowerShell to install Hyper-V, you can install it using the Windows GUI by following the below steps:
Open the start menu and type
optionalfeatures
and press Enter.Tick the box for Hyper-V and then press OK.
Hyper-V Manager
All of the below configuration will be done in the Hyper-V Manager. This application will be automatically installed when enabling Hyper-V in the above steps. To open it, open that start menu and locate Hyper-V Manager
.
Virtual Switch Configuration
We will need to create two virtual network switches that will be used within the lab. An External switch that will be connected to the gateway virtual machine enabling the lab to have internet access, and a Private switch that will be connected to the gateway virtual machine as well as all other virtual machines in the lab enabling communication between the virtual machines.
External Virtual Network Switch
Open Hyper-V Manager and press Virtual Switch Manager in the left hand pane
Select New Virtual Network Switch
Select External and then press Create Virtual Switch
Name the switch
lab-switch-wan
Under connection type, select External Network and then select the correct network adapter that is used to connect the host workstation to the network
Press Apply to finish creating the External network switch.
Private Virtual Network Switch
Open Hyper-V Manager and press Virtual Switch Manager in the left hand pane
Select New Virtual Network Switch
Select Private and then press Create Virtual Switch
Name the switch
lab-switch-lan
Under connection type, select Private Network
Press Apply to finish creating the External network switch.
Virtual Machine Configuration
Installing the Gateway (pfSense)
Now the virtual network switches have been created, we can start to setup the virtual machines. The first virtual machine we need to setup is the gateway appliance. In this guide we are going to use pfSense, but other router and firewall combo appliances will work fine if you know how to set them up.
Open Hyper-V Manager and press New in the left hand pane and then select Virtual Machine
Select Next on the Before You Begin wizard page
Give the virtual machine a name of
FW01
and press NextSelect Generation 1 and press Next
Enter
1024
for the Startup Memory, and unselect Use Dynamic Memory and then press NextFor the networking, select
lab-switch-wan
and then press NextChange the size of the virtual hard disk to
20
GB and press NextSelect Install an operating system from a bootable CD/DVD-ROM and then press Browse
Locate and select the pfSense iso file that you previously downloaded and then press Next
Press Finish to create the virtual machine
Right-click the virtual machine and press Settings
Under Processor, change the Number of Virtual Processors to
1
Under Checkpoints, unselect Use Automatic Checkpoints and press Apply and then OK
Double-click the virtual machine and then press Start to start the virtual machine
The virtual machine should automatically boot into the pfSense installation media
After the virtual machine has launched into the install media for pfSense, select Enter to accept the Copyright and Distribution notice
Select Enter on Install (Install pfSense)
Scroll down and select the correct keyboard layout and then press Enter and then press the UP arrow and then Enter on the Continue with selected keymap
Press Enter on Auto (ZFS)
Press Enter on Install
Press Enter on Stripe (Stripe - No Redundancy)
Press Space to select the virtual disk, and then press Enter
Press the Left arrow to highlight Yes, and then press Enter to confirm the virtual disk will be reformatted
The install will now start
After the install has finished, press Enter on No to any manual configuration modifications
Press Enter to reboot the virtual machine
Close the virtual machine connection window
Right-click the virtual machine and press Settings
Under IDE Controller 1, DVD Drive, change Media from Image File to None, and then press Apply and then OK
Right-click the virtual machine and press Reset
Double-click the virtual machine to open the connection window
It should automatically start the boot from the virtual drive and start the second configuration stage
When it asks to configure VLANs, press
N
and then EnterEnter the name of the interface you want to use for the WAN connection, it should be
hn0
and the press EnterPress Enter to skip the LAN interface assignment
Press
Y
and then Enter to confirm interface assignmentsClose the virtual machine connection window
Right-click the virtual machine and press Shutdown and then wait for the virtual machine to shutdown
Right-click the virtual machine and press Settings
Select Add Hardware, then select Network Adapter, and then press Add
Under Virtual Switch, select
lab-switch-lan
and press Apply and then OKDouble-click the virtual machine and then press Start to start the virtual machine
When the virtual machine has booted, select Assign Interfaces by pressing
1
and then EnterPress
N
and then Enter to not setup VLANsFor the WAN interface name, enter
hn0
and press EnterFor the LAN interface name, enter
hn1
and press EnterCheck assignment and then press
Y
and then press Enter to proceedNow we need to set the LAN interface IP address by pressing
2
and then Enter to enter into the IP assignment wizardPress
2
and then Enter to configure the hn1 interfaceEnter the IP address you want to set for the gateway (example:
10.0.0.254
) and then press EnterEnter the subnet mask bit count (example:
24
) and then press EnterPress Enter to skip the upstream gateway address
Press Enter to skip the IPv6 IP address assignment
Press
N
and then Enter to bypass the DHCP setupThis guide assumes you are going to setup DHCP on one of the Windows servers within the lab environment. If you are not going that, you can follow the DHCP setup wizard by pressing
Y
and then Enter.Press
Y
and then Enter to revert the HTTP webConfigurator protocolOnce the config has been applied, press Enter to continue
You can now close the virtual machine connection window as no further configuration needs to be done on the pfSense gateway.
Installing the Virtual Lab Servers
You can now start creating the servers that for your virtual lab. The only thing you need to make sure you do is when you are creating the virtual machine, when it asks what networking connection to use, make sure you select lab-switch-lan
.