We practice what we preach

Cookieless analytics, fully managed by ByteRon. No personal data collected, no invasive tracking. Ever.

Privacy Policy →

VLAN Switch Configuration for OPNsense - UniFi and Netgear Setup Guide

Published: at 10:00

TL;DR

Configure UniFi and Netgear managed switches to pass VLAN traffic for your OPNsense network. This guide covers a UniFi 24-port switch as the main distribution switch, Netgear GS108Ev3 for DMZ isolation, and UniFi WiFi APs broadcasting multiple SSIDs across VLANs.

Prerequisites:

  • Completed OPNsense VLAN setup
  • UniFi Network Application installed
  • UniFi 24-port switch and Netgear GS108Ev3 managed switch
  • UniFi WiFi access points (U6 Pro, UAP-AC-Lite, or similar)

What you’ll configure:

  • UniFi switch trunk and access ports for VLANs
  • Netgear GS108 dedicated DMZ switch with VLAN isolation
  • UniFi WiFi APs with multiple SSIDs mapped to VLANs

Introduction

VLANs exist at layer 2, meaning they’re implemented on switches, not just routers. After configuring VLANs on OPNsense, you must configure your network switches to pass VLAN-tagged traffic correctly; otherwise, your VLANs won’t work regardless of how perfectly OPNsense is configured.

This guide complements the OPNsense VLAN setup described in the main configuration guide, covering switch-specific configuration for trunk ports, access ports, WiFi AP VLAN assignments, and DMZ isolation.

ℹ️ Quick Terminology Reference

Trunk Ports: Carry multiple VLANs with tags preserved (802.1Q). Used for switch-to-switch or switch-to-router links.

Access Ports: Carry a single VLAN, stripping tags before delivering to end devices.

Native VLAN/PVID: Untagged traffic on a port is assigned to this VLAN.

  • UniFi/Cisco: “Native VLAN”
  • Netgear: “PVID” (Port VLAN ID)

Vendor-Specific Terminology:

  • UniFi: Trunk = “All” or multiple networks | Access = single network
  • Netgear: Trunk = tagged VLANs | Access = untagged VLAN membership

Network Topology Overview

Our Network Structure

