Set up an isolated lab VLAN in UniFi
A lab network is a place where you can break things without breaking anything else. In UniFi that comes down to three pieces: a virtual network with its own VLAN, switch ports that put machines on it, and a firewall zone that decides what it can reach.
This walk-through uses the UniFi Network application on a UniFi OS gateway with the zone-based firewall, which arrived in Network 9.0. The menu names below are from Network 9.4. Network 9.3 has the zone and DNS pages under Settings → Policy Engine instead. Older versions with the legacy firewall can do the same thing with LAN In rules, but the steps differ.
Plan the addresses first
Pick a VLAN ID and a subnet before opening the controller, and write them down. Matching the third octet to the VLAN ID makes packet captures and firewall logs easier to read at a glance. Future you will be grateful. The values below are examples used through the rest of this post, not a setup you need to copy.
| Setting | Value | Notes |
|---|---|---|
| Name | Lab | Shown in client lists and firewall zones |
| VLAN ID | 40 | Any unused ID from 2 to 4009 |
| Gateway / subnet | 10.40.0.1/24 | 254 usable addresses |
| Static range | 10.40.0.2 – .99 | Lab servers and VMs you SSH to by address |
| DHCP range | 10.40.0.100 – .249 | Short-lived VMs and containers |
| Domain | lab.home.arpa | home.arpa is reserved for this by RFC 8375 |
Create the network
In UniFi Network, go to Settings → Networks → New Virtual Network. Give it the name, set the gateway IP and subnet, and open the advanced settings to set the VLAN ID manually. Leave DHCP mode as DHCP Server and set the range so it doesn't overlap your static block.
Set the domain name in the DHCP options too. Clients then get lab.home.arpa as their search domain, so ssh build1 works without the full name once the gateway has DNS records for your static hosts. In Network 9.4 you add those under Settings → Policy Table → Create New Policy → DNS as Host (A) records.
Isolate Network or a firewall zone?
The network settings also offer Isolate Network (Ubiquiti's docs call it Network Isolation). It's a one-click switch that sets up firewall rules to block traffic between this network and your other local networks. That includes the traffic you actually want from your laptop, and there's nothing to adjust. It's a blunt instrument.
A firewall zone takes a few more minutes but lets you choose exactly what crosses the boundary: your admin machines in, nothing from the lab out, internet and DNS allowed. Leave Isolate Network off and use the zone below.
Put ports on the VLAN
A network exists on the gateway as soon as you save it. Machines join it through switch ports, and there are two kinds you need.
Access ports
For a machine that only ever lives on the lab network, such as a spare mini PC, open the switch in UniFi Devices, select the port in the Port Manager and set its Native VLAN / Network to Lab. Set Tagged VLAN Management to Block All so the port carries nothing else. The machine needs no VLAN configuration of its own.
Trunk ports
A hypervisor is different. Its own management address can stay on your main network while its VMs sit on Lab, so the port keeps your normal native network and carries Lab as a tagged VLAN. Set its Tagged VLAN Management to Custom and allow only Lab, rather than Allow All, so a VM can't tag its way onto your other VLANs.
On Proxmox that means a VLAN-aware bridge, and each VM's network device gets VLAN tag 40.
auto vmbr0
iface vmbr0 inet static
address 192.168.1.20/24
gateway 192.168.1.1
bridge-ports eno1
bridge-stp off
bridge-fd 0
bridge-vlan-aware yes
bridge-vids 2-4094
The host keeps its address on the main network, so you still reach the Proxmox web interface there. bridge-vids 2-4094 is the default for a VLAN-aware bridge, and is written out here only to make it visible.
Check the tag on every VM. A network device with no VLAN tag sends untagged traffic, and the switch puts that on the port's native network, your main one. It's the easiest way for a lab VM to escape the lab without anything looking wrong.
Keep a way back inDon't move the switch's own management address onto the lab VLAN while you're connected through it. If the firewall rules aren't in place yet you lose the controller's path to the switch, and recovering can mean a factory reset and re-adopting it. Change ports one at a time and check each before moving on.
Give it a firewall zone
The zone-based firewall groups networks into zones and sets policies between each pair of zones. New networks land in the Internal zone, where everything can talk to everything. Open the zone settings (Settings → Zones in Network 9.4), create a custom zone called Lab and move the Lab network into it.
Then set the policies between Lab and the other zones:
- Internal → Lab: allow, from your admin machines. Your laptop can reach lab machines over SSH, their web interfaces and anything else you run there. Set the source to your laptop and anything else you manage the lab from, by device or IP address, rather than the whole zone. Otherwise every phone, TV and smart plug on Internal can wander into the lab too.
- Lab → Internal: block. A misbehaving VM can't go poking around your other devices. Keep return traffic enabled on the Internal → Lab allow policy, so replies to connections you start still get back.
- Lab → External: allow. Lab machines need the internet for package updates and container images.
- Lab → Gateway: allow DNS and DHCP only. Add an allow policy for DNS (port 53) and DHCP (port 67), then a block policy for everything else to the gateway. This stops lab machines from reaching the gateway's own management interface.
A custom zone doesn't inherit the policies of the built-in zones, so check the Lab row and column in the zone matrix for VPN, Hotspot, DMZ and any other custom zones, and add what you need. If you reach the lab over a VPN, that needs its own VPN → Lab allow policy, as in connecting an iPhone app to Proxmox, where the phone reaches the servers over a VPN.
The examples here are IPv4. Each policy has an IP version setting (IPv4, IPv6 or both), so if you turn on IPv6 for Lab, make the block and allow policies cover both, and allow ICMPv6 from Lab to the gateway: IPv6 needs it for neighbour discovery and router advertisements. The simpler choice is to leave IPv6 off on Lab until you've checked.
Check it from both sides
First pick a device on the main network that answers ping, such as a NAS, and ping it from your laptop. A timeout from the lab only proves something if that device normally replies.
Then, from a machine on the lab network, confirm the address, DNS and the blocks. Pinging the gateway won't work, because the policy above only allows DNS and DHCP to it:
# Address from the right range, search domain set
ip -brief addr
cat /etc/resolv.conf
# DNS through the gateway and the internet work
getent hosts deb.debian.org
curl -sI https://deb.debian.org | head -1
# A device on the main network should time out
ping -c 3 -W 2 192.168.1.50
# The gateway's management interface should be blocked too
curl -m 3 -k https://10.40.0.1
Then from your laptop on the main network, SSH to a lab host by name. If that works and the last two checks above fail, the lab is in place. Anything you start on VLAN 40 from now on can only reach the internet and the gateway's DNS and DHCP, so go ahead and break things there. The rest of the network won't notice.
If you use unifi-mcp, a question like "which clients are on the Lab network?" is a quick way to see what has actually landed on the VLAN. There's a write-up of how I built unifi-mcp in the AI section.
Written by Matt Oddie · Markdown version