Note: This post was originally written on July 18, 2017, and updated on November 23, 2026, to replace Sophos XG with OPNsense and cover modern Hyper-V and Proxmox lab setups.
I test a lot of things in my lab, and plenty of those projects need their own subnet and DHCP server. Spinning up an Active Directory domain is the classic example. If you drop a new domain controller with DHCP enabled straight onto your home network, it will start handing out IP addresses to your TV, your phone, and everything else in the house. That is a fast way to make everyone in your home mad at you.
To keep your lab from breaking your home network while still giving your virtual machines (VMs) internet access, you need to put your lab behind a virtual router. I am walking through this using Hyper-V, though the exact same two-switch design works in Proxmox (vmbr0 for WAN and a second bridge for your lab) or VMware.
Prerequisites
Before you build the virtual router, make sure you have:
- A hypervisor host (Windows 11 Pro / Windows Server with Hyper-V enabled, or Proxmox).
- The OPNsense installer ISO downloaded and extracted (pfSense works the same way if you prefer it).
- At least two virtual CPUs and 2 GB of RAM available for the router VM.
Creating the Virtual Switches
- Open Hyper-V Manager and click Virtual Switch Manager in the right-hand Actions pane.
- Select New virtual network switch, choose Private, and click Create Virtual Switch. Name it something obvious like Lab-LAN. Any VM connected to this switch can talk to other VMs on the same switch, and nothing on your physical home network can see it.
- If you do not already have an External virtual switch bound to your host’s physical network adapter, create one now and name it External-WAN. This will act as the WAN side of your virtual router.
Warning: Double-check which switch you attach to your test VMs later. Never attach a lab VM running DHCP or experimental services to External-WAN, or it will broadcast directly onto your home network.
Choosing Your Segmentation Approach
There are a few ways to isolate a lab, and the right one depends on your hardware.
| Approach | Hardware Needed | Best For |
|---|---|---|
| Private Switch + Virtual Router | Any single-NIC host | Full firewall control, multiple lab subnets, and zero physical switch config. |
| Hyper-V Default Switch (NAT) | Windows 10/11 host | Quick one-off VMs that just need internet without custom routing or firewall rules. |
| Physical VLANs | Managed switch + VLAN-aware router | Multi-host labs where VMs on different physical servers share isolated subnets. |
Building the Router VM
- In Hyper-V Manager, create a new Generation 2 VM (or Generation 1 if your firewall image requires legacy BIOS) and assign it two vCPUs, 2 GB to 4 GB of static RAM, and a 20 GB virtual hard disk. Disable Dynamic Memory for the router VM, because firewall appliances do not handle memory ballooning well.
- During the wizard, connect the initial network adapter to External-WAN (or Lab-LAN, just keep track of which one you add first).
- Open the VM’s Settings > Security and uncheck Enable Secure Boot if you are booting a FreeBSD-based appliance like OPNsense.
- Go to Settings > Add Hardware, add a second Network Adapter, and connect it to Lab-LAN.
- Under Automatic Start Action, set the VM to Always start this virtual machine automatically so your lab network comes up whenever the host reboots.
- Mount the OPNsense ISO under the DVD drive, boot the VM, and run through the installer to write it to the virtual disk.
Configuring OPNsense
- When OPNsense boots to the console menu, log in as installer (or root once installed) and check the interface assignments. If your WAN and LAN interfaces are swapped, choose option 1 (Assign Interfaces) and map the MAC address connected to External-WAN as WAN and Lab-LAN as LAN.
- Choose option 2 (Set interface IP address) to give the LAN interface a static subnet that does not collide with your home network (for example, 10.10.50.1/24) and enable the DHCP server on that interface.
- Spin up a small Windows or Linux management VM connected only to Lab-LAN. It should pull an IP in 10.10.50.x from OPNsense.
- Open a browser on that management VM and go to https://10.10.50.1 to finish the OPNsense web wizard.
Gotcha: By default, OPNsense blocks private IP ranges (RFC 1918) on the WAN interface. Since your virtual router’s WAN sits behind your home router on a private subnet like 192.168.1.x, that is fine for outbound lab traffic, but uncheck Block private networks under Interfaces > WAN if you ever need to reach the virtual firewall from your home LAN.
The Payoff
You now have a dedicated, business-grade virtual router sitting in front of your lab. Any VM you attach to Lab-LAN gets internet access through NAT, while your Active Directory domain, DHCP, and DNS experiments stay completely walled off from your home network. If you need another isolated subnet later, you just add one more Private virtual switch and attach a new NIC to the OPNsense VM.