Networking Room — home

Home / Field Guides / OPNsense VLAN setup on 26.7: trunk, interfaces, DHCP and gue...

Field guide · OPNsense

OPNsense VLAN setup on 26.7: trunk, interfaces, DHCP and guest isolation

A screen-by-screen OPNsense VLAN setup for the 26.7 series: VLAN devices, the new Assignments page, Dnsmasq DHCP ranges, a clean switch trunk, and the firewall rules that keep guest and IoT networks away from your LAN.

Illustration: a fanless mini PC firewall cabled with teal patch leads to a managed network switch on a home-lab shelf
Illustration: a fanless mini PC firewall cabled with teal patch leads to a managed network switch on a home-lab shelf

OPNsense VLAN setup at a glance

Steps
8, one per screen (two of them on the switch)
Time needed
About 30 to 45 minutes, plus however long your switch's menus take
Written for
OPNsense 26.7.6 or later, with the new Assignments page and Firewall ‣ Rules
Where VLANs are created
Interfaces ‣ Devices ‣ VLAN
Where DHCP is set
Services ‣ Dnsmasq DNS & DHCP
Example networks
VLAN 20 IOT on 192.168.20.1/24, VLAN 30 GUEST on 192.168.30.1/24
Hardware you must have
A managed switch with 802.1Q VLAN support; an unmanaged switch cannot do this

This OPNsense VLAN setup takes a working firewall with one ordinary LAN and adds two separate networks to it: one for smart-home and IoT gadgets, one for guests. Both travel over a single trunk cable to a managed switch, both get addresses from OPNsense, and firewall rules stop either of them reaching your main LAN or the firewall's own login page.

The guide is compiled from the official OPNsense documentation (the VLAN and LAGG how-to, the Devices, Interfaces, Dnsmasq and Rules manual pages, and the 26.7 release notes), cross-checked against the Thomas-Krenn wiki. We did not run it on a bench of our own. If you are still choosing hardware, our list of mini PCs for OPNsense and pfSense covers boxes with enough ports for the layout used here.

What you need before you start

  • A managed switch. It must let you create 802.1Q VLANs and choose, per port, which VLANs are tagged and which one is untagged. Unmanaged switches pass tags through blindly or drop them.
  • A spare port on the firewall. The cleanest layout uses one port that carries only tagged VLANs. In this guide it is igc2; Interfaces ‣ Assignments shows which devices are already in use. Your names may be igb, em, re or vtnet.
  • A VLAN and subnet plan. Write down each VLAN ID (1 to 4094), its name and its subnet before you touch anything. Putting the VLAN ID in the third octet, as the OPNsense docs suggest, makes the plan readable at a glance: VLAN 20 is 192.168.20.0/24.
  • A way back in. Keep a monitor and keyboard (or the serial console) handy, and do not change the port you are currently managing OPNsense through.
  • A fresh configuration backup. Download one from System ‣ Configuration ‣ Backups before step 1. Restoring it is the fastest undo.
  • A VLAN-aware access point, if guests use Wi-Fi. It must be able to put one SSID on a tagged VLAN. Most business and prosumer access points can; many ISP-supplied routers cannot.

The decision that blocks most people: where does the untagged LAN go?

A VLAN-tagged frame carries a small label saying which network it belongs to. An untagged frame carries none, so the switch drops it into the port's default VLAN. The OPNsense documentation is blunt about the link between the firewall and the switch: do not mix tagged and untagged VLANs on that trunk. Depending on the switch, router advertisements, DHCP and other broadcasts can leak between the tagged networks and the untagged one.

Think of the trunk as a building's service lift that only accepts labelled boxes. Unlabelled boxes end up on whichever floor the lift happens to stop at. So decide first where your existing, untagged LAN lives. There are three common answers.

