← Back to Blog
FortiGateOPNsenseIPsecIKEv2VPNNetwork Security

Building a FortiGate to OPNsense Site-to-Site IPsec Tunnel with IKEv2

Building a FortiGate to OPNsense Site-to-Site IPsec Tunnel with IKEv2

Building a FortiGate to OPNsense Site-to-Site IPsec Tunnel with IKEv2

Site-to-site VPNs between mixed-vendor firewalls always sound simple on paper and turn ugly the moment you press Apply. This guide walks through a complete, working FortiGate to OPNsense IKEv2 IPsec tunnel, covering Phase 1 and Phase 2, firewall policies, routing, and the troubleshooting steps that actually fix the common failures.

The configuration is shown with example IP addresses — substitute your own. Tested with FortiOS 7.4 and OPNsense 26.1 (strongSwan/swanctl).

What you'll learn

  • How to configure FortiGate Phase 1 and Phase 2 for a mixed-vendor IPsec tunnel
  • How to set matching OPNsense strongSwan/swanctl connection settings
  • Which firewall rules and routes are required for traffic flow
  • How to avoid the typical AUTH_FAILED, NO_PROPOSAL_CHOSEN, and traffic-drop problems

1. Topology

                         IPsec (IKEv2 / ESP)
+------------------+        over Internet         +--------------------+
| FortiGate        |  203.0.113.10  ===========>  | OPNsense           |
| WAN: 203.0.113.10|                              | WAN: 198.51.100.20 |
| LAN: 192.168.120.0/24                            | LAN: 10.10.0.0/24  |
+------------------+                              +--------------------+
        |                                                    |
   192.168.120.0/24                                     10.10.0.0/24
   (Office network)                                    (Cloud / DC)
SidePublic IPLocal Subnet
FortiGate203.0.113.10192.168.120.0/24
OPNsense198.51.100.2010.10.0.0/24

We'll authenticate with a Pre-Shared Key (PSK) and use IKEv2 with AES-128/SHA-256/DH14 — a sensible modern default that both vendors interop cleanly on.


2. Crypto Parameters (must match exactly on both ends)

ParameterValue
IKE versionIKEv2
AuthenticationPSK
Phase 1 encryptionAES128
Phase 1 hashSHA256
Phase 1 DH group14 (modp2048)
Phase 1 lifetime86400 s
Phase 2 encryptionAES128
Phase 2 hashSHA256
Phase 2 PFS group14
Phase 2 lifetime43200 s
ModeTunnel
NAT-TOff (both sides have public IPs)
DPDOn demand / restart

Tip: 90% of "auth failed / no proposal chosen" tickets come from one of these values being one notch off on one side. Pin them down before clicking Save.


3. FortiGate Configuration

3.1 Phase 1 (IKE)

GUI: VPN ▸ IPsec Tunnels ▸ Create New ▸ Custom.

FieldValue
NameOPNsense-DC
Remote GatewayStatic IP Address
IP Address198.51.100.20
Interfacewan1
NAT TraversalDisable
Dead Peer DetectionOn Demand
Authentication MethodPre-shared Key
Pre-shared Key<your-PSK>
IKE Version2
Mode(n/a for IKEv2)
Encryption / AuthAES128 / SHA256
Diffie-Hellman14
Key Lifetime86400

CLI equivalent:

config vpn ipsec phase1-interface
    edit "OPNsense-DC"
        set interface "wan1"
        set ike-version 2
        set peertype any
        set net-device disable
        set proposal aes128-sha256
        set dhgrp 14
        set remote-gw 198.51.100.20
        set psksecret <your-PSK>
        set dpd on-demand
        set nattraversal disable
    next
end

3.2 Phase 2 (Child SA / Selectors)

FieldValue
NameOPNsense-DC-P2
Local AddressSubnet 192.168.120.0/24
Remote AddressSubnet 10.10.0.0/24
Encryption / AuthAES128 / SHA256
PFSEnabled, DH14
Lifetime43200 s
Auto-negotiateEnabled

CLI:

config vpn ipsec phase2-interface
    edit "OPNsense-DC-P2"
        set phase1name "OPNsense-DC"
        set proposal aes128-sha256
        set pfs enable
        set dhgrp 14
        set keylifeseconds 43200
        set src-subnet 192.168.120.0 255.255.255.0
        set dst-subnet 10.10.0.0 255.255.255.0
        set auto-negotiate enable
    next
end

3.3 Static Route

config router static
    edit 0
        set dst 10.10.0.0 255.255.255.0
        set device "OPNsense-DC"
        set comment "Remote LAN via IPsec"
    next
end

3.4 Firewall Address Objects + Policies

config firewall address
    edit "Office-LAN"
        set subnet 192.168.120.0 255.255.255.0
    next
    edit "DC-LAN"
        set subnet 10.10.0.0 255.255.255.0
    next
