Introduction
strongSwan is open-source software for creating virtual private networks using IPsec. Its compatibility with different systems and devices lets you securely connect networks in different locations.
In this article, we will configure a site-to-site VPN using IKEv2 and a pre-shared key (PSK). This will connect your Clouding servers' private network to a network in another location.
We will use “swanctl” to manage the configuration instead of the older procedure based on the “ipsec.conf” and “ipsec.secrets” files.
Instructions and prerequisites
These steps are intended for a new installation on Ubuntu 24.04 LTS or Debian 12/13, using a Linux server as the VPN gateway.
Connect via SSH as root. The “#” symbol before each command indicates that it runs as this user; do not copy the symbol.
If you already have a VPN configured, back up its files and review the installed services before continuing. Do not run the old and new strongSwan services simultaneously for the same connections.
We will use the following details for this example:
| Setting | Clouding | Other location |
|---|---|---|
| VPN gateway public IP | 203.0.113.10 | 198.51.100.20 |
| Private network | 10.20.10.0/24 | 192.168.1.0/24 |
| VPN gateway private IP | 10.20.10.10 | 192.168.1.1 |
Important: the public addresses in the table are reserved for documentation. Replace them with your gateways' actual addresses. Also adapt the private IP addresses and subnets to your setup.
The networks at both ends must be different and must not overlap. The Clouding VPN server and the servers you want to access must be connected to the same private network.
The example assumes that the Clouding public IP is configured directly on the server. If a gateway is behind NAT, adapt its local address and configure port forwarding on the device performing that NAT.
Firewall configuration
Allow UDP ports 500 and 4500 at both ends. The Clouding firewall rules should look similar to those in this screenshot:
If the other gateway has a static public IP, restrict the source of these rules to that address.
You must also allow the required traffic between the private networks in the Clouding firewall profiles, the gateway firewalls, and the destination servers.
In this example, we will force ESP encapsulation over UDP using “encap = yes”, so the tunnel's data traffic will use UDP port 4500.
Installing strongSwan
Update the package list and install strongSwan with support for “swanctl” and systemd, together with the tools we will use:
# apt update
# apt install charon-systemd strongswan-swanctl openssl nanoNext, enable persistent IPv4 forwarding so the server can act as a gateway:
# printf 'net.ipv4.ip_forward=1\n' > /etc/sysctl.d/99-strongswan-forwarding.conf
# sysctl --systemCheck that the change has taken effect:
# sysctl net.ipv4.ip_forwardThe output should show “net.ipv4.ip_forward = 1”. If the other gateway is also a Linux server, enable forwarding there in the same way.
Creating the pre-shared key (PSK)
The pre-shared key authenticates the two gateways. Generate a random key with:
# openssl rand -hex 32Store the result securely. We will use exactly the same text at both ends.
The examples contain “REPLACE_WITH_YOUR_KEY”. Replace this text with the generated key and do not reuse the same key for independent connections.
Configuring the strongSwan connection
On the Clouding server, open “/etc/swanctl/swanctl.conf”:
# nano /etc/swanctl/swanctl.confFor this new installation, use the following configuration, replacing the addresses, networks, and key with your own. If the file already contains connections, do not overwrite them:
connections {
clouding-sede {
version = 2
local_addrs = 203.0.113.10
remote_addrs = 198.51.100.20
proposals = aes256-sha256-modp2048
encap = yes
rekey_time = 2h
dpd_delay = 30s
local {
auth = psk
id = 203.0.113.10
}
remote {
auth = psk
id = 198.51.100.20
}
children {
red-privada {
local_ts = 10.20.10.0/24
remote_ts = 192.168.1.0/24
esp_proposals = aes256gcm16-modp2048
rekey_time = 1h
start_action = trap|start
dpd_action = restart
}
}
}
}
secrets {
ike-clouding-sede {
id-clouding = 203.0.113.10
id-sede = 198.51.100.20
secret = "REPLACE_WITH_YOUR_KEY"
}
}The “connections” block contains the VPN connections. Within each connection, “local” and “remote” define gateway authentication, while “children” defines the traffic protected by IPsec. The “secrets” block contains the pre-shared key.
The addresses in “local_addrs” and “remote_addrs” identify the gateways. The “local_ts” and “remote_ts” fields specify the networks carried through the tunnel.
The identities in “local”, “remote”, and “secrets” must match those configured at the other end. Here, we use the public addresses as identities.
For IKE, we use AES-256, SHA-256, and DH group 14. For ESP, we use AES-256-GCM with a 128-bit authentication tag and PFS using DH group 14. AES-GCM includes integrity protection, so no separate SHA algorithm is added to that proposal.
Save the file and restrict its permissions because it contains the pre-shared key:
# chown root:root /etc/swanctl/swanctl.conf
# chmod 600 /etc/swanctl/swanctl.confBelow, we retain the original article's reference tables, based on the strongSwan 5.9 documentation. Algorithm availability depends on the installed version, plugins, and kernel.
These tables are a compatibility reference, not a recommendation to use every algorithm. Avoid entries marked “s” and options without encryption, such as “null” or AES-GMAC, if you need confidentiality.
The letters in the tables identify the cryptographic libraries and strongSwan plugins implementing each algorithm for IKE.
Algorithms marked “s” are deprecated for security reasons.
| Option | Plugin | Since |
|---|---|---|
| s | Deprecated due to security issues | |
| x | Default cryptographic plugin | See the Plugins column |
| b | Botan cryptographic library | strongSwan 5.7.0 |
| w | wolfSSL cryptographic library | strongSwan 5.8.0 |
| o | OpenSSL cryptographic library | |
| g | Gcrypt cryptographic library | |
| a | AF_ALG userspace cryptographic API for Linux | Linux kernel 2.6.38 |
The following letters identify Linux kernel support for ESP or AH algorithms. The “s” marker indicates an algorithm deprecated for security reasons.
| Option | Since |
|---|---|
| s | Deprecated due to security issues |
| k | Linux kernel 2.6 |
| m | Linux kernel 2.6.33 |
| n | Linux kernel 4.2 |
| p | Compatibility with kernels incorrectly using 96-bit truncation for SHA-256 Linux kernel < 2.6.33 |
| q | For AH, AES-GMAC is negotiated as an ESP encryption algorithm |
Encryption algorithms
| Keyword | Description | IANA | IKE | ESP | Plugins |
|---|---|---|---|---|---|
| 3des | 168-bit 3DES-EDE-CBC | 3 | s x w o g a | s k | des |
| cast128 | 128-bit CAST-CBC | 6 | s o g a | s k | |
| blowfish128 or blowfish | 128-bit Blowfish-CBC | 7 | s x o g a | s k | blowfish |
| blowfish192 | 192-bit Blowfish-CBC | 7 | s x o a | s k | blowfish |
| blowfish256 | 256-bit Blowfish-CBC | 7 | s x o a | s k | blowfish |
| null | No encryption | 11 | w o | k | |
| aes128 or aes | 128-bit AES-CBC | 12 | x b w o g a | k | aes |
| aes192 | 192-bit AES-CBC | 12 | x b w o g a | k | aes |
| aes256 | 256-bit AES-CBC | 12 | x b w o g a | k | aes |
| aes128ctr | 128-bit AES-COUNTER | 13 | x w o g a | k | aes, ctr |
| aes192ctr | 192-bit AES-COUNTER | 13 | x w o g a | k | aes, ctr |
| aes256ctr | 256-bit AES-COUNTER | 13 | x w o g a | k | aes, ctr |
| camellia128 or camellia | 128-bit Camellia-CBC | 23 | o g a | k | |
| camellia192 | 192-bit Camellia-CBC | 23 | o g a | k | |
| camellia256 | 256-bit Camellia-CBC | 23 | o g a | k | |
| camellia128ctr | 128-bit Camellia-COUNTER | 24 | o g a | k | |
| camellia192ctr | 192-bit Camellia-COUNTER | 24 | o g a | k | |
| camellia256ctr | 256-bit Camellia-COUNTER | 24 | o g a | k |
Authenticated encryption algorithms (AEAD)
AEAD algorithms combine encryption and authentication. No separate integrity algorithm is added. When using them for IKE, a pseudo-random function (PRF) must be specified explicitly.
| Keyword | Description | IANA | IKE | ESP | Plugins |
|---|---|---|---|---|---|
| aes128ccm8 or aes128ccm64 | 128-bit AES-CCM with a 64-bit ICV | 14 | x b w o g a | k | aes, ccm |
| aes192ccm8 or aes192ccm64 | 192-bit AES-CCM with a 64-bit ICV | 14 | x b w o g a | k | aes, ccm |
| aes256ccm8 or aes256ccm64 | 256-bit AES-CCM with a 64-bit ICV | 14 | x b w o g a | k | aes, ccm |
| aes128ccm12 or aes128ccm96 | 128-bit AES-CCM with a 96-bit ICV | 15 | x b w o g a | k | aes, ccm |
| aes192ccm12 or aes192ccm96 | 192-bit AES-CCM with a 96-bit ICV | 15 | x b w o g a | k | aes, ccm |
| aes256ccm12 or aes256ccm96 | 256-bit AES-CCM with a 96-bit ICV | 15 | x b w o g a | k | aes, ccm |
| aes128ccm16 or aes128ccm128 | 128-bit AES-CCM with a 128-bit ICV | 16 | x b w o g a | k | aes, ccm |
| aes192ccm16 or aes192ccm128 | 192-bit AES-CCM with a 128-bit ICV | 16 | x b w o g a | k | aes, ccm |
| aes256ccm16 or aes256ccm128 | 256-bit AES-CCM with a 128-bit ICV | 16 | x b w o g a | k | aes, ccm |
| aes128gcm8 or aes128gcm64 | 128-bit AES-GCM with a 64-bit ICV | 18 | x b w o g a | k | aes, gcm |
| aes192gcm8 or aes192gcm64 | 192-bit AES-GCM with a 64-bit ICV | 18 | x b w o g a | k | aes, gcm |
| aes256gcm8 or aes256gcm64 | 256-bit AES-GCM with a 64-bit ICV | 18 | x b w o g a | k | aes, gcm |
| aes128gcm12 or aes128gcm96 | 128-bit AES-GCM with a 96-bit ICV | 19 | x b w o g a | k | aes, gcm |
| aes192gcm12 or aes192gcm96 | 192-bit AES-GCM with a 96-bit ICV | 19 | x b w o g a | k | aes, gcm |
| aes256gcm12 or aes256gcm96 | 256-bit AES-GCM with a 96-bit ICV | 19 | x b w o g a | k | aes, gcm |
| aes128gcm16 or aes128gcm128 | 128-bit AES-GCM with a 128-bit ICV | 20 | x b w o g a | k | aes, gcm |
| aes192gcm16 or aes192gcm128 | 192-bit AES-GCM with a 128-bit ICV | 20 | x b w o g a | k | aes, gcm |
| aes256gcm16 or aes256gcm128 | 256-bit AES-GCM with a 128-bit ICV | 20 | x b w o g a | k | aes, gcm |
| aes128gmac | No encryption, with 128-bit AES-GMAC | 21 | k | ||
| aes192gmac | No encryption, with 192-bit AES-GMAC | 21 | k | ||
| aes256gmac | No encryption, with 256-bit AES-GMAC | 21 | k | ||
| camellia128ccm8 or camellia128ccm64 | 128-bit Camellia-CCM with a 64-bit ICV | 25 | o g a | ||
| camellia192ccm8 or camellia192ccm64 | 192-bit Camellia-CCM with a 64-bit ICV | 25 | o g a | ||
| camellia256ccm8 or camellia256ccm64 | 256-bit Camellia-CCM with a 64-bit ICV | 25 | o g a | ||
| camellia128ccm12 or camellia128ccm96 | 128-bit Camellia-CCM with a 96-bit ICV | 26 | o g a | ||
| camellia192ccm12 or camellia192ccm96 | 192-bit Camellia-CCM with a 96-bit ICV | 26 | o g a | ||
| camellia256ccm12 or camellia256ccm96 | 256-bit Camellia-CCM with a 96-bit ICV | 26 | o g a | ||
| camellia128ccm16 or camellia128ccm128 | 128-bit Camellia-CCM with a 128-bit ICV | 27 | o g a | ||
| camellia192ccm16 or camellia192ccm128 | 192-bit Camellia-CCM with a 128-bit ICV | 27 | o g a | ||
| camellia256ccm16 or camellia256ccm128 | 256-bit Camellia-CCM with a 128-bit ICV | 27 | o g a | ||
| chacha20poly1305 | 256-bit ChaCha20/Poly1305 with a 128-bit ICV | 28 | x b w o | n | chapoly |
Pseudo-random functions, or PRFs, are used in IKEv2 key derivation. If not specified explicitly, strongSwan can derive the PRF from a compatible integrity algorithm in the proposal.
AEAD algorithms in IKE have no separate integrity algorithm, so the PRF must be configured explicitly.
| Keyword | Description | IANA | IKE | Plugins |
|---|---|---|---|---|
| prfmd5 | PRF MD5 | 1 | s x w o a | md5, hmac |
| prfsha1 | PRF SHA1 | 2 | s x b w o a | sha1, hmac |
| prfaesxcbc | PRF AES XCBC | 4 | x a | aes, xcbc |
| prfaescmac | PRF AES CMAC | 8 | x | aes, cmac |
| prfsha256 | PRF SHA2_256 | 5 | x b w o a | sha2, hmac |
| prfsha384 | PRF SHA2_384 | 6 | x b w o a | sha2, hmac |
| prfsha512 | PRF SHA2_512 | 7 | x b w o a | sha2, hmac |
The hash functions provided by the gcrypt plugin can also be used with the hmac plugin.
Key derivation functions
IKEv2 derives key material from the negotiated PRF using PRF and PRF+. Since strongSwan 5.9.6, these operations have been provided by plugins.
| Base PRF | IKE | Plugins |
|---|---|---|
| PRF MD5 | s x w o | md5, hmac, kdf |
| PRF SHA1 | s x b w o | sha1, hmac, kdf |
| PRF AES XCBC | x | aes, xcbc, kdf |
| PRF AES CMAC | x | aes, cmac, kdf |
| PRF SHA2_256 | x b w o | sha2, hmac, kdf |
| PRF SHA2_384 | x b w o | sha2, hmac, kdf |
| PRF SHA2_512 | x b w o | sha2, hmac, kdf |
The botan, openssl, and wolfssl plugins implement HMAC-based operations through their respective HKDF implementations.
The kdf plugin provides generic implementations for supported PRFs.
Diffie-Hellman groups
Regular modular prime groups
| Keyword | Modulus | IANA | IKE | Plugins |
|---|---|---|---|---|
| modp768 | 768 bits | 1 | s x b w o g | gmp |
| modp1024 | 1024 bits | 2 | s x b w o g | gmp |
| modp1536 | 1536 bits | 5 | s x b w o g | gmp |
| modp2048 | 2048 bits | 14 | x b w o g | gmp |
| modp3072 | 3072 bits | 15 | x b w o g | gmp |
| modp4096 | 4096 bits | 16 | x b w o g | gmp |
| modp6144 | 6144 bits | 17 | x b o g | gmp |
| modp8192 | 8192 bits | 18 | x b o g | gmp |
Modular prime groups with prime-order subgroup
| Keyword | Modulus | Subgroup | IANA | IKE | Plugins |
|---|---|---|---|---|---|
| modp1024s160 | 1024 bits | 160 bits | 22 | s x b w o g | gmp |
| modp2048s224 | 2048 bits | 224 bits | 23 | s x b w o g | gmp |
| modp2048s256 | 2048 bits | 256 bits | 24 | s x b w o g | gmp |
NIST elliptic curve groups
| Keyword | Prime size | IANA | IKE | Plugins |
|---|---|---|---|---|
| ecp192 | 192 bits | 25 | s w o | |
| ecp224 | 224 bits | 26 | w o | |
| ecp256 | 256 bits | 19 | b w o | |
| ecp384 | 384 bits | 20 | b w o | |
| ecp521 | 521 bits | 21 | b w o |
Brainpool elliptic curve groups
| Keyword | Modulus | IANA | IKE | Plugins |
|---|---|---|---|---|
| ecp224bp | 224 bits | 27 | o | |
| ecp256bp | 256 bits | 28 | b w o | |
| ecp384bp | 384 bits | 29 | b w o | |
| ecp512bp | 512 bits | 30 | b w o |
Modern elliptic curve groups
| Keyword | Modulus | IANA | IKE | Plugins |
|---|---|---|---|---|
| curve25519 or x25519 | 256 bits | 31 | x b w o | curve25519 |
| curve448 or x448 | 448 bits | 32 | w o |
Source:https://docs.strongswan.org/docs/5.9/config/IKEv2CipherSuites.html
Configuring the other gateway
At the other location, configure an IKEv2 connection with PSK. If you use a compatible firewall or router, enter the following values, adapting them to its option names:
| Parameter | Value at the other location |
|---|---|
| Version | IKEv2 |
| Authentication | Pre-shared key, identical to the one on Clouding |
| Remote gateway address | 203.0.113.10 |
| Local identity | 198.51.100.20 |
| Remote identity | 203.0.113.10 |
| Local network | 192.168.1.0/24 |
| Remote network | 10.20.10.0/24 |
| IKE proposal | AES-256, SHA-256, and DH group 14 |
| ESP proposal | AES-256-GCM with a 128-bit tag and PFS using DH group 14 |
| IKE rekey interval | 2 hours, as a reference for this example |
| IPsec rekey interval | 1 hour, as a reference for this example |
The names and exact meaning of rekeying options may vary by manufacturer. Check its documentation if it distinguishes between rekey time and maximum lifetime.
If the other gateway also uses strongSwan with swanctl, adapt the file above by swapping the local and remote values, including addresses, identities, and networks. The key must be the same.
Configuring routes and allowing traffic
Devices on each network must send traffic for the other network through their VPN gateway. If that gateway is already their default gateway, you may not need to add routes.
On Clouding servers that do not use the VPN gateway as their gateway, add a route to “192.168.1.0/24” through the VPN gateway's private IP, “10.20.10.10” in this example.
On Linux, run as root:
# ip route add 192.168.1.0/24 via 10.20.10.10This route is temporary. To keep it after a restart, add it to your distribution's network configuration, for example through Netplan or NetworkManager, as appropriate.
On Windows Server, open PowerShell or a command prompt as administrator and add the persistent route:
route -p add 192.168.1.0 mask 255.255.255.0 10.20.10.10At the other location, there must be a return route to “10.20.10.0/24” through its VPN gateway. Do not add these routes on the gateway itself pointing to its own address.
Also check that the firewalls allow forwarding between the two networks and access to the services you need. For example, for SSH access from the other location, the destination server must allow the source “192.168.1.0/24”.
This example preserves the original private addresses. If your gateways have NAT or masquerading rules, exempt IPsec-protected traffic so it continues to match the tunnel's networks.
You can find details on routing and NAT in the strongSwan traffic forwarding documentation.
Starting the connection and checking its status
Once both gateways are configured, start the service on the Clouding server and enable it to start automatically:
# systemctl enable --now strongswan
# systemctl status strongswan --no-pagerLoad the configuration and check the available connections:
# swanctl --load-all
# swanctl --list-connsThe “start_action = trap|start” option requests that the connection start when loaded and allows matching traffic to trigger the tunnel again. To initiate negotiation manually, run:
# swanctl --initiate --child red-privadaCheck the established security associations:
# swanctl --list-sasCheck that the IKE connection is established and an IPsec association is installed for “10.20.10.0/24” and “192.168.1.0/24”.
Next, test communication from a device on one network to a device on the other. Use ping if allowed, or connect to an authorised service such as SSH or RDP. The tunnel's byte counters should increase as you generate traffic.
For this test, use devices with addresses within the configured subnets. A test from the gateway's public IP does not match the traffic defined in this example.
If the tunnel does not connect or carry traffic
Check the service logs:
# journalctl -u strongswan -n 100 --no-pager- If the other gateway does not respond, check its addresses, UDP ports 500 and 4500, and port forwarding if NAT is involved.
- If authentication fails, check the PSK and identities configured at both ends.
- If you see a proposal error, check that both gateways support the same IKE and ESP algorithms.
- If the tunnel is established but there is no communication, check the subnets, routes in both directions, forwarding rules, the Clouding firewall, and the destination devices' firewalls.
To load later changes, save the file and run “swanctl --load-all” again. Changes may interrupt the connection, and some parameters will take effect when the tunnel is renegotiated.
And that’s it! Once your tests work in both directions, your two networks will be connected through the VPN 🙂
Remember, if you have any questions about this or any other matter related to your servers at Clouding, feel free to email soporte@clouding.io We’re here for whatever you need. Just ask us!