Three ways to connect OPNsense to a managed switch, judged against the OPNsense VLAN how-to
Layout Cables to the switch Matches the docs? Best for
A. LAN on its own port, VLANs on a dedicated trunk port 2 Yes: the trunk carries tagged frames only Boxes with 3 or more ports; used in this guide
B. LAN moved into a VLAN as well, one trunk for everything 1 Yes: this is the docs' own example Fresh installs, or once you have console access
C. Untagged LAN and tagged VLANs on the same port 1 No: the docs advise against it Often works, but leaks depend on the switch
ISP ONU OPNsense Managed switch IoT: VLAN 20 AP: LAN + VLAN 30 LAN PC
Layout A: two cables between the firewall and the switch, igc1 for the untagged LAN and igc2 as a trunk with VLANs 20 and 30 tagged. They are on different VLANs, so they do not form a loop. The access point puts its guest SSID on VLAN 30.

OPNsense VLAN setup, step by step

The example values below assume layout A: igc2 is the unassigned trunk port, VLAN 20 becomes IOT and VLAN 30 becomes GUEST. Swap in your own port name, IDs and subnets. Steps 3 and 4 happen on the switch, whose menus differ by brand, so they describe what to set rather than where to click.

01

Create the VLAN devices (Interfaces ‣ Devices ‣ VLAN)

Add a new entry. Device: vlan0.20 (VLAN devices are named vlan, or qinq for stacked tags). Parent interface: igc2. VLAN tag: 20. Leave VLAN priority empty unless you use priority tagging. Description: something you will recognise later, such as igc2_vlan20_IOT. Save, then add a second entry for tag 30, and apply. Common mistake: choosing a parent that is already assigned as LAN. In layouts A and B the docs say the parent interface should stay unassigned.

02

Assign each VLAN as an interface (Interfaces ‣ Assignments)

Use the add button, pick vlan0.20 as the Device and give it the Description IOT. In the same dialog tick Enabled, set IPv4 Configuration Type to Static IPv4 and enter 192.168.20.1/24 as the IPv4 address. Leave IPv6 Configuration Type on None for now. Save, then repeat for vlan0.30 as GUEST with 192.168.30.1/24. Finally press Apply on the Assignments page. Common mistakes: typing the address without the /24, and forgetting Apply. Saved but unapplied changes are discarded if the firewall reboots.

03

Make the switch port a clean trunk

In the switch's VLAN page, create VLANs 20 and 30 with the same IDs. On the port cabled to igc2, add VLANs 20 and 30 as tagged members and remove every untagged or native VLAN from it. If the switch will not let a port have no untagged VLAN, the docs suggest a sacrificial one: set the native VLAN to an unused ID such as 3999 and use that ID nowhere else. Common mistake: leaving the switch's default VLAN 1 untagged on the trunk.

04

Set the access ports and the access point port

A device that knows nothing about VLANs, such as a smart plug hub or a TV, goes on an access port: untagged member of VLAN 20 only. On switches that show a separate PVID (port VLAN ID) setting, set it to 20 as well, otherwise untagged frames arriving on that port still land in VLAN 1. The access point's port carries its management network untagged (your LAN here) and VLAN 30 tagged. Then, in the access point's own settings, map the guest SSID to VLAN 30.

05

Let Dnsmasq serve the new interfaces (Services ‣ Dnsmasq DNS & DHCP ‣ General)

In the Interface field, add IOT and GUEST next to LAN; do not replace LAN, or the main network stops getting leases. Make sure DHCP register firewall rules is ticked so OPNsense creates the rules that let DHCP requests in on those interfaces. Press Apply. Common mistake: a leftover ISC DHCP or Kea DHCP service still running. The Dnsmasq docs warn that either one blocks the ports Dnsmasq needs.

06

Add a DHCP range per VLAN (Services ‣ Dnsmasq DNS & DHCP ‣ DHCP ranges)