end

config firewall policy
    edit 0
        set name "Office-to-DC"
        set srcintf "lan"
        set dstintf "OPNsense-DC"
        set action accept
        set srcaddr "Office-LAN"
        set dstaddr "DC-LAN"
        set schedule "always"
        set service "ALL"
        set nat disable
    next
    edit 0
        set name "DC-to-Office"
        set srcintf "OPNsense-DC"
        set dstintf "lan"
        set action accept
        set srcaddr "DC-LAN"
        set dstaddr "Office-LAN"
        set schedule "always"
        set service "ALL"
    next
end

Critical: set nat disable on the outbound tunnel policy. If FortiGate masquerades the source, the packet's source address will no longer match the Phase 2 selector and the remote end silently drops it — one of the most time-consuming bugs to chase.


4. OPNsense Configuration (modern swanctl/Connections model)

OPNsense 25.x and later expose strongSwan's swanctl configuration directly under VPN ▸ IPsec ▸ Connections. This replaces the legacy Tunnel Settings UI. Use the new model — it maps 1:1 to swanctl/strongSwan.

4.1 Connection (Phase 1)

VPN ▸ IPsec ▸ Connections ▸ Connections ▸ +

FieldValue
Enabled✓
Proposalsaes128-sha256-modp2048
VersionIKEv2
Uniquereplace
Aggressiveunchecked
Mobikechecked
Local Addresses198.51.100.20
Remote Addresses203.0.113.10
UDP Encapsulationunchecked
Reauth Time86400
Rekey Time77400
DPD Delay30
DPD Timeout120

4.2 Local Authentication

Connections ▸ Local authentication ▸ +

FieldValue
Connection(the connection above)
AuthenticationPre-Shared Key
ID198.51.100.20

4.3 Remote Authentication

Connections ▸ Remote authentication ▸ +

FieldValue
Connection(same)
AuthenticationPre-Shared Key
ID203.0.113.10

4.4 Pre-Shared Key

VPN ▸ IPsec ▸ Pre-Shared Keys ▸ +

FieldValue
Local identifier198.51.100.20
Remote identifier203.0.113.10
PSK typePSK
Pre-Shared Key<your-PSK>

Type the PSK manually rather than pasting; stray invisible characters in copy/paste are a classic cause of AUTH_FAILED.

4.5 Child SA (Phase 2)

Connections ▸ Children ▸ +

FieldValue
Enabled✓
Connection(same)
ModeTunnel
Policieschecked
ESP Proposalsaes128-sha256-modp2048
Start Actionstart
Close Actionnone
DPD Actionrestart
Local TS10.10.0.0/24
Remote TS192.168.120.0/24
Rekey Time38880

4.6 Enable IPsec

VPN ▸ IPsec ▸ Settings → Enable IPsec ✓ → Apply.

4.7 Firewall Rules

OPNsense will not pass traffic through the tunnel without explicit rules on the IPsec interface, even when the SA is up.

Firewall ▸ Rules ▸ IPsec ▸ +

ActionSourceDestinationDescription
Pass192.168.120.0/2410.10.0.0/24Allow Office to DC

4.8 Outbound NAT (No-NAT for Tunnel Traffic)

If Firewall ▸ NAT ▸ Outbound is set to Automatic or Hybrid, add a manual rule before the auto rules:

InterfaceSourceDestinationNAT
WAN10.10.0.0/24192.168.120.0/24No NAT

This stops OPNsense from masquerading tunnel traffic out the public WAN IP.


5. Bringing the Tunnel Up

On OPNsense (shell):

configctl ipsec reload
swanctl --list-conns
swanctl --initiate --child <child-uuid>
swanctl --list-sas

A healthy tunnel looks like:

<conn>: ESTABLISHED, IKEv2 ...
  AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_2048
  <child>: INSTALLED, TUNNEL, ESP:AES_CBC-128/HMAC_SHA2_256_128/MODP_2048
    local  10.10.0.0/24
    remote 192.168.120.0/24

On FortiGate:

get vpn ipsec tunnel summary
diagnose vpn ike gateway list name OPNsense-DC

6. End-to-End Verification

From a host on 192.168.120.0/24:

ping 10.10.0.10
ssh [email protected]

From a host on 10.10.0.0/24:

ping 192.168.50.10

OPNsense live capture (decrypted traffic):

tcpdump -ni enc0

FortiGate live capture (encrypted + decrypted on the named tunnel interface):

diagnose sniffer packet any "host 10.10.0.10 and host 192.168.50.10" 4 0 l

swanctl --list-sas byte/packet counters incrementing on both in and out is the cleanest sign things really work end-to-end.


7. Troubleshooting Cheat Sheet

These are the failures you're most likely to hit, in roughly the order they appear:

7.1 IKE_AUTH fails with AUTHENTICATION_FAILED