graph TD
    Internet([Internet]) --> ISP[ISP Modem]
    ISP --> WAN[OPNsense igb0 WAN]
    WAN --> OPNsense[OPNsense Firewall]

    OPNsense -->|igb1 Trunk| Port23["UniFi Port 23
    LAN + VLAN40,42,44,46"]
    OPNsense -->|igb2 DMZ Only| Port24["UniFi Port 24
    Native: VLAN999, Tagged: VLAN10"]

    Port23 --> UniFi24[UniFi 24-Port Switch]
    Port24 --> UniFi24

    UniFi24 -->|Port 1
    Native: VL40, Tagged: 42,44,46| U6Pro["U6 Pro AP
    SSIDs: SecWiFi, IoT, Guest, GoatNET"]
    UniFi24 -->|Port 2
    Native: VL40, Tagged: 42,44,46| UALAC["UAP-AC-Lite
    SSIDs: SecWiFi, IoT, Guest, GoatNET"]
    UniFi24 -->|Port 10
    VLAN10| NetgearGS108[Netgear GS108]
    UniFi24 -->|Port 13
    LAN| MainPC[Main PC]
    UniFi24 -->|Port 15
    Trunk| FlexSwitch["USW Flex
    LAN + DMZ trunk"]

    NetgearGS108 -->|Ports 5-8
    VLAN10| DMZServers[DMZ Servers]

    FlexSwitch -->|Ports 2-5| FlexDevices[Extended Network Devices]

    class OPNsense danger
    class UniFi24 primary
    class NetgearGS108,FlexSwitch teal
    class Internet amber

VLAN Traffic Flow Through Switch

graph LR
    subgraph OPNsense
        igb1[igb1<br/>LAN interface]
        igb2[igb2<br/>vlan0.10 only]
    end

    subgraph "UniFi Switch Internal"
        P23[Port 23<br/>Native: LAN<br/>Tagged: 40,42,44,46]
        P24[Port 24<br/>Native: VL999<br/>Tagged: 10]
        Fabric{Switch<br/>Fabric}
        P1[Port 1<br/>Native: VL40<br/>Tagged: 42,44,46]
        P2[Port 2<br/>Native: VL40<br/>Tagged: 42,44,46]
        P10[Port 10<br/>Native: VL10]
        P13[Port 13<br/>Native: LAN<br/>Tagged: Allow All]
        P15[Port 15<br/>Native: LAN<br/>Tagged: Allow All]
    end

    subgraph Devices
        AP1[U6 Pro]
        AP2[UAP-AC-Lite]
        PC[Main PC]
        Netgear[Netgear GS108]
        Flex[USW Flex]
    end

    igb1 -->|Untagged LAN<br/>Tagged VL40,42,44,46| P23
    igb2 -->|Tagged VL10 only| P24
    P23 --> Fabric
    P24 --> Fabric
    Fabric --> P1
    Fabric --> P2
    Fabric --> P10
    Fabric --> P13
    Fabric --> P15
    P1 --> AP1
    P2 --> AP2
    P10 --> Netgear
    P13 --> PC
    P15 --> Flex

    class igb1,igb2 danger
    class Fabric primary

VLAN Traffic Flow:

  • Trunk Ports (23, 24, 1, 2, 13, 15): Carry multiple VLANs with tags preserved
  • Access Port (10): Carries only DMZ_VL10 untagged

VLAN Assignment Summary

VLAN IDNetwork NamePurposeSubnetPhysical Location
DefaultLANTrusted wired devices10.0.0.0/24Port 13 (Main PC), Port 15 (USW Flex), Port 23 Native
VLAN10DMZ_VL10Public-facing servers10.0.10.0/24Port 24 Tagged → Port 10 → Netgear GS108
VLAN40SECWIFI_VL40Secure WiFi10.0.40.0/24U6 Pro & UAP-AC-Lite (Native)
VLAN42IOT_VL42IoT WiFi devices10.0.42.0/24U6 Pro & UAP-AC-Lite (Tagged)
VLAN44GUEST_VL44Guest WiFi network10.0.44.0/24U6 Pro & UAP-AC-Lite (Tagged)
VLAN46GOATNET_VL46Unfiltered network10.0.46.0/24U6 Pro & UAP-AC-Lite (Tagged)
VLAN999BLACKHOLE_VL999Security (unused)NonePort 24 Native (tags untagged as VL999)

UniFi Switch Configuration

Configure the UniFi switch to implement the network topology and VLAN assignments described above.

Create VLANs in UniFi Controller

In Settings → Networks, create networks for each VLAN using these settings:

Common Settings (apply to ALL networks):

  • Router: Third-party Gateway
  • DHCP Mode: None

Create each network with these specific values:

Network NameVLAN IDGateway/SubnetPurpose
LANDefault (untagged)10.0.0.1/24Trusted wired devices (native on Ports 13, 15, 23)
DMZ_VL101010.0.10.1/24Public-facing servers
SECWIFI_VL404010.0.40.1/24Secure WiFi
IOT_VL424210.0.42.1/24IoT WiFi devices
GUEST_VL444410.0.44.1/24Guest WiFi
GOATNET_VL464610.0.46.1/24Unfiltered network
BLACKHOLE_VL999999(leave blank)Security - black hole VLAN
UniFi Networks overview showing all created VLANs: LAN, DMZ_VL10, SECWIFI_VL40, IOT_VL42, GUEST_VL44, GOATNET_VL46, and BLACKHOLE_VL999
💡 Security: Black Hole VLANs Explained

Use an unused VLAN VLAN999 as the native VLAN on trunk ports that should only carry tagged traffic. Any unexpected untagged frames get tagged as VLAN999 and discarded, preventing VLAN hopping attacks.

When to use Black Hole VLAN:

  • Port 24 (DMZ Uplink): Carries only tagged VLAN10. OPNsense igb2 has no native interface, so any untagged frames are security threats.

When to use Native LAN:

  • Port 23 (OPNsense igb1): Legitimate untagged LAN traffic from devices like the Main PC must reach OPNsense.
  • Port 15 (USW Flex): Devices at remote location need untagged LAN access, plus carries tagged VLANs like DMZ_VL10 for downstream switches.

Port 23 - OPNsense igb1 (LAN + VLANs):

UniFi Devices → [Your Switch] → Ports → Port 23:

FieldValue
NameOPNsense Uplink
Native Network/VLANLAN
Tagged VLAN ManagementCustom
Tagged VLANsSECWIFI_VL40, IOT_VL42, GUEST_VL44, GOATNET_VL46
ℹ️ Why Native LAN?

OPNsense igb1 handles untagged LAN traffic from devices like the Main PC (Port 13) and USW Flex (Port 15). These untagged LAN frames must reach igb1, while the tagged WiFi VLANs (40, 42, 44, 46) pass through simultaneously.

UniFi Port 23 configuration showing Native VLAN as LAN and tagged VLANs for WiFi (40, 42, 44, 46)

Port 24 - OPNsense igb2 (DMZ):

UniFi Devices → [Your Switch] → Ports → Port 24:

FieldValue
NameDMZ Uplink
Native Network/VLANBLACKHOLE_VL999
Tagged VLAN ManagementCustom
Tagged VLANsDMZ_VL10
ℹ️ Why VLAN999 (Black Hole VLAN)?

OPNsense igb2 has only vlan0.10 configured for tagged VLAN10. No native/untagged interface exists on igb2. Setting native to VLAN999 ensures any untagged frames are discarded (security best practice to prevent VLAN hopping attacks).

UniFi Port 24 configuration showing Native VLAN as BLACKHOLE_VL999 and Tagged VLAN DMZ_VL10 for DMZ uplink security

Create Port Profile for WiFi APs

Port profiles allow consistent configuration across multiple ports. We’ll create one profile for both WiFi access points.

Settings → Profiles → Port Profile → Create New Profile:

FieldValue
Profile NameWiFi VL(40-42-44-46)
Native Network/VLANSECWIFI_VL40
Tagged NetworksIOT_VL42, GUEST_VL44, GOATNET_VL46
ℹ️ Why Native SECWIFI_VL40?

AP management traffic uses the native VLAN SECWIFI_VL40. Since the UniFi Controller is on LAN, a firewall rule allows UniFi devices on SECWIFI_VL40 to reach the controller. SecWiFi clients use the native/untagged VLAN, while other SSIDs (IoT, Guest, GoatNET) use tagged VLANs 42, 44, 46.

UniFi port profile creation screen showing WiFi VL(40-42-44-46) profile with Native SECWIFI_VL40 and tagged VLANs 42, 44, 46

Configure Access Ports and WiFi APs

Ports 1 & 2 - WiFi Access Points:

UniFi Devices → [Your Switch] → Ports → Port 1:

FieldValue
Port ProfileWiFi VL(40-42-44-46)

Assign the same WiFi VL(40-42-44-46) profile to Port 2 (UAP-AC-Lite).

Both U6 Pro (Port 1) and UAP-AC-Lite (Port 2) broadcast all 4 SSIDs (SecWiFi, IoT_WiFi, Guest_WiFi, GoatNET) on different floors using identical VLAN assignments from the profile.

UniFi Port 1 configuration showing WiFi VL(40-42-44-46) port profile assignment for U6 Pro access point

Port 10 - Netgear GS108 Uplink (DMZ):

UniFi Devices → [Your Switch] → Ports → Port 10:

FieldValue
Native NetworkDMZ_VL10
Tagged VLAN ManagementBlock ALL
ℹ️ Why Block ALL and Native DMZ_VL10?

Security isolation combined with proper VLAN handling. Here’s the traffic flow: - OPNsense sends tagged VLAN10 to Port 24 - UniFi switch fabric routes VLAN10 to Port 10 - Port 10 sends VLAN10 traffic untagged to Netgear because DMZ_VL10 is the native network - Netgear Port 1 receives untagged frames and re-tags them as VLAN10 via PVID 10 - Blocking all tagged VLANs on Port 10 ensures no other network traffic can enter/exit this port, maintaining DMZ isolation

UniFi Port 10 configuration showing Native Network as DMZ_VL10 and Tagged VLAN Management set to Block ALL for Netgear uplink

Port 13 - Main PC (LAN Access):

UniFi Devices → [Your Switch] → Ports → Port 13:

FieldValue
Native NetworkLAN
Tagged VLAN ManagementAllow All
ℹ️ Why Allow All?

Flexibility for future trunking if needed (e.g., running VMs on different VLANs). Currently used as LAN access port.

UniFi Port 13 configuration showing Native Network as LAN and Tagged VLAN Management set to Allow All for Main PC

Port 15 - USW Flex Uplink (Trunk):

UniFi Devices → [Your Switch] → Ports → Port 15:

FieldValue
Native NetworkLAN
Tagged VLAN ManagementAllow All
ℹ️ Why Allow All?

Port 15 connects to USW Flex, which daisy-chains to a USW Flex Mini. The Flex Mini has a TV on DMZ_VL10, requiring tagged VLAN10 to pass through Port 15 → Flex → Flex Mini. Native LAN handles other devices at the remote location.

UniFi Port 15 configuration showing Native Network as LAN and Tagged VLAN Management set to Allow All for USW Flex trunk

USW Flex Configuration

The USW Flex connected to Port 15 extends network access to a remote location.

Port Configuration:

  • Port 1: Uplink to main switch Port 15 (receives LAN native + all tagged VLANs)
  • Port 3: Trunk to USW Flex Mini (LAN native + tagged DMZ_VL10)
  • Ports 2, 4-5: LAN access for local devices

The Flex receives all VLANs from Port 15, passes DMZ_VL10 downstream to the Flex Mini (which has a TV on DMZ_VL10), and provides LAN access to other devices at the remote location.


Netgear GS108 Configuration

With the UniFi switch configured, set up the Netgear GS108Ev3 to handle DMZ traffic isolation. The Netgear switch connects to UniFi Port 10, which receives DMZ VLAN10 from OPNsense igb2 via Port 24.

Configure Netgear Switch IP

Netgear switches ship with a factory static IP 192.168.0.239. To integrate it into your DMZ network, you’ll configure it to use DHCP with a static lease from OPNsense.

Step 1: Access switch via factory default IP:

  1. Connect your computer directly to the Netgear switch
  2. Set your computer to static IP: 192.168.0.2/24
  3. Browse to: http://192.168.0.239
  4. Login with default credentials: admin / password

Step 2: Note the switch MAC address:

On the main screen (System → Management → Switch Information), note the switch MAC address. You’ll need this for the static DHCP lease.

Netgear System Management Switch Information screen showing DHCP Mode checkbox and switch MAC address

Step 3: Configure static DHCP lease in OPNsense:

In OPNsense: Services → Dnsmasq DNS & DHCP → Hosts:

  • MAC Address: [Your Netgear switch MAC address from Step 2]
  • IP Address: 10.0.10.99
  • Hostname: netgear-dmz-switch
  • Domain: (leave blank or use your domain)
  • Description: Netgear GS108Ev3 DMZ Switch

This ensures the switch gets 10.0.10.99 when it requests DHCP from DNSmasq.

Step 4: Enable DHCP mode on switch:

Back on the Netgear switch (System → Management → Switch Information):

  • Check the DHCP Mode: Enable checkbox
  • Click Apply

The switch will reboot and request an IP via DHCP from OPNsense, receiving 10.0.10.99 based on your static lease configuration.

Step 5: Access switch on DMZ network:

After the switch reboots:

  1. Reconnect your computer to the main network
  2. Access the switch at its new DHCP-assigned IP: http://10.0.10.99
  3. The switch now operates on your DMZ VLAN10 network

Create VLAN 10 (DMZ)

VLAN → 802.1Q → Advanced → VLAN Configuration → Add:

FieldValue
VLAN ID10

Configure Port Memberships

VLAN → 802.1Q → Advanced → VLAN Membership:

VLAN 1 (Default - Unused):

Configure VLAN 1 to only include unused ports:

PortMembershipPurpose
1Not checked (neither T nor U)Uplink - only carries VLAN10, must NOT be in VLAN1
2-4Untagged (U)Unused spare ports (factory default)
5-8Not checked (neither T nor U)DMZ servers - only in VLAN10, must NOT be in VLAN1
Netgear VLAN 1 membership showing only ports 2-4 marked as Untagged (U), with ports 1 and 5-8 not checked
⚠️ Remove Ports from VLAN 1

By default, ALL ports are members of VLAN1. You must explicitly remove Port 1 and Ports 5-8 from VLAN1 by leaving them unchecked (neither T nor U). Leaving them in VLAN1 creates a security risk - VLAN1 traffic could leak between the DMZ and management networks.

VLAN 10 (DMZ):

PortMembership TypePurpose
1Tagged (T)Uplink to UniFi Port 10 (receives untagged, sends tagged)
5Untagged (U)DMZ Server 1
6Untagged (U)DMZ Server 2
7Untagged (U)DMZ Server 3
8Untagged (U)DMZ Server 4

Select VLAN 10 from the dropdown menu. Set Port 1 as “Tagged” (T) for the uplink to UniFi Port 10. Set Ports 5-8 as “Untagged” (U) for DMZ servers.

Netgear VLAN 10 membership showing Port 1 as Tagged (T) and Ports 5-8 as Untagged (U)

Configure Port PVID (Native VLAN)

VLAN → 802.1Q → Advanced → Port PVID Configuration:

PortPVIDPurpose
110Uplink to UniFi Port 10 (tags untagged incoming frames as VLAN10)
2-41Unused (spare ports, left in default VLAN 1)
5-810DMZ servers (tags untagged frames to VLAN10)

What PVID does: PVID (Port VLAN ID) assigns untagged incoming frames to the specified VLAN - similar to “native VLAN” in Cisco terminology. Ports 5-8 need PVID 10 so DMZ servers’ untagged traffic gets tagged with VLAN10.

Netgear PVID configuration showing Port 1 and Ports 5-8 with PVID 10, Ports 2-4 with PVID 1

With this configuration, any device connected to ports 5-8 on the Netgear switch will automatically receive a DHCP address from the DMZ_VL10 subnet 10.0.10.0/24 via OPNsense DNSmasq.


WiFi Access Point Configuration

With the UniFi switch configured and WiFi APs connected to Ports 1 & 2, create wireless networks (SSIDs) and map them to VLANs. The Netgear switch handles only wired DMZ traffic and is not involved in WiFi configuration.

UniFi Access Points

UniFi APs are configured through the UniFi Controller and can broadcast multiple SSIDs, each on a different VLAN.

Create Wireless Networks (SSIDs)

In Settings → WiFi, create each SSID with these settings:

SSID NameNetworkSecurityBroadcasting APsNotes
SecWiFiNative NetworkWPA2/WPA3 PersonalAll APsStrong password
IoT_WiFiIOT_VL42WPA2 PersonalAll APsDevice-compatible password
Guest_WiFiGUEST_VL44WPA2 PersonalAll APsOptional: Enable Guest Portal
GoatNETGOATNET_VL46WPA2/WPA3 PersonalAll APsStrong password
💡 Wireless Meshing

Enable wireless meshing in each WiFi network’s settings by configuring Mesh Parents and Mesh Connect with both APs selected. This allows APs to wirelessly extend coverage.

UniFi WiFi overview showing all four SSIDs created with Broadcasting APs set to all access points: SecWiFi (VLAN40), IoT_WiFi (VLAN42), Guest_WiFi (VLAN44), and GoatNET (VLAN46)

Verification

Test your configuration systematically to ensure VLANs work correctly.

Step 1: Verify OPNsense VLAN Interfaces

On OPNsense:

ifconfig | grep vlan

Expected output: All VLAN interfaces showing as UP:

vlan0.10: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST>
vlan0.40: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST>
vlan0.42: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST>
vlan0.44: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST>
vlan0.46: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST>

If any VLAN shows as DOWN, check OPNsense interface configuration.

Step 2: Test WiFi VLAN Assignment

Connect a device to each WiFi network and verify it receives the correct subnet:

ip addr show | grep inet

Expected results:

  • SecWiFi: 10.0.40.x (e.g., 10.0.40.105)
  • IoT_WiFi: 10.0.42.x (e.g., 10.0.42.112)
  • Guest_WiFi: 10.0.44.x (e.g., 10.0.44.101)
  • GoatNET: 10.0.46.x (e.g., 10.0.46.108)

If wrong subnet: Check SSID→Network assignment in UniFi WiFi settings and port profile on switch ports 1 & 2.

Step 3: Verify VLAN Isolation

From a device on SECWIFI_VL40, attempt to reach another VLAN:

ping 10.0.42.1

Expected: No response (OPNsense firewall rules block inter-VLAN traffic by default).

If ping succeeds: Check OPNsense firewall rules - VLANs should not be able to reach each other unless explicitly allowed.

Step 4: Test Internet Access

From devices on each VLAN:

ping 1.1.1.1
curl -I https://www.google.com

Expected: Both should succeed on all VLANs.

If fails: Check OPNsense outbound NAT rules and firewall allow rules for internet access.

Step 5: Verify DMZ Isolation

From a DMZ device (connected to Netgear):

# Should get IP from DMZ subnet
ip addr  # Expected: 10.0.10.x

# Should reach internet
ping 1.1.1.1  # Expected: Success

# Should NOT reach LAN
ping 10.0.0.1  # Expected: Timeout (firewall blocks DMZ→LAN)

From LAN device:

# LAN can reach DMZ (SEC_LAN_IG ICMP intranet ping rule allows LAN→DMZ)
ping 10.0.10.1  # Expected: Success

Notes

This post is intended to be used in conjunction with OPNsense VLAN setup

[references]
Related Guides:
  1. [1.1]
    Building a Secure Home Network with OPNsense — Complete OPNsense VLAN configuration
  2. [1.2]
    Testing Your OPNsense Setup — Verification procedures
  3. [1.3]
    Plex Remote Access Through OPNsense — Selective routing configuration
Switch Documentation:
  1. [2.1]
    UniFi Network Application — Official UniFi documentation
  2. [2.2]
    Netgear GS108Ev3 Manual — Switch configuration manual
Technical References:
  1. [3.1]
    Switch Port VLAN Assignment (Trunk & Access Ports) — UniFi VLAN configuration and trunk port behavior
  2. [3.2]
  3. [3.3]
    VLAN Membership vs PVID — Understanding PVID and tagged/untagged ports
[changelog]
2025-01-17:
  • Added configuration screenshots
  • Fixed technical inaccuracies in traffic flow descriptions
  • Improved table formatting and callout usage
2025-01-15:
  • Initial publication

Disclaimer

Use the information provided here at your own risk, but if you find errors or issues in this guide, leave a comment and I’ll try to address them ASAP.

RO

Ronaldo

BSc Mathematics | MSc Information Security

  • Technical problem-solver with unusually broad capabilities & interests
  • I figure things out and get things done

Comments

Table of Contents