Add a range with Interface IOT, Start address 192.168.20.100 and End address 192.168.20.199. Save, add a second range for GUEST from 192.168.30.100 to 192.168.30.199, then Save and Apply. You do not need to enter a gateway or DNS server: a range automatically hands out the interface's own address as both. Common mistake: a range outside the interface's subnet, for example 192.168.2.x on an interface set to 192.168.20.1/24.

07

Write the GUEST rules (Firewall ‣ Rules, GUEST selected)

A new interface blocks everything inbound until you add rules, and with the default quick setting the first matching rule wins, so order matters. Add the five rules in the table below, top to bottom, with Direction left on in and Version IPv4. Save each, then press Apply. Common mistake: putting the allow-any rule above the block rules, which lets guests reach your LAN.

08

Write the IOT rules the same way

Copy the GUEST pattern to IOT: allow DNS to This Firewall, block This Firewall, block LAN net, block GUEST net, then pass IOT net to any. You do not need a rule for your PC to reach the IoT devices: the standard LAN rule already allows LAN to any destination, and because rules are stateful the replies come back without an extra rule on IOT.

Firewall rules for the guest VLAN, in order

GUEST interface rules, evaluated top to bottom; the IOT interface uses the same pattern with its own net
# Action Protocol Source Destination Port Why
1 Pass TCP/UDP GUEST net This Firewall 53 (DNS) Name lookups through Unbound
2 Block any GUEST net This Firewall any Keeps guests off the web GUI
3 Block any GUEST net LAN net any Main network stays private
4 Block any GUEST net IOT net any Guests cannot see your gadgets
5 Pass any GUEST net any any Everything else, which means the internet

DHCP still works with rule 2 in place because the rules created by DHCP register firewall rules are automatic rules, and the docs note that automatic rules are usually registered before yours. The same five-rule pattern is the one the official OPNsense guest-network how-to uses, with a DNS rule added because this setup has no captive portal to open DNS for you.

How to check it worked

  1. Address. Plug a laptop into a VLAN 20 access port. It should get an address between 192.168.20.100 and .199, with 192.168.20.1 as gateway and DNS server.
  2. Lease. The laptop should appear in the Dnsmasq leases view under Services ‣ Dnsmasq DNS & DHCP.
  3. Internet and DNS. Run the commands below. Pinging a public address and resolving a name should both work.
  4. Isolation. Pinging your LAN gateway (192.168.1.1 in a default install) or opening the OPNsense login page from the IOT or GUEST network should fail. That failure is the point. On GUEST and IOT, even a ping to the network's own gateway fails, because rule 2 blocks everything to This Firewall except DNS.
  5. The other direction. From a LAN PC, ping a device on 192.168.20.x. It should answer, because LAN is allowed to start connections into IOT.
Windows 10/11 Command Prompt (macOS and Linux: ipconfig getifaddr en0 or ip addr instead of ipconfig) On a client in VLAN 20 or VLAN 30
ipconfig /all
:: expect 192.168.20.1xx (or 192.168.30.1xx), Default Gateway 192.168.20.1

nslookup example.com 192.168.20.1
:: expect an answer: rule 1 lets DNS through

ping 1.1.1.1
:: expect replies: the allow-any rule covers the internet

ping 192.168.1.1
:: expect timeouts: LAN net is blocked

tracert -d 1.1.1.1
:: the first hop should be the VLAN's gateway address

Settings to change after setup

  • Take a new backup. Download another configuration file from System ‣ Configuration ‣ Backups now that the VLANs work.
  • Check Unbound's interfaces. The docs say Unbound adds access-list entries for configured interfaces automatically. If you ever narrowed Network Interfaces under Services ‣ Unbound DNS ‣ General, add IOT and GUEST there too.
  • Turn on client isolation for guests. The OPNsense guest-network how-to recommends layer 2 isolation on the access point (or port isolation on the switch), because devices in the same VLAN talk directly and never pass through the firewall.
  • Plan IPv6 before you enable it. Leave the new interfaces on None until IPv4 works. When you add IPv6, make sure the block rules cover IPv4 and IPv6, or guests may reach the LAN over the protocol you did not filter.
  • Expect casting and discovery to stop across VLANs. Chromecast, AirPlay and printer discovery rely on multicast that does not cross a router. Keep phones and the TV on the same VLAN, or add an mDNS repeater and matching rules.