Phase 1 negotiated, IKE_AUTH rejected by peer. Almost always:

  • PSK mismatch (retype manually on both sides).
  • Peer ID mismatch — on FortiGate, set peertype any and unset peerid/localid until you've confirmed the basics.

Watch FortiGate IKE in real time:

diagnose debug reset
diagnose debug application ike -1
diagnose debug enable
diagnose vpn ike gateway flush name OPNsense-DC

7.2 NO_PROPOSAL_CHOSEN on the CHILD_SA

Phase 1 came up but Phase 2 fails. The IKE log will print received proposals vs configured proposals — find the mismatch (commonly SHA1 vs SHA256, or dhgrp differs):

peer:  AES_CBC/128 SHA256 MODP2048
mine:  AES_CBC/128 SHA1   MODP2048   <-- mismatch

Align them on whichever side is wrong.

7.3 SA up but no traffic flows

Walk this checklist in order:

  1. OPNsense IPsec firewall rule exists for the source/destination subnets (Firewall ▸ Rules ▸ IPsec). The auto-generated pass out on enc0 rule isn't enough — you need an inbound pass rule too.
  2. No outbound NAT on either side rewriting the source. On FortiGate that's set nat disable on the policy. On OPNsense it's a manual No NAT outbound rule.
  3. Routing on the gateways: each side needs a route to the remote subnet via the IPsec interface. On FortiOS the static route is mandatory; on OPNsense it's installed automatically when Policies is enabled on the Child SA.
  4. Routing on the end hosts: their default gateway must be the firewall, or they must have a static route to the remote subnet via the firewall.

7.4 TCP handshake works, data hangs (SSH banner loops, HTTPS stalls)

Classic MTU / MSS problem over IPsec. ESP overhead pushes packets above the path MTU and "DF" set packets get dropped silently somewhere.

Confirm with:

ping -M do -s 1400 10.10.0.10     # likely fails
ping -M do -s 1350 10.10.0.10     # likely succeeds

Fix on OPNsense: Firewall ▸ Settings ▸ Normalization ▸ +, scope to the IPsec interface, TCP, set Max MSS = 1350.

On FortiGate, set TCP MSS on the tunnel interface:

config system interface
    edit "OPNsense-DC"
        set tcp-mss 1350
    next
end

7.5 Asymmetric routing

If one end is L2-adjacent to a host that also lives behind a NAT'ing intermediate gateway, FortiGate (or strongSwan) will see SYN on one interface and ACKs on another and drop the data packets due to TCP sanity checks.

Fix the routing so the path is symmetric. Either:

  • Add a more-specific (/32 or smaller subnet) static route on the firewall pointing to the correct interface.
  • Add a route on the end host that prefers the correct gateway.

If you really can't avoid asymmetry:

config system settings
    set asymroute enable
end

…but treat that as a last resort. It weakens session checks across the whole VDOM.

8. Useful Diagnostic Commands

OPNsense

swanctl --list-conns                      # loaded configuration
swanctl --list-sas                        # current SAs (counters!)
swanctl --initiate --child <uuid>         # bring up a child SA
swanctl --terminate --ike <uuid>          # tear down
configctl ipsec reload                    # apply config changes
pfctl -sr | grep enc0                     # active firewall rules on IPsec
pfctl -ss | grep <ip>                     # state table
tcpdump -ni enc0                          # decrypted traffic
tcpdump -ni pflog0                        # firewall drops

FortiGate

get vpn ipsec tunnel summary
diagnose vpn ike gateway list name <p1>
diagnose vpn tunnel list name <p2>
diagnose sniffer packet any "host x and host y" 4 0 l
diagnose firewall iprope lookup <src> <sport> <dst> <dport> <proto> <iface>
diagnose debug reset
diagnose debug application ike -1
diagnose debug flow filter addr <ip>
diagnose debug flow show function-name enable
diagnose debug flow trace start 20
diagnose debug enable

The iprope lookup command is gold — it tells you exactly which firewall policy ID a packet would match, so you can be sure the right one is winning.


9. Wrap-Up

The pieces aren't complicated individually:

  1. Identical IKE/ESP proposals on both sides.
  2. Identical traffic selectors on both sides.
  3. PSK and IDs that match.
  4. A static route to the remote subnet on each firewall.
  5. Firewall policies allowing both directions.
  6. No NAT on the tunnel path.
  7. MSS clamp on the tunnel interface.
  8. Symmetric routing for the end hosts.

Get those right and the tunnel just works. Miss any one and you get hours of AUTH_FAILED, NO_PROPOSAL_CHOSEN, or — worst of all — a tunnel that comes up cleanly and silently drops traffic. The diagnostic commands in section 8 will tell you which of the eight you missed; don't guess.


If this saved you an evening of debugging, share it with whoever's about to do the same setup tomorrow.