IPsec Site-to-Site Tunnels with strongSwan & VTI Interfaces on Linux Servers

IPsec Site-to-Site Tunnels
Verified Answer

To build a route-based IPsec site-to-site tunnel on Linux, configure strongSwan with IKEv2 charon-systemd and attach traffic to a Virtual Tunnel Interface (VTI) using XFRM marks. This exposes the encrypted link as a standard Linux network device rather than static policy selectors. You can then run OSPF, BGP, or static ip route rules directly over the VTI interface.

Route-Based IPsec Architecture Using strongSwan and Linux VTI

Traditional policy-based IPsec tunnels bind encryption directly to static XFRM traffic selectors, forcing administrators to rewrite security policies whenever subnets change and complicating dynamic routing. Pairing strongSwan IKEv2 with Linux Virtual Tunnel Interfaces (vti) decouples cryptography from IP forwarding, enabling standard kernel routing tables, BGP/OSPF daemons, and firewall zones over encrypted bare-metal links.

Core Stack Covered: strongSwan swanctl (VICI), Linux XFRM mark-based VTI, IKEv2 AES-256-GCM/ChaCha20-Poly1305, MTU/MSS clamping, and FRR BGP failover.

Linking branch offices or multi-region nodes to Linux dedicated servers with policy-based IPsec forces rigid XFRM selector edits whenever subnets change. Virtual Tunnel Interfaces decouple IKEv2 cryptography from kernel routing, though MTU overhead and asymmetric paths require careful tuning. Follow this walkthrough for swanctl configuration, BGP failover, and verification.

Rigid Policy Selectors

Static XFRM traffic selectors break dynamic routing and require manual tunnel reconfiguration whenever internal server subnets expand.

MTU & Crypto Overhead

IPsec encapsulation shrinks effective payload size, causing silent packet drops unless TCP MSS clamping and interface MTUs align.

Validate VTI & Routing

Test swanctl IKEv2 handshakes, inspect XFRM interface counters, and verify BGP route convergence across redundant VTI links.

Kernel Modules, Sysctl & Firewall Prerequisites for VTI

Before configuring strongSwan, verify that your Linux kernel includes the ip_vti, xfrm_user, and af_key modules, and that your perimeter firewall permits UDP ports 500 (IKE), 4500 (NAT-T), and IP protocol 50 (ESP). If your dedicated server sits behind a stateful firewall or you manage host rules with nftables/ufw, ensure that XFRM-decrypted packets are not dropped by reverse-path filtering. For broader host perimeter hardening, review our Linux server security hardening guide.

Sysctl & Kernel Requirements

  • IPv4/IPv6 Forwarding: Enable net.ipv4.ip_forward=1 so packets arriving on the VTI interface can traverse to internal LAN or container bridges.
  • Disable Policy on VTI Device: Set disable_policy=1 and disable_xfrm=1 on the VTI interface itself so decrypted traffic is not re-evaluated against global XFRM policies in a loop.
  • Relax Reverse-Path Filtering: Asymmetric multi-path tunnels require rp_filter=2 (loose) or 0 on VTI interfaces; strict rp_filter=1 silently drops valid return packets.
  • Hardware AES-NI Verification: Confirm CPU flags include aes and pclmulqdq so kernel AES-GCM runs at multi-gigabit line rate.
Terminal / Bash

# Verify AES-NI CPU support and load VTI kernel modules
grep -E 'aes|pclmulqdq' /proc/cpuinfo | head -n 2
modprobe ip_vti xfrm_user

# Persist sysctl settings for routing and VTI handling
cat <<'EOF' > /etc/sysctl.d/99-ipsec-vti.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
EOF
sysctl --system

On Debian 12 and Ubuntu 24.04 LTS, install strongswan, strongswan-swanctl, and charon-systemd. Using swanctl (the modern VICI-based configuration format) is strongly preferred over legacy ipsec.conf, which is deprecated upstream and lacks clean structured reload semantics.

Policy-Based IPsec vs. VTI vs. XFRM Interfaces

Linux supports three distinct IPsec architectures. Selecting the right model depends on whether you need dynamic routing, multi-tunnel redundancy, or compatibility with legacy hardware appliances such as Cisco ASA, Palo Alto, or AWS Site-to-Site VPN.

Architecture Kernel Mechanism Dynamic Routing (BGP/OSPF) Multi-Tunnel / Overlapping Subnets Operational Complexity
Policy-Based IPsec XFRM policies bound to IP/CIDR selectors Not supported natively Requires manual policy ordering; fragile Low for 1–2 static subnets
VTI (ip_vti) Virtual tunnel interface matched via XFRM mark Full support (FRR, BIRD) Clean per-interface mark isolation Moderate; requires disable_policy=1
XFRM Interface (xfrm) Native if_id binding (Kernel 4.19+) Full support (FRR, BIRD) Supports IPv4+IPv6 dual-stack on one link Low–Moderate; cleanest modern option