Troubleshooting: symptom and fix

The VLAN device is missing from the Assignments list

Go back to Interfaces ‣ Devices ‣ VLAN and make sure the entry was saved and applied. A device can only be assigned once, so if vlan0.20 is already attached to another interface it will not be offered again. Also check that the parent port is the one you meant; a typo in the parent creates a VLAN on the wrong NIC.

Clients on the VLAN get a 169.254.x.x address

No DHCP answer reached them. Work from the cable outwards: is the switch port an untagged member of the right VLAN, with a matching PVID? Is the trunk port tagged for that VLAN? Is the interface selected in the Dnsmasq Interface field, and does it have a DHCP range? If Dnsmasq will not start at all, check that ISC DHCP or Kea is not still running and read Services ‣ Dnsmasq DNS & DHCP ‣ Log.

Clients get an address but no internet

A new interface blocks everything inbound until a rule allows it, so the usual cause is a missing or disabled pass rule at the bottom of the list. If pinging 1.1.1.1 works but websites do not load, the DNS rule (rule 1) is missing or sits below the This Firewall block rule.

Guests can still reach the LAN

Look at the order: the allow-any rule must be last. Then clear old connections, because existing states can keep a connection alive after you add a block rule. The docs point to Firewall ‣ Diagnostics ‣ States for resetting them.

DHCP or IPv6 addresses from the wrong network appear

This is the leak the OPNsense how-to warns about when tagged and untagged traffic share a trunk. Remove the native VLAN from the trunk port, or move it to an unused blackhole ID, and make sure the trunk's parent interface on OPNsense is not also assigned as LAN.

FAQ

Do I need a managed switch for an OPNsense VLAN setup?

Yes. The switch has to know which ports carry which VLAN and has to add or remove tags. The OPNsense docs say unmanaged switches only provide basic functionality and do not support the VLAN features this setup needs.

Can I put the VLANs on my existing LAN port?

You can, and many home setups do, but that mixes untagged LAN traffic with tagged VLANs on one trunk, which the OPNsense documentation advises against. Use a spare port (layout A) or move the LAN into its own VLAN as well (layout B) if your hardware allows it.

Does the parent interface need its own IP address?

No. The VLAN how-to says the parent interface should stay unassigned. Only the VLAN interfaces get addresses. In rare cases the parent is assigned without any network configuration, purely to override link speed.

Should I use Dnsmasq or Kea for DHCP on the VLANs?

The OPNsense docs recommend Dnsmasq for small and medium networks of under about 1,000 clients, and the setup wizard already uses it for DHCP. Kea suits larger or high-availability setups that need lease synchronisation.

The short version

  1. Create VLAN devices under Interfaces ‣ Devices ‣ VLAN on an unassigned parent port, assign them under Interfaces ‣ Assignments with a static /24, and press Apply.
  2. Keep the trunk to the switch tagged-only. Mixing the untagged LAN onto it is the layout the OPNsense docs warn against.
  3. Add each VLAN to Dnsmasq's Interface list and give it a DHCP range; gateway and DNS are handed out automatically.
  4. New interfaces block everything inbound. Allow DNS, block the firewall and your other networks, then allow everything else, in that order.

Sources

Compiled from the following official documentation and one independent reference, read on 3 December 2026. Menu names are quoted from these pages; no bench test was run for this guide.

Need a switch that can carry the trunk? Our guide to 2.5GbE switches for a home lab marks which picks are managed and support VLANs.

MA

Mawdud Ahmed

Runs network operations for a licensed fibre ISP in Khulna, Bangladesh (AS137403) — GPON access, MikroTik edge, BGP upstream. Every review here is tested against that network rather than a lab loop.