strongSwan site-to-site VPN with swanctl.conf: a full example

A complete swanctl.conf example for an IKEv2 site-to-site tunnel from a Linux gateway to an IPsec VPN server, with the firewall rules around it and a route-based variant.

strongSwanLinux · 198.51.100.20IPsec VPN server203.0.113.10swanctl.conf · exampleconnections { vpn-server { proposals = aes256-sha256-ecp384 children { lan { esp_proposals = aes256gcm16-ecp384 } }}

The short answer

A strongSwan site-to-site VPN on a current Linux distribution is configured in swanctl.conf, not the old ipsec.conf. You describe the tunnel in a connections section (the IKE SA, with children for the ESP SAs and the subnets they protect), put the pre-shared key in secrets, load it all with swanctl --load-all and check it with swanctl --list-sas. The daemon is charon-systemd, run by a systemd unit whose name depends on the distribution.

This guide is a complete strongSwan swanctl configuration example for a Linux gateway at 198.51.100.20 (LAN 192.168.10.0/24) connecting to an IPsec VPN server at 203.0.113.10 (networks 10.10.0.0/16) over IKEv2. It covers the policy-based setup first, then a route-based variant with XFRM interfaces. Everything applies to strongSwan 5.9 and 6.x unless noted.

Why swanctl and not ipsec.conf? The ipsec starter and its ipsec.conf/ipsec.secrets files are the legacy interface. They have been deprecated for years and are no longer built by default from strongSwan 6.0, so guides that still use them leave you with a configuration you will have to rewrite. swanctl talks to the daemon over the VICI interface, reloads configuration without dropping unrelated tunnels, and its output is far more useful when debugging.

Values that must match on both sides

SettingstrongSwan (branch)VPN server
Public IP / IKE identity198.51.100.20203.0.113.10
Protected networks192.168.10.0/2410.10.0.0/16
IKE versionIKEv2IKEv2
IKE proposalaes256-sha256-ecp384AES-256, SHA-256, DH group 20
IKE lifetime8 h (28800 s)28800 s
ESP proposalaes256gcm16-ecp384AES-256-GCM, PFS group 20
Child SA lifetime1 h (3600 s)3600 s
AuthenticationPre-shared keySame pre-shared key
Dead peer detectionOnOn

strongSwan proposals are written as one string of algorithm keywords. aes256-sha256-ecp384 means AES-256-CBC, HMAC-SHA-256 integrity (also used as the PRF) and DH group 20. aes256gcm16-ecp384 in esp_proposals means AES-256-GCM with a 16-byte ICV, and the DH group in an ESP proposal turns on PFS. strongSwan also accepts GCM for IKE (for example aes256gcm16-prfsha384-ecp384) if the server offers it.

Install strongSwan and find the service name

Install the swanctl-based daemon, not the legacy starter:

  • Debian and Ubuntu: apt install charon-systemd, which pulls in strongswan-swanctl. The unit is strongswan.service. The strongswan-starter package and unit are the legacy ipsec.conf stack; don't run both. Configuration lives in /etc/swanctl/.
  • Fedora and RHEL-family (EPEL): dnf install strongswan. The configuration directory is /etc/strongswan/swanctl/. Recent packages run swanctl through strongswan.service; older ones used strongswan-swanctl.service.

If in doubt, systemctl list-unit-files 'strongswan*' shows what your package installed. The rest of this guide uses /etc/swanctl/; adjust the path on RHEL-family systems.

Example strongSwan site-to-site configuration (policy-based)

Example configuration for a strongSwan gateway, saved as /etc/swanctl/conf.d/vpn-server.conf (files in conf.d are included by the default swanctl.conf):

# Example configuration for a strongSwan gateway (swanctl.conf syntax)
# Branch: 198.51.100.20, LAN 192.168.10.0/24
# VPN server: 203.0.113.10, networks 10.10.0.0/16

connections {
  vpn-server {
    version = 2
    local_addrs  = 198.51.100.20
    remote_addrs = 203.0.113.10

    # IKE: AES-256-CBC, SHA-256, DH group 20; rekey every 8 h
    proposals  = aes256-sha256-ecp384
    rekey_time = 8h

    # Dead peer detection: check the peer after 30 s of silence
    dpd_delay = 30s

    local {
      auth = psk
      id   = 198.51.100.20
    }
    remote {
      auth = psk
      id   = 203.0.113.10
    }

    children {
      lan {
        local_ts  = 192.168.10.0/24
        remote_ts = 10.10.0.0/16

        # ESP: AES-256-GCM with PFS group 20; rekey every hour
        esp_proposals = aes256gcm16-ecp384
        rekey_time    = 1h

        # Bring the tunnel up at load, and again on traffic or failure
        start_action = trap|start
        dpd_action   = restart
        close_action = start
      }
    }
  }
}

secrets {
  ike-vpn-server {
    id-1   = 198.51.100.20
    id-2   = 203.0.113.10
    secret = ""
  }
}

Use a long random pre-shared key, for example 32 or more characters from a password generator, and keep the file readable by root only (chmod 600). The same key goes on the VPN server.

A few notes on the choices:

  • start_action = trap|start needs strongSwan 5.9.6 or newer. On older 5.9 releases use start (initiate at load) or trap (initiate on traffic).
  • If the server is the side that always initiates, set start_action = none and let strongSwan respond.
  • If the branch has more than one LAN, list them comma-separated in local_ts; the server must list the same networks as its remote side.
  • When the branch sits behind NAT, keep local_addrs empty or set to its private address, but leave id at the public IP so the server recognises it. NAT traversal is automatic.

Forwarding, NAT exemption and MSS clamping

The gateway has to forward packets between the LAN and the tunnel, must not masquerade them, and should clamp the TCP MSS. With iptables:

# Example configuration: forwarding and firewall on the strongSwan gateway
sysctl -w net.ipv4.ip_forward=1   # persist in /etc/sysctl.d/

# Allow IKE, NAT-T and ESP from the server
iptables -A INPUT -s 203.0.113.10 -p udp -m multiport --dports 500,4500 -j ACCEPT
iptables -A INPUT -s 203.0.113.10 -p esp -j ACCEPT

# Don't masquerade traffic that goes into the tunnel (insert above MASQUERADE)
iptables -t nat -I POSTROUTING -s 192.168.10.0/24 -d 10.10.0.0/16 -j ACCEPT

# Clamp TCP MSS on SYNs crossing the tunnel
iptables -t mangle -A FORWARD -s 192.168.10.0/24 -d 10.10.0.0/16 \
  -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1360
iptables -t mangle -A FORWARD -s 10.10.0.0/16 -d 192.168.10.0/24 \
  -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1360

With nftables the same ideas apply: an accept in the NAT postrouting chain before masquerade, and tcp option maxseg size set 1360 on SYN packets in the forward chain. Instead of subnets you can also match -m policy --dir out --pol ipsec (iptables) or meta ipsec exists (nftables) for traffic that IPsec will encrypt.

Load and start

systemctl enable --now strongswan   # unit name: see the section above
swanctl --load-all                  # load connections and secrets
swanctl --initiate --child lan      # only needed without start_action

Route-based variant with XFRM interfaces

Policy-based works well for a few fixed subnets. If you prefer routing (several prefixes, dynamic routing, or one tunnel per peer that you treat like an interface), use an XFRM interface. strongSwan supports them since 5.8.0, on Linux 4.19 or newer. The traffic selectors become 0.0.0.0/0 on both sides, and the routing table decides what enters the tunnel. The server must be configured route-based (VTI) too, with matching selectors.

Example configuration for the route-based variant; only the changed lines are shown:

# Example configuration: route-based variant (XFRM interface, if_id 42)
connections {
  vpn-server {
    # ...same version, addresses, proposals, auth as above...
    if_id_in  = 42
    if_id_out = 42

    children {
      lan {
        local_ts  = 0.0.0.0/0
        remote_ts = 0.0.0.0/0
        esp_proposals = aes256gcm16-ecp384
        rekey_time    = 1h
        start_action  = start
        dpd_action    = restart
      }
    }
  }
}

# Create the interface, give it the inside address, route the far side
ip link add ipsec0 type xfrm dev eth0 if_id 42
ip addr add 169.254.100.2/30 dev ipsec0
ip link set ipsec0 up
ip route add 10.10.0.0/16 dev ipsec0

strongSwan doesn't install routes for CHILD_SAs with an outbound interface ID, so the ip route line is yours to manage (or let a routing daemon do it). Create the interface at boot with systemd-networkd, NetworkManager or a small unit. Apply the MSS clamping rules to traffic leaving ipsec0. For more on the trade-offs, see IPsec configuration examples.

Verify the tunnel

swanctl --list-conns          # is the connection loaded as expected?
swanctl --list-sas            # IKE SA and CHILD_SAs currently up
swanctl --log                 # live daemon log (Ctrl+C to stop)
journalctl -u strongswan -f   # same log via systemd
ip xfrm state                 # kernel SAs
ip xfrm policy                # kernel policies (policy-based)
ping -I 192.168.10.1 10.10.0.1

A healthy tunnel looks like this in swanctl --list-sas (illustrative output, SPIs shortened):

vpn-server: #1, ESTABLISHED, IKEv2, 5d1e...a7_i* 9c2b...44_r
  local  '198.51.100.20' @ 198.51.100.20[500]
  remote '203.0.113.10' @ 203.0.113.10[500]
  AES_CBC-256/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_384
  established 95s ago, rekeying in 7h50m
  lan: #1, reqid 1, INSTALLED, TUNNEL, ESP:AES_GCM_16-256/ECP_384
    installed 95s ago, rekeying in 55m, expires in 64m
    in  c3a1b2d4,  12840 bytes,   107 packets,     2s ago
    out c9e8f7a6,  13104 bytes,   109 packets,     2s ago
    local  192.168.10.0/24
    remote 10.10.0.0/16

Check three things: the IKE SA is ESTABLISHED with the algorithms you expect, the CHILD_SA is INSTALLED with the right subnets, and both in and out counters grow while you ping. If the ports show [4500], NAT traversal is in use, which is fine.

Common problems

Proposal mismatch

NO_PROPOSAL_CHOSEN in the log means no common algorithm set. The log prints both the proposals received and the ones configured; compare them. Typical causes: a different DH group, PFS on one side only (strongSwan includes the DH group in esp_proposals, so the server must use PFS too) or GCM configured on one side and CBC on the other.

ID mismatch

Errors such as no matching peer config found or AUTHENTICATION_FAILED usually mean the IDs differ. strongSwan uses the local IP address as ID by default. Behind NAT that is the private address, so set id explicitly as above and make sure the secrets entry has the same IDs. A wrong key gives AUTHENTICATION_FAILED too.

NAT and firewalling

An established tunnel with out counters rising but nothing coming back often means the server lacks a route back to 192.168.10.0/24 or masquerades the traffic. On the strongSwan side, an in counter rising with no replies on the LAN means forwarding or the firewall is blocking. Check UDP 500 and 4500 are open on both ends.

MTU and MSS

Small pings work, large transfers stall: add or lower the MSS clamp, and test with ping -M do -s 1372 10.10.0.1 to find the largest packet that passes. See IPsec troubleshooting for a full checklist.

Running the other end

strongSwan is a fine branch gateway; for a static IP that doesn't depend on the office line, the other end needs a gateway with one. TunnelYard gives you a dedicated IPsec server with its own static public IP, IKEv2 policy-based tunnels, and a config export (the OpenWrt preset uses strongSwan swanctl, or the settings sheet for any other IKEv2 device) so both ends start from the same values. It works the same way with other vendors' firewalls; compare the same tunnel on MikroTik or pfSense.

FAQ

strongSwan swanctl site-to-site VPN: common questions

Should I use swanctl.conf or ipsec.conf for strongSwan?

Use swanctl.conf. The ipsec starter with ipsec.conf and ipsec.secrets is the legacy interface, deprecated for years and no longer built by default from strongSwan 6.0. swanctl talks to the daemon over VICI, reloads configuration without dropping unrelated tunnels, and gives far more useful output when debugging. Load it with swanctl --load-all.

What does aes256-sha256-ecp384 mean in a strongSwan proposal?

It is a strongSwan IKE proposal string: AES-256-CBC encryption, HMAC-SHA-256 integrity (also used as the PRF) and DH group 20, which is ECP-384. For ESP, aes256gcm16-ecp384 means AES-256-GCM with a 16-byte ICV plus PFS with DH group 20. strongSwan also accepts GCM for IKE, for example aes256gcm16-prfsha384-ecp384, if the server offers it.

How do I enable PFS in strongSwan?

Add a DH group to esp_proposals in the child section. For example, esp_proposals = aes256gcm16-ecp384 turns on PFS with DH group 20. The server must use PFS with the same group, otherwise phase 2 fails with NO_PROPOSAL_CHOSEN. strongSwan logs both the proposals received and the ones configured, so compare them when the child SA will not install.

Which strongSwan package and service should I install on Ubuntu?

On Debian and Ubuntu, install charon-systemd, which pulls in strongswan-swanctl; the unit is strongswan.service and configuration lives in /etc/swanctl/. Do not also run the legacy strongswan-starter package. On Fedora and RHEL-family systems, dnf install strongswan uses /etc/strongswan/swanctl/. systemctl list-unit-files 'strongswan*' shows what your package installed.

How do I build a route-based strongSwan tunnel with an XFRM interface?

Set if_id_in and if_id_out on the connection, use 0.0.0.0/0 as both traffic selectors, and create the interface with ip link add ipsec0 type xfrm dev eth0 if_id 42. XFRM interfaces need strongSwan 5.8.0 or newer on Linux 4.19 or newer. strongSwan does not install routes for them, so add ip route add 10.10.0.0/16 dev ipsec0 yourself. The server must be route-based too.

How do I check that a strongSwan IPsec tunnel is up?

Run swanctl --list-sas. A healthy tunnel shows the IKE SA as ESTABLISHED with the expected algorithms, the CHILD_SA as INSTALLED with the right subnets, and both in and out counters growing while you ping. Port 4500 in the output means NAT traversal is in use. swanctl --log streams the daemon log. See IPsec troubleshooting for failures.