VTI remains the most widely supported route-based standard across third-party firewall appliances and cloud VPN gateways, while Linux xfrm interfaces (using if_id) offer an even cleaner alternative when both endpoints run Linux kernels 4.19+. In both cases, strongSwan negotiates 0.0.0.0/0 <-> 0.0.0.0/0 traffic selectors and lets the kernel routing table decide which prefixes enter the tunnel.

Step-by-Step strongSwan swanctl & VTI Tunnel Deployment

In this example, Node A (public IP 203.0.113.10, tunnel inner IP 169.254.10.1/30) connects to Node B (public IP 198.51.100.20, tunnel inner IP 169.254.10.2/30) to route internal private subnets 10.10.0.0/16 and 10.20.0.0/16.

1. Create the Persistent VTI Interface

Configure the vti0 device with a unique XFRM key/mark (100) and set the interface MTU to 1400 bytes to leave headroom for ESP and UDP/NAT-T encapsulation headers.

Terminal / Bash

# Create vti0 interface on Node A
ip link add vti0 type vti local 203.0.113.10 remote 198.51.100.20 key 100
ip addr add 169.254.10.1/30 dev vti0
ip link set vti0 mtu 1400 up

# Disable XFRM policy lookup and strict rp_filter on vti0
sysctl -w net.ipv4.conf.vti0.disable_policy=1
sysctl -w net.ipv4.conf.vti0.disable_xfrm=1
sysctl -w net.ipv4.conf.vti0.rp_filter=0

# Route remote private subnet over vti0
ip route add 10.20.0.0/16 dev vti0

To persist vti0 across reboots, place the link definition inside a systemd-networkd .netdev and .network pair or a post-up hook in /etc/network/interfaces, and ensure strongswan starts after network-online.target.

2. Configure strongSwan swanctl.conf

Disable automatic route installation in /etc/strongswan.d/charon.conf (set install_routes = no) so strongSwan does not inject conflicting policy routes into table 220. Then define the IKEv2 connection with mark_in = 100 and mark_out = 100 matching your vti0 key.

Terminal / Bash

cat <<'EOF' > /etc/swanctl/conf.d/site-to-site-vti.conf
connections {
  dc-nyc-to-fra {
    version = 2
    local_addrs = 203.0.113.10
    remote_addrs = 198.51.100.20
    proposals = aes256gcm16-prfsha384-ecp384
    dpd_delay = 15s
    dpd_timeout = 45s
    rekey_time = 3600s
    mobike = no

    local {
      auth = psk
      id = @dc-nyc.example.net
    }
    remote {
      auth = psk
      id = @dc-fra.example.net
    }

    children {
      vti-child {
        local_ts = 0.0.0.0/0
        remote_ts = 0.0.0.0/0
        esp_proposals = aes256gcm16-ecp384
        mark_in = 100
        mark_out = 100
        start_action = trap
        dpd_action = restart
        rekey_time = 1800s
      }
    }
  }
}

secrets {
  ike-dc-fra {
    id = @dc-fra.example.net
    secret = "ReplaceWith-64Char-HighEntropy-PSK-Generated-Via-OpenSSL"
  }
}
EOF

chmod 600 /etc/swanctl/conf.d/site-to-site-vti.conf
swanctl --load-all
swanctl --initiate --child vti-child

3. Permit IPsec & VTI Forwarding in nftables

Ensure your host firewall allows IKEv2 negotiation on the WAN interface and forwards decrypted traffic traversing vti0:

Terminal / Bash

nft add rule inet filter input udp dport { 500, 4500 } accept
nft add rule inet filter input ip protocol esp accept
nft add rule inet filter forward iifname "vti0" accept
nft add rule inet filter forward oifname "vti0" accept

Crypto Offload, MSS Clamping & Throughput Verification

Even with hardware AES-NI, unoptimized VTI tunnels often suffer from TCP stalls or asymmetric throughput caused by IP fragmentation and single-core encryption bottlenecks. Applying TCP MSS clamping and verifying XFRM state counters ensures wire-speed stability.

SQL / Query

# Clamp TCP MSS to 1360 bytes on vti0 to prevent PMTUD blackholes
nft add rule inet filter forward oifname "vti0" tcp flags syn tcp option maxseg size set 1360
nft add rule inet filter forward iifname "vti0" tcp flags syn tcp option maxseg size set 1360

# Verify active IKEv2 SA and XFRM kernel state/policies
swanctl --list-sas
ip xfrm state
ip xfrm policy

# Test end-to-end tunnel reachability and packet counters
ping -c 5 -I 169.254.10.1 169.254.10.2
ip -s link show vti0

When scaling above 5 Gbps on multi-core bare-metal servers, enable pcrypt kernel crypto parallelization (modprobe pcrypt) or configure RSS/RPS across NIC queues so ESP encryption is distributed across multiple CPU cores rather than pinning a single softirq thread. Without multi-core crypto distribution, a single 3.5 GHz core typically saturates around 3–4 Gbps of AES-256-GCM traffic, leaving the remaining 31 or 63 cores idle while packet drops climb in /proc/net/softnet_stat. You can inspect per-CPU softirq load with mpstat -P ALL 1 while running an iperf3 multi-stream test across the VTI link.

