Skip to content

IKEv2 mobile clients with strongSwan

How to configure strongSwan as an IKEv2 gateway for iOS, macOS, Windows, and Android mobile clients — EAP authentication, MOBIKE roaming, and the certificate quirks each OS enforces.

IKEv2 with EAP is the only VPN protocol every major mobile OS speaks natively without an app install. macOS, iOS, Windows, and Android all dial it; ChromeOS too with caveats. We use strongSwan as the gateway for this scenario when clients want a “configuration profile” experience and cannot install OpenVPN/WireGuard apps everywhere. This article is the working server config with notes on the certificate fields each OS is fussy about and how MOBIKE keeps the tunnel up as users roam between Wi-Fi and cellular.

How to verify

Before configuring, confirm strongSwan is the swanctl-style install and that the FQDN your clients will hit matches the server cert exactly.

swanctl --version
ls /etc/swanctl/conf.d/
openssl x509 -in /etc/swanctl/x509/server.crt -noout -text | \
  grep -E 'Subject:|DNS:|Extended Key Usage' -A1

If the SAN does not list the FQDN clients use, iOS and Android will refuse the connection silently. macOS will show a cert dialog and let the user override; do not rely on that.

What’s happening

The mobile clients all speak IKEv2 with the same general shape but enforce different cert and EAP details:

  • iOS / macOS — strict SAN check. Must include the FQDN clients dial. Trusts a cert chain rooted at any trusted CA in the system keychain (or a profile-installed CA).
  • Windows — requires serverAuth and ikeIntermediate extended key usage. Without ikeIntermediate, Windows aborts with “policy match failure.”
  • Android — strict SAN check, uses the strongSwan client app for cert-import flows. Native VPN supports IKEv2 with PSK or username/password since Android 12; the strongSwan app is more capable.

EAP-MSCHAPv2 is the workhorse for “username + password” flows because every OS supports it. For higher security, use EAP-TLS with a per-user client cert — supported by all four but requires more deployment plumbing.

MOBIKE (RFC 4555) lets a client change source IP without renegotiating the tunnel. When a phone moves from Wi-Fi to cellular, the tunnel survives. Without MOBIKE, the SA dies and the phone re-establishes — usually fine, but disruptive for long-lived TCP connections.

The procedure

  1. Issue a server certificate with the right extensions.

    cd /etc/swanctl
    pki --gen --type ed25519 > private/server.key
    pki --pub --in private/server.key | \
      pki --issue --cacert x509ca/ca.crt --cakey private/ca.key \
          --dn "CN=vpn.example.org" \
          --san vpn.example.org \
          --flag serverAuth --flag ikeIntermediate \
          --lifetime 730 > x509/server.crt

    The --san is the FQDN clients dial. The two flags satisfy Windows.

  2. Write /etc/swanctl/conf.d/mobile.conf.

    connections {
        mobile {
            version = 2
            proposals = aes256gcm16-prfsha384-ecp384,aes256-sha256-modp2048
            pools = mobile-pool
            rekey_time = 24h
            fragmentation = yes
            dpd_delay = 30s
            dpd_timeout = 120s
            send_certreq = no
            mobike = yes
    
            local_addrs = %any
            local {
                auth = pubkey
                certs = server.crt
                id = vpn.example.org
            }
            remote {
                auth = eap-mschapv2
                eap_id = %any
            }
            children {
                net {
                    local_ts = 0.0.0.0/0
                    esp_proposals = aes256gcm16-ecp384,aes256-sha256
                }
            }
        }
    }
    
    pools {
        mobile-pool {
            addrs = 10.30.0.0/24
            dns = 1.1.1.1, 9.9.9.9
        }
    }
    
    secrets {
        eap-alice {
            id = alice
            secret = "VeryLongPassphraseGoesHere"
        }
    }
  3. Load and confirm.

    swanctl --load-all --noprompt
    swanctl --list-conns
    swanctl --list-certs
  4. Distribute the CA certificate to the client OS. On macOS/iOS, ship a .mobileconfig profile bundling the CA and the VPN settings. On Windows, install the CA into “Trusted Root Certification Authorities” via GPO or Intune. On Android, install via the strongSwan app or system VPN profile.

  5. Configure the client with these values:

    • Server: vpn.example.org (the SAN-listed FQDN)
    • Remote ID: vpn.example.org (must match server id)
    • Local ID: alice (the EAP identity)
    • Authentication: Username/password (EAP-MSCHAPv2)
    • Username: alice
    • Password: the secret from swanctl.conf
  6. Open the firewall.

    ufw allow 500/udp
    ufw allow 4500/udp
    sysctl -w net.ipv4.ip_forward=1
    iptables -t nat -A POSTROUTING -s 10.30.0.0/24 -o eth0 -j MASQUERADE
    iptables -A FORWARD -m policy --pol ipsec --dir in  -s 10.30.0.0/24 -j ACCEPT
    iptables -A FORWARD -m policy --pol ipsec --dir out -d 10.30.0.0/24 -j ACCEPT
  7. Watch a connection come up.

    journalctl -u strongswan -f
    swanctl --list-sas

    Verify MOBIKE is in the SA’s extension list: MOBIKE_SUPPORTED should appear.

Common pitfalls

  • Forgetting ikeIntermediate EKU on the server cert — Windows clients fail with cryptic “credentials supplied conflict with an existing set of credentials” or “policy match.” Always include both serverAuth and ikeIntermediate.
  • Mismatch between local.id and the SAN — iOS rejects silently. The two must be identical strings.
  • Pushing IPv6 DNS without IPv6 default route — clients will time out on every DNS query because they have an IPv6 resolver they cannot reach.
  • Disabling MOBIKE for “simplicity” — mobile users will see a 5-10 second blip every time they switch network. Keep it on.
  • Storing EAP secrets in committed YAML — they are passwords. Split secrets into /etc/swanctl/secrets/ and exclude from version control.

In the engagements we run, IKEv2 with EAP is the right choice for BYOD environments where you cannot dictate the VPN client. The configuration above is the gateway; the Managed Operations work is keeping the cert from expiring at 3 a.m., rotating EAP credentials on schedule, and producing audit reports of who connected from where.