Deploying a robust IKEv2 VPN on FreeBSD gives organisations and developers a balance of modern cryptography, compatibility across client platforms, and the stability of FreeBSD as a network operating system. This guide walks through a practical, secure deployment using strongSwan on FreeBSD, covering package install, certificate-based authentication, detailed configuration snippets, network and firewall considerations, and operational hardening tips. It targets sysadmins, developers and site operators who need a production-ready IKEv2 server on FreeBSD.
Why IKEv2 on FreeBSD?
IKEv2 is the modern IKE protocol: it provides efficient rekeying, NAT traversal (NAT-T), MOBIKE support, and excellent cross-platform client support (Windows, macOS, iOS, Android, Linux). FreeBSD is a popular choice for network appliances and VPN gateways because of its stability, predictable kernel interfaces and mature firewalling via pf. Using strongSwan on FreeBSD combines an actively maintained IKEv2 implementation with the reliability of FreeBSD.
High-level deployment model
The recommended, simple and widely-compatible model used here is:
- strongSwan userland (charon) as the IKEv2 daemon.
- Certificate-based authentication for the server and optional client certificates (stronger than PSK).
- Policy-based IPsec with client virtual addresses (rightsourceip) and NAT/PF rules for routing client traffic out to the Internet.
- System hardening: kernel and sysctl tuning, limiting ciphers, and secure private key handling.
Prerequisites and OS setup
Assume a FreeBSD host with a public IPv4 address (A.B.C.D) and the usual administrative access (root). Update packages and install strongSwan:
pkg update && pkg upgrade
pkg install strongswan
Enable strongSwan at boot by adding to /etc/rc.conf:
strongswan_enable="YES"
Enable IP forwarding and other relevant kernel settings in /etc/sysctl.conf:
net.inet.ip.forwarding=1— allow IPv4 forwarding.net.inet6.ip6.forwarding=1— if you want IPv6 forwarding.net.inet.ip.fastforwarding=1— improves throughput on some hardware (test before enabling in production).
Firewall and NAT: pf setup
Use pf to filter and NAT traffic originating from VPN clients. Example /etc/pf.conf snippet (adapt interfaces and networks):
# Interfaces
ext_if = "em0"
vpn_net = "10.10.10.0/24"
set skip on lo
nat on $ext_if from $vpn_net to any -> ($ext_if)
pass in on $ext_if proto { tcp udp } from any to ( $ext_if ) port { 500, 4500 } keep state
pass in on $ext_if proto esp from any to ($ext_if) keep state
Reload pf with service pf restart or use pfctl after testing rules carefully.
Certificates and PKI (recommended)
Use certificate-based authentication rather than PSKs for better security and manageability. strongSwan includes an easy-to-use PKI toolset.
Generate an RSA/ECDSA CA, server certificate and an optional client certificate:
- Create CA private key and self-signed cert:
ipsec pki --gen --type rsa --size 4096 --outform pem > ca.keyipsec pki --self --ca --in ca.key --dn "CN=Example VPN CA" --outform pem > ca.cert - Create server key and CSR, then sign server cert:
ipsec pki --gen --type rsa --size 3072 --outform pem > server.keyipsec pki --pub --in server.key | ipsec pki --issue --cacert ca.cert --cakey ca.key --dn "CN=vpn.example.com" --san "vpn.example.com" --flag serverAuth --outform pem > server.cert - Create client key and cert (optional for certificate-authenticated clients):
ipsec pki --gen --type rsa --size 3072 --outform pem > client.keyipsec pki --pub --in client.key | ipsec pki --issue --cacert ca.cert --cakey ca.key --dn "CN=user1" --outform pem > client.cert
Place certs and keys under /usr/local/etc/ipsec.d/:
/usr/local/etc/ipsec.d/cacerts/ca.cert/usr/local/etc/ipsec.d/private/server.key/usr/local/etc/ipsec.d/certs/server.cert
Core strongSwan configuration
The minimum files to configure are /usr/local/etc/ipsec.conf, /usr/local/etc/ipsec.secrets and optionally /usr/local/etc/strongswan.conf for logging tuning. Below is an IKEv2-focused example using certificate auth and assigning virtual IPs.
/usr/local/etc/ipsec.conf
Example content:
config setup
charondebug="ike 1, knl 1, cfg 0"
conn ikev2-vpn
auto=add
compress=no
type=tunnel
keyexchange=ikev2
fragmentation=yes
forceencaps=yes
rekey=yes
left=%any
leftid="vpn.example.com"
leftcert=server.cert
leftsendcert=always
leftsubnet=0.0.0.0/0
right=%any
rightid=%any
rightauth=eap-radius, pubkey
rightsendcert=never
rightsourceip=10.10.10.0/24
rightdns=1.1.1.1,8.8.8.8
ike=aes256-sha256-modp2048
esp=aes256gcm16-prfsha256-ecp384
dpdaction=clear
dpddelay=300s
dpdtimeout=1h
Notes:
- leftsubnet=0.0.0.0/0 together with rightsourceip is a common setup to push full-tunnel routing through the VPN. Adjust if you prefer split-tunneling.
- leftid should be a FQDN matching the server certificate SAN to avoid client trust warnings.
- rightauth can be set to
pubkey(client cert) oreap-mschapv2(username/password); combine with RADIUS if you need central authentication. - Limit IKE and ESP proposals to secure, modern algorithms. Avoid legacy DES/3DES and SHA1 where possible.
/usr/local/etc/ipsec.secrets
Example when using certificate-only authentication (server private key):
: RSA "server.key"
If you use EAP/username passwords, add lines like:
user1 : EAP "S3cr3tP@ss"
Optional: Integrate with RADIUS for EAP
For enterprise environments, delegating user authentication to RADIUS (e.g., FreeRADIUS, Microsoft NPS) is common. Install and configure strongSwan’s eap-radius plugin and edit /usr/local/etc/strongswan.conf or ipsec.conf to point at your RADIUS server with shared secret and retry policies. Use TLS client certs for administrators and EAP for end-users.
Routing considerations
With the above policy-based approach, strongSwan assigns clients addresses from the rightsourceip pool. You must ensure these addresses are NATed / routed to the external interface via pf, or route them via explicit routes. The pf NAT rule shown earlier handles NAT to the external interface.
Security hardening and best practices
- Prefer certificates over PSKs. PSKs are easy for initial testing but are less scalable and riskier for production.
- Harden cipher suites: choose AES-GCM or ChaCha20-Poly1305 where available, ECC curves like P-384 or Curve25519 for key agreement, and avoid modp1024/sha1 combinations.
- Protect private keys: limit filesystem permissions, store keys with 600 permissions and owned by root only.
- Limit management plane exposure: allow only necessary ports (UDP 500, UDP 4500 and ESP) on the public interface; block IKE management ports from general internal networks if not required.
- Monitor and log: configure strongSwan logging levels for both normal operation and troubleshooting (store logs centrally or feed to SIEM).
- Keep packages updated: subscribe to FreeBSD security advisory feeds and update strongSwan promptly when security patches are published.
Operational notes and troubleshooting
Useful commands:
service strongswan start|stop|restart— control the daemon.ipsec statusall— show connection and child SA status.ipsec up ikev2-vpn— manually initiate connection (from server side).- Check logs via
/var/log/daemonor the system logging facility; adjust logging in/usr/local/etc/strongswan.confif needed.
Common failures and diagnostic tips:
- Clients can’t connect: verify UDP 500/4500 are reachable; check NAT-T and fragmentation settings if MTU-related failures occur.
- Certificate validation errors: ensure client trusts your CA and the server certificate’s SAN matches the configured
leftid. - No traffic flows after connection: confirm IP forwarding, pf NAT rules, and that assigned client IPs are in the expected subnet and not conflicting with other networks.
Advanced options
For larger deployments consider:
- Using RADIUS or LDAP backend for EAP authentication and accounting.
- Deploying HA pairs with floating IPs (e.g., CARP on FreeBSD) and synchronised configuration for resilience.
- Implementing split DNS or split-tunnel rules using push routes and per-client profiles.
- Enabling connection health monitoring (DPD and lifetimes tuned per SLAs).
Wrap-up
Setting up an IKEv2 VPN on FreeBSD using strongSwan delivers a secure, standards-based solution suitable for corporate and developer environments. Focus on certificate-based authentication, up-to-date cryptography choices, correct pf/NAT routing and logging. The configuration examples above provide a practical, production-oriented baseline you can adapt for single-server or scaled deployments. For further details on strongSwan’s features and FreeBSD-specific integration nuances, consult the respective project documentation and test configurations in a staging environment before production rollout.
For more VPN deployment guides and dedicated-server VPN best practices, visit Dedicated-IP-VPN at https://dedicated-ip-vpn.com/.