Additionally, verify that your swanctl.conf Dead Peer Detection (DPD) timers match your failover SLA. Setting dpd_delay = 15s and dpd_timeout = 45s ensures stale Security Associations are torn down within 45 seconds if a remote ISP circuit drops silently, rather than waiting for the default 1-hour IKE rekey interval. If you are deciding whether your team should manage complex multi-site crypto routing in-house or offload perimeter operations, compare operational models in our managed vs. unmanaged dedicated servers comparison.

Diagnosing IKEv2/XFRM Faults & Safe Rollback

When a VTI tunnel negotiates successfully in swanctl --list-sas but drops packets, the culprit is almost always an XFRM mark mismatch, a missing disable_policy=1 sysctl, or an overlapping route in routing table 220.

Systematic Fault Isolation

  • Tunnel Up, Zero Return Packets: Run ip -s xfrm state and watch replay-window and byte counters. If outbound bytes increment but inbound stays zero, check whether the remote firewall drops ESP (protocol 50) or whether rp_filter=1 on vti0 is discarding packets.
  • Large HTTP/SSH Transfers Hang: Small ICMP pings succeed while TLS handshakes stall. This is a classic Path MTU blackhole; verify that TCP MSS clamping is set to 1360 or lower on both sides.
  • Routing Loop on Encrypted Outer Packets: If 0.0.0.0/0 traffic selectors are installed into table 220 by mistake, the outer ESP packet tries to route back into vti0. Confirm charon.install_routes = no in /etc/strongswan.d/charon.conf.

Clean Teardown & Rollback

To tear down the VTI tunnel cleanly without interrupting non-tunnel WAN traffic:

Terminal / Bash

swanctl --terminate --ike dc-nyc-to-fra
ip route del 10.20.0.0/16 dev vti0
ip link del vti0
ip xfrm state flush
ip xfrm policy flush

Dynamic BGP Failover Over Redundant VTI Tunnels

Because VTI devices behave like standard point-to-point interfaces, pairing two VTI tunnels (vti0 via ISP-A and vti1 via ISP-B) with FRRouting (FRR) BGP turns static site-to-site IPsec into an active-active or active-standby WAN fabric. Each VTI endpoint receives a /30 link-local or RFC 1918 transit address, and FRR exchanges internal 10.0.0.0/8 prefixes over eBGP sessions with Bidirectional Forwarding Detection (BFD) enabled for sub-second link failure detection.

Terminal / Bash

# Example FRR BGP + BFD snippet for redundant VTI peers
vtysh -c "configure terminal" \
  -c "router bgp 65010" \
  -c "neighbor 169.254.10.2 remote-as 65020" \
  -c "neighbor 169.254.10.2 bfd" \
  -c "address-family ipv4 unicast" \
  -c "network 10.10.0.0/16" \
  -c "maximum-paths 2"

When vti0 experiences packet loss or an upstream carrier outage, BFD tears down the BGP adjacency within 900 milliseconds and shifts all outbound traffic onto vti1 without manual intervention or IKEv2 policy rewrites. For production deployments, combine this with systemd service dependencies so frr.service starts strictly after strongswan.service and your VTI netdev units are up. To prevent asymmetric routing during maintenance windows, configure graceful BGP shutdown (RFC 8326) by applying the well-known GRACEFUL_SHUTDOWN community (65535:0) on the target VTI peer for 60 seconds before terminating the IKEv2 child SA. This drains active TCP flows cleanly onto the secondary tunnel without dropping persistent database replication or API connections.

Frequently Asked Questions

Why use VTI instead of policy-based IPsec on Linux dedicated servers?

VTI exposes the encrypted tunnel as a standard Layer 3 interface (vti0), allowing you to use normal kernel routing tables, BGP/OSPF failover via FRR, ECMP load balancing, and interface-based firewall rules without rewriting IKEv2 traffic selectors.

What happens if I forget to set disable_policy=1 on the VTI interface?

Without net.ipv4.conf.vti0.disable_policy=1, decrypted packets emerging from the VTI device are re-checked against XFRM inbound policies and dropped silently by the kernel if no matching unencrypted policy exists.

Which encryption cipher offers the best throughput on bare-metal Linux?

aes256gcm16 (or aes128gcm16) delivers the highest throughput on x86_64 servers equipped with Intel/AMD AES-NI and PCLMULQDQ instructions because authenticated encryption executes in a single hardware-accelerated pass.

Can strongSwan VTI tunnels run across NAT without a static public IP on one side?

Yes, UDP encapsulation (NAT-T on port 4500) works with VTI, provided the initiator connects to a known static responder IP and the responder’s vti interface uses remote any or a modern xfrm interface with if_id.

How do I monitor VTI tunnel uptime and packet drops in production?

Monitor ip -s link show vti0 for TX/RX errors, export swanctl --list-sas state via a Prometheus textfile collector, and track kernel XFRM error counters in /proc/net/xfrm_stat.

Build Encrypted Multi-Region Mesh Links on 10Gbps Bare Metal

Interconnect your data centers and private cloud VPCs with AES-NI accelerated Linux dedicated servers, dedicated IPv4/IPv6 allocations, and low-latency global routing.

Launch Your Dedicated Network Node