OPNsenseXXII · IPsecIPsec configuration models
IPsec route-based vs policy-based — how OPNsense wires the tunnel into the firewall
What you'll learn
- Distinguish policy-based VPN from route-based VPN on OPNsense
- Explain why route-based VPN with a VTI gives the operator a real interface to firewall on
- Configure a route-based VTI IPsec tunnel on OPNsense
- Choose between policy-based and route-based for a given deployment
- Recognise the failure modes that come from policy-based without a clear selector
Prerequisites
Verified against OPNsense 25.x · FreeBSD 14.x · PF (FreeBSD packet filter) FreeBSD 14.x · Unbound 1.20+ · Kea DHCP OPNsense 25.x plugin · WireGuard in-kernel + OPNsense plugin · strongSwan (IPsec plugin) OPNsense 25.x plugin · OpenVPN 2.6.x · Suricata 7.x · 2026-08-15
An IPsec tunnel on OPNsense can be wired into the firewall in two fundamentally different ways. The classic model — policy-based VPN — encapsulates traffic based on traffic selectors that match the source and destination subnets: any packet matching the selector gets put into the tunnel. The modern model — route-based VPN — creates a virtual tunnel interface (VTI) that the routing table treats as a next hop: the operator pushes a route to the remote subnet through the VTI, and packets that follow the route get encapsulated. Both models produce working IPsec tunnels. The difference is in what the operator can do with the tunnel once it exists — fire wall rules, NAT exceptions, multi-WAN integration, monitoring all look very different on the two models. This lesson covers the two models, how OPNsense implements each, and how to choose.
The two models
Policy-based VPN. The Phase 2 entry carries a traffic selector (local subnet, remote subnet, protocol, port range). When a packet matches the selector, strongSwan encapsulates it and sends it through the IPsec SA. The matching happens in the IPsec layer, before the firewall or routing table sees the packet as a tunnel packet. From the operating system’s perspective, the encapsulated traffic just disappears into the SA; the only way to know what’s encapsulated is to read the SA’s selectors.
Route-based VPN. The IPsec SA is associated with a virtual tunnel interface (a ipsecX interface on FreeBSD, or a tunX if using the TUN device model). The operator assigns an IP address to the VTI, adds a route to the remote subnet through the VTI as next hop, and writes firewall rules on the VTI just like on any other interface. From the operating system’s perspective, the tunnel is a wire — packets routed through it get encapsulated, packets not routed through it do not.
| Aspect | Policy-based | Route-based (VTI) |
|---|---|---|
| What selects traffic | Traffic selector in Phase 2 entry | Routing table — any route whose next hop is the VTI |
| Firewall rules | On the LAN and WAN interfaces only (the IPsec SA is invisible to PF) | On the VTI just like any other interface |
| Multi-WAN integration | Difficult (no way to distinguish traffic on the SA without additional selectors) | Works naturally (the route is the selector) |
| NAT rules | Outside the SA; the SA encapsulates everything that matches | On the VTI; rules are first-class firewall objects |
| Multiple subnets | One Phase 2 per subnet pair | One Phase 2 with 0.0.0.0/0 selectors, then routes |
| Failure mode | Subtle — selectors may not match the traffic you expected | Obvious — if the route is missing, packets don’t traverse |
Why route-based VPN is usually the right choice
Five reasons route-based VPN beats policy-based in production:
Firewall rules on the tunnel. With a VTI, the operator writes firewall rules that match source/destination tuples from the LAN to the remote subnet across the VTI — exactly the same shape as rules for any other interface. With policy-based, the only “rules” are the traffic selectors in the Phase 2 entry, which are far less expressive.
NAT exceptions per remote network. A typical estate has some traffic that should cross the IPsec tunnel without NAT (so the remote end sees the original source IP) and other traffic that should be NAT-translated. On a VTI, the operator writes the NAT rule with the VTI as the egress interface. On a policy-based tunnel, the same effect requires careful Phase 2 selector management.
Multi-WAN integration. If the firewall has two WANs and the operator wants IPsec traffic to use the primary WAN but everything else to use the default route, the VTI makes this trivial — add a route to the tunnel with the primary WAN as the gateway. Policy-based VPNs cannot be paired with gateway groups because the SA is invisible to the routing table.
Monitoring. A VTI appears in ifconfig output, systat -ifstat, and OPNsense’s interface statistics pages. The operator can see packet counts, error counts, and byte counters on the tunnel just like on any other interface. Policy-based tunnels show up only in strongSwan’s status output, not in any system-wide interface view.
Multiple subnets without selector multiplication. A route-based tunnel can carry traffic to many remote subnets by adding more routes through the VTI. A policy-based tunnel needs a new Phase 2 entry per subnet pair, each with its own SA, each with its own lifetime, each with its own negotiation. Route-based with one Phase 2 + many routes is operationally simpler.
Configuring route-based VPN on OPNsense
The configuration workflow for a route-based tunnel:
- Phase 1 entry under
VPN → IPsec → Tunnel Configuration → Add Phase 1. IKEv2, certificate or PSK, AES-256-GCM, DH group 14 or 31, 24h lifetime. Standard. - Phase 2 entry under the same tunnel. Set both Local subnet and Remote subnet to
0.0.0.0/0(a wildcard), set Protocol to ESP, set Encryption to AES-256-GCM, enable PFS, 1h lifetime. - Enable VTI under the Phase 2 entry’s “Tunnel Settings” or in the Phase 1 entry’s advanced settings. The OPNsense UI exposes VTI as the “Install Virtual Tunnel Interface” toggle.
- Assign the VTI as an interface. Once Phase 2 is saved, a new
ipsec0(or similar) interface appears underInterfaces → Assignments. Assign it a name (e.g.,OPT_VPN). - Configure the VTI under
Interfaces → OPT_VPN. Set a private IP address — typically a/30between two fictional endpoint addresses like10.10.10.1/30peer10.10.10.2. The peer IP does not need to be reachable; it just identifies the far side of the tunnel. - Add a route under
System → Routes → Configurationfor the remote subnet with the VTI as the gateway, or rely on dynamic routing if the operator is running OSPF/BGP. - Add firewall rules for the VTI: allow the LAN subnets to talk to the remote subnets, block anything that should not enter the tunnel.
$ ifconfig ipsec0ipsec0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1400
inet 10.10.10.1 --> 10.10.10.2 netmask 0xfffffffc
inet6 fe80::a8b1:c2d3:e4f5:6789%ipsec0 prefixlen 64 scopeid 0x8
nd6 options=21<PERFORMNUD,NO_RADR>
groups: ipsec
phase 2
reqid 1Illustrative output
The VTI is a point-to-point interface with a relatively small MTU (typically 1400; the operator can lower it to 1380 or even 1360 for safety). The operator writes firewall rules on the VTI and treats it as an internal interface that happens to encapsulate through IPsec.
When policy-based VPN still wins
Two scenarios where policy-based is the right answer:
Hub-and-spoke with very different subnet shapes per spoke. A central hub with 10 spoke sites, each protecting a different subnet (192.168.1.0/24, 192.168.2.0/24, etc.), can use one Phase 1 entry on the hub per spoke, each with a Phase 2 entry whose selector matches that specific spoke’s subnet. Route-based would work too, but the policy-based shape is sometimes easier to audit (“the tunnel to spoke 7 carries only 192.168.7.0/24”).
Strict payload containment. If the deployment has a compliance requirement that no traffic beyond a specific subnet pair can cross the tunnel, the policy-based traffic selector enforces that at the SA level. The operator cannot accidentally route additional traffic through the SA without modifying the Phase 2 entry.
These scenarios are real but rare. For the majority of deployments, route-based VPN with a VTI is simpler, more flexible, and easier to integrate with the rest of the firewall.
Verifying route-based VPN
The verification workflow for a route-based tunnel:
- Confirm the VTI exists.
ifconfig ipsec0shows the interface with its IP address and point-to-point peer.swanctl --list-sasshows the active IKE and ESP SAs. - Confirm the route.
netstat -rn | grep ipsec0shows the route to the remote subnet through the VTI. - Confirm the firewall allows the traffic.
pfctl -s rules | grep ipsec0shows any firewall rules on the VTI. A missing rule on a VTI with a default-deny policy is the most common silent failure. - Confirm traffic flows. A ping from the LAN to a host on the remote subnet appears in
tcpdump -ni ipsec0as clear-text encapsulated packets, and intcpdump -ni WANas the encrypted ESP traffic. - Confirm state.
pfctl -s state | grep ipsec0shows the PF states on the VTI.
$ route -n get 10.1.0.50route to: 10.1.0.50
destination: 10.1.0.0/24
interface: ipsec0
gateway: 10.10.10.2
fib: 0
flags: <UP,DONE>
recvpipe sendpipe ssthresh rtt,msec mtu expire
0 0 0 0 1500 0Illustrative output
Summary
- Policy-based VPN matches traffic to traffic selectors at the SA level; the tunnel is invisible to the rest of the firewall.
- Route-based VPN creates a VTI (virtual tunnel interface) that the routing table treats as a next hop; the tunnel is a first-class interface.
- Route-based VPN is the production default because it integrates with firewall rules, NAT, multi-WAN, and monitoring.
- Configure route-based VPN on OPNsense by enabling VTI on Phase 2, assigning the VTI as an interface, and adding routes.
- Wildcard selectors in policy-based VPN are a footgun — switch to route-based instead.
Knowledge check · 4 questions
Q1. A site-to-site IPsec deployment needs to allow LAN-to-remote traffic for two remote subnets (10.1.0.0/24 and 10.2.0.0/24), with different NAT exclusions per subnet, and the firewall has two WANs. Which model is the simpler choice?
Q2. On a policy-based IPsec tunnel, PF can write rules on the IPsec SA as if it were a real interface.
Q3. Which of the following are reasons route-based VPN (with a VTI) is the typical production choice on OPNsense? Select all that apply.
Q4. After saving a route-based IPsec configuration, the operator cannot reach the remote subnet. The Phase 2 SA is up (swanctl --list-sas shows ESTABLISHED). ping from the firewall itself to the remote subnet fails. What is the most likely cause?
Passing score: 75%. Answers are checked in this browser.