Migrating from an EdgeRouter X to OPNsense

My Ubiquiti EdgeRouter X seems to only get critical security updates these days, so I replaced it with OPNsense, which is open source. My EdgeRouter config came mostly from mjp66’s EdgeRouter guide, with home, guest, IoT and spare networks as VLANs.

I built the OPNsense box from the parts in ServerBuilds.net’s NAS Killer 6.0 guide, an ASUS PRIME H310M-C/CSM board and a Pentium Gold G5400 with 16 GB of DDR4, in a Thermaltake Versa H18 case. I picked a desktop board over a mini PC for its PCIe slots (one x16 and two x1), so I can swap in faster network cards later. For now an Intel 82576 dual-port gigabit card handles the network, one port for the WAN and one as a trunk carrying every VLAN to my UniFi gear, USW-Flex switches and U6 Pro access points (a router-on-a-stick setup).

Port isolation during setup

Turn on port isolation for the new router’s switch port before you plug it into the LAN. It’s a router, so in some situations it starts routing traffic for other devices before it’s configured. My OPNsense box’s logs showed traffic from my local devices until I isolated its port on the UniFi switch, and it stayed isolated until I was ready to switch over.

Translating the firewall rules

OPNsense can’t import an EdgeRouter config, so I rebuilt mine by hand. Each EdgeRouter VLAN (a vif on its built-in switch) became a VLAN interface in OPNsense, and each address group became an alias, OPNsense’s name for a saved list of addresses.

The EdgeRouter gives each VLAN one ruleset for traffic to the router itself (local) and another for traffic passing through it (in). These were my guest network’s:

set firewall name GUEST_LOCAL default-action drop
set firewall name GUEST_LOCAL rule 1 action accept
set firewall name GUEST_LOCAL rule 1 protocol udp
set firewall name GUEST_LOCAL rule 1 destination port 67
set firewall name GUEST_LOCAL rule 2 action accept
set firewall name GUEST_LOCAL rule 2 protocol tcp_udp
set firewall name GUEST_LOCAL rule 2 destination port 53

set firewall name GUEST_IN default-action accept
set firewall name GUEST_IN rule 20 action drop
set firewall name GUEST_IN rule 20 destination group address-group RFC-1918_GROUP

set interfaces switch switch0 vif 20 firewall local name GUEST_LOCAL
set interfaces switch switch0 vif 20 firewall in name GUEST_IN

OPNsense has a single list per interface, checked top to bottom, so both rulesets became the guest tab under Firewall > Rules. “GUEST address” is the router’s own IP on that VLAN, and “GUEST net” is the whole guest subnet:

Action  Source     Destination    Port  Description
pass    GUEST net  GUEST address  53    Allow DNS to firewall
block   GUEST net  RFC1918        *     Block access to all other private networks
block   GUEST net  GUEST address  *     Block Firewall Access
pass    GUEST net  *              *     Allow Internet Access

There’s no DHCP rule because guests get DHCP from OPNsense without one.

Untagged traffic and VLAN 1

VLAN 1 mattered because I kept the UniFi switches and access points behind a non-UniFi router. Out of the box, the UniFi devices and anything on UniFi’s Default network use VLAN 1. My home network was VLAN 1 on the EdgeRouter too, so I made a VLAN 1 interface in OPNsense for it. None of that traffic showed up there. It arrived untagged, on the trunk’s parent interface.

Untagged and VLAN 1 turn out to be the same traffic, seen from different sides of the switch. Inside the UniFi switch, the Default network is VLAN 1, and it’s each port’s native VLAN, so the switch strips the tag when that traffic leaves a port and adds it back when untagged traffic arrives. The EdgeRouter X has its own switch chip with the same setting (port VLAN ID, or PVID, 1 on its ports), so untagged traffic became VLAN 1 inside the router too and landed on vif 1. My OPNsense box has a plain network card with no switch in front of it, so nothing turns untagged traffic into VLAN 1. A VLAN 1 interface there only gets frames that actually carry a tag of 1, and UniFi never sends those.

That leaves two options. OPNsense can use the parent interface for that traffic, or every port has to be tagged. Tagging everything means moving the home network to VLAN 2 or higher, since UniFi won’t let you create a network with VLAN ID 1, and then each switch needs one of these:

  • a port profile with the new network as its primary network, applied to every port
  • a network override on the switch, setting its virtual network to the new network

Either one is a step I’d have to remember on every new switch, and the UniFi controller app’s only hint about any of this is a greyed-out VLAN field on the Default network. I’d rather have a switch that’s explicit about tagging than one that simplifies it for me.