This builds a two-tier failover on OPNsense: new connections leave through the backup WAN when the primary fails, local DNS keeps answering, and traffic between your own networks never wanders out of a WAN. Established sessions do not survive the switch. A new public address breaks them, and the client has to reconnect. Keep OPNsense's Multi WAN how-to[1] open beside this; the steps below follow its order and fill in the parts it leaves to you.
Have these before you touch a setting:
- two WANs that each work on their own
- console access, in case a rule locks you out of the web GUI
- a configuration backup taken today
- a maintenance window, because step 6 pulls the plug on the primary
Two menu changes in the current 26.7 series affect the paths below. The MVC firewall rules page is now the default (the manual calls it Firewall ‣ Rules [new]), and the old static rules pages moved to the optional os-firewall-legacy plugin; existing rules keep working either way, per the 26.7 release notes[2]. Outbound NAT is being replaced by Firewall ‣ NAT ‣ Source NAT (Outbound).
1. Prove Each WAN Works on Its Own
- Open System ‣ Gateways ‣ Configuration and confirm both WAN gateways are listed. A dynamically configured WAN, such as one on DHCP, normally creates its own, with a name like
WAN_DHCP, so you only add one by hand for a static WAN. If a gateway you expect is missing, stop and fix that: the system only considers gateways shown on this page, according to the gateway reference[3]. - For a statically addressed WAN, open Interfaces ‣ [that WAN] and check that its upstream gateway is set. The how-to notes that on a default setup this is what creates the source NAT rule for traffic leaving the interface and the reply-to return path.
- Ping out through each WAN from Interfaces ‣ Diagnostics ‣ Ping, with that WAN as the source.
- Write down the current default route from System ‣ Routes ‣ Status. You will compare against it in step 6.
- Give each gateway its own Monitor IP: a dependable public host beyond your ISP's edge, so a dead upstream path shows as a failure even while the modem still answers. Use a different address on each gateway, as the how-to's example does with 8.8.8.8 and 8.8.4.4. OPNsense routes each monitor address out of its own gateway with a dedicated host route unless you tick Disable Host Route, and separate targets keep the two status readings independent. Leave Disable Gateway Monitoring and Mark Gateway as Down unchecked.
- Open Firewall ‣ NAT ‣ Source NAT (Outbound). In automatic mode, check there are rules for both WANs. If you run manual or hybrid mode, static public addresses, VPNs or inbound services, read every rule that touches either WAN. A LAN rule that sends traffic to WAN2 still fails if the packets leave with the wrong translated address.
You are done when both gateways show online against their own monitor addresses, each WAN passes its own ping, and source NAT covers both WANs.
2. Build the Failover Group
- Go to System ‣ Gateways ‣ Group and add a group. The how-to calls it
WANGWGROUP; any name works, but you will pick it from a list later, so make it obvious. - Put the primary gateway on Tier 1 and the backup on Tier 2. Gateways that share a tier balance load between them, and gateways on different tiers fail over, which is what you want here. OPNsense offers five tiers if you add a third link later.
- Pick a Trigger Level. The how-to's example uses Packet Loss.
| Trigger level | Fires when | Pick it when |
|---|---|---|
| Member Down | The gateway has 100% packet loss | You only want to leave on a hard outage. |
| Packet Loss | Loss to the gateway is higher than its threshold | A lossy link should count as failed. |
| High Latency | Latency to the gateway is higher than its threshold | Delay alone makes the link unusable for you. |
| Packet Loss or High Latency | Either of the above | You have watched both symptoms and accept more switching. |
- Set the thresholds on each gateway, not on the group: in System ‣ Gateways ‣ Configuration, edit the gateway and open its advanced options. You get low and high latency thresholds in milliseconds, low and high packet loss thresholds in percent, the probe interval, Down (seconds of failed probes before the alarm fires) and the averaging settings, all listed in the how-to's advanced options[1]. There is no single right set of numbers. A cellular backup and a fiber primary need different tolerances, so watch each link's monitor readings during normal use and set thresholds above that ordinary variation. Set them too tight and the firewall flaps between WANs.
- Save, apply, and read the gateway status. If a WAN you know works shows offline, work through it in the gateway troubleshooting[3] order before touching any threshold: ping the monitor address through that interface, check System ‣ Routes ‣ Status for its route, confirm a
dpingerprocess in System ‣ Diagnostics ‣ Services, then look for ICMP to the monitor address in Interfaces ‣ Diagnostics ‣ Packet Capture.
You are done when the group shows the primary on Tier 1 and the backup on Tier 2, and both members report the same status your step 1 tests did.
3. Policy-Route LAN Traffic Through the Group
- Open Firewall ‣ Rules [new] and choose LAN in the interface filter. That view includes the floating and interface-group rules that act on LAN, which matters: the processing order[4] is floating rules, then interface groups, then the interface itself, and rules are quick by default, so the first match wins. A floating or group rule that matches first decides before your LAN rule is read.
- Above the internet rule, add pass rules for each internal subnet and VPN destination LAN is supposed to reach, with Gateway left on
default. Policy routing skips the system routing table, so an any-destination rule with a gateway set will push traffic for your other networks into the WAN group. Add only destinations LAN should already reach. This is a routing fix, not a reason to open a path from IoT to your LAN; the OPNsense IoT rule guide covers that boundary. - Add the DNS exception, also above the internet rule: Pass, interface LAN, protocol TCP/UDP, destination the firewall's LAN address as a single host (
192.168.1.1/32in the how-to), destination port DNS, Gatewaydefault. Without it, a client's query to the firewall's own resolver gets routed toward the WAN group. The how-to's rule is IPv4 only, so add a matching IPv6 rule if clients query the firewall over IPv6, and give any other service on the firewall that LAN clients use the same kind of exception. - Point the internet rule at the group. The how-to edits the Default allow LAN to any rule and sets its Gateway to
WANGWGROUP; a narrower pass rule placed below your exceptions works the same way. Repeat for any other VLAN that should fail over, keeping guest and IoT restrictions above it. - Leave the reply-to settings alone unless your topology needs a change you have tested. With multi-WAN, OPNsense adds reply-to automatically so replies leave by the interface the traffic arrived on, as described under Disable reply-to[5].
- Apply, open a fresh connection from a LAN client, and find its state in Firewall ‣ Diagnostics ‣ States. When it is unclear which WAN carried the traffic, capture on both WANs. A traceroute from the client cannot tell you which rule matched.
You are done when new internet connections leave through the group, DNS queries to the firewall stay local, and every allowed internal or VPN destination still routes normally.
4. Make the Firewall's Own Traffic Fail Over
Policy routing only moves traffic that matches a rule. Everything the firewall originates itself, including Unbound's lookups, follows the system default route, and there is only one default per IP version at a time. Fix that separately.
- In System ‣ Gateways ‣ Configuration, tick Upstream Gateway on both WAN gateways and give the primary the lower Priority number. The how-to's metered example uses 253 for the main line and 254 for the backup. When choosing a default, OPNsense sorts upstream gateways first and then by priority, where 1 is most important and 255 least.
- In System ‣ Settings ‣ General, enable Allow default gateway switching. Without it the default only changes at startup or when an interface connects or disconnects, so a monitored outage leaves the firewall's own traffic pointed at the dead link. The (active) marker on the gateways page shows the calculated default, which can differ from the real routing table while switching is off; System ‣ Routes ‣ Status shows what is actually in use.
- On the same page, set the DNS servers with a gateway beside each one, at least one unique server per gateway. The how-to binds 8.8.8.8 to WAN and 8.8.4.4 to WAN2. If Allow DNS server list to be overridden by DHCP/PPP on WAN is ticked, the servers your ISPs hand out are used as well, so decide whether you want that.
- In Services ‣ Unbound DNS ‣ General, leave Network Interfaces and Outgoing Network Interfaces on All, which the Unbound manual[6] recommends for both. It also notes that explicit outgoing interfaces only work when they are statically configured, so picking a DHCP or PPPoE WAN there is asking for a resolver that stops when its address changes.
- If Unbound forwards queries, do not tick Use System Nameservers under Services ‣ Unbound DNS ‣ Query Forwarding in this setup. The manual warns against it when multiple DNS servers in General have separate gateways: Unbound reaches them over locally created routes, which stop working when that gateway is down. Forward to servers you list there instead, or leave Unbound resolving on its own.
- Test both directions: a query from a LAN client to the firewall's LAN address, and a lookup run on the firewall itself. If the client query fails only after you added the group rule, recheck the DNS exception from step 3 and the client's entry in Services ‣ Unbound DNS ‣ Access Lists. If the firewall's own lookups fail, check the system DNS servers, the active default route and Unbound's outgoing interfaces.
You are done when both lookups succeed now; step 6 proves they still succeed with either WAN down.
5. Decide What Happens to Existing States
- Leave Sticky connections (Firewall ‣ Settings ‣ Advanced) off for a plain Tier 1 / Tier 2 group unless a specific application needs it. Per the advanced settings[5], it makes a gateway group use the same gateway for the same source address while a state is active, with an optional timeout. That helps load-balanced traffic and does nothing for a session whose public address just changed. If you later balance two gateways on one tier, the how-to also says to disable Shared forwarding on that page.
- Choose Failover States and Failback States per gateway in System ‣ Gateways ‣ Configuration. Both kill states so clients reconnect; nothing migrates. They are set on the gateway, so they apply wherever that gateway is used, with no distinction between groups. - Failover States on the primary: when it goes down, its states are killed so clients reconnect over another online gateway. - Failback States on the backup: when a higher-priority gateway comes back, the backup's states are killed. This is the how-to's setup[1] for a metered LTE or 5G backup, so nothing keeps burning data on it after the main line recovers.
- Keep monitoring and default gateway switching on. The gateway reference says each option needs either default gateway switching or gateway-group membership to trigger, and the how-to's metered example enables switching and calls it necessary. Step 4 already did that.
- Expect SSH sessions, video calls and anything else long-lived to drop and reconnect whenever states are killed. That is the point of the option.
You are done when the state options on each gateway match the disruption you will accept, and a metered backup has Failback States set.
6. Pull the Plug and Time It
- Before the test, open a long-lived session from a LAN client (SSH or RDP, which the how-to suggests) and note the public IP it uses. Run a DNS query from the client to the firewall's LAN address and a lookup on the firewall itself.
- Disconnect the primary WAN. Watch System ‣ Gateways ‣ Configuration, the default route in System ‣ Routes ‣ Status, and Firewall ‣ Diagnostics ‣ States.
- Time two intervals: from the unplug until the gateway is marked down, and from then until a new connection works through WAN2.
- Check web access, both DNS paths, any VPNs and your internal routes over WAN2. The session pinned to WAN1 will drop; reconnect it and confirm the new public IP.
- Reconnect WAN1 and wait for failback. Confirm new connections return to Tier 1 and the default route moves back. If you set Failback States, the sessions on WAN2 should be forced to reconnect.
- Unplugging a cable only tests hard-failure detection. If you chose a loss or latency trigger, test a degraded link separately.
- If you run IPv6, repeat the rules, DNS exception and test for the IPv6 gateways instead of assuming the IPv4 run covers it. The native IPv6 on OPNsense guide covers the delegated-prefix side.
You are done when new connections and DNS recover through either working WAN, internal routes still work, and your notes record detection time, which sessions dropped and how failback behaved. If any one of those checks fails, go back to its step before you trust the backup link.