How to Set Up an IKEv2 VPN Server with … – DigitalOcean
Introduction
A virtual private network, or VPN, allows you to securely encrypt traffic as it travels through untrusted networks, such as those at the coffee shop, a conference, or an airport.
IKEv2, or Internet Key Exchange v2, is a protocol that allows for direct IPSec tunneling between the server and client. In IKEv2 VPN implementations, IPSec provides encryption for the network traffic. IKEv2 is natively supported on some platforms (OS X 10. 11+, iOS 9. 1+, and Windows 10) with no additional applications necessary, and it handles client hiccups quite smoothly.
In this tutorial, you’ll set up an IKEv2 VPN server using StrongSwan on an Ubuntu 18. 04 server and connect to it from Windows, macOS, Ubuntu, iOS, and Android clients.
Prerequisites
To complete this tutorial, you will need:
One Ubuntu 18. 04 server configured by following the Ubuntu 18. 04 initial server setup guide, including a sudo non-root user and a firewall.
Step 1 — Installing StrongSwan
First, we’ll install StrongSwan, an open-source IPSec daemon which we’ll configure as our VPN server. We’ll also install the public key infrastructure component so that we can create a certificate authority to provide credentials for our infrastructure.
Update the local package cache and install the software by typing:
sudo apt update
sudo apt install strongswan strongswan-pki
Now that everything’s installed, let’s move on to creating our certificates.
An IKEv2 server requires a certificate to identify itself to clients. To help us create the certificate required, the strongswan-pki package comes with a utility to generate a certificate authority and server certificates. To begin, let’s create a few directories to store all the assets we’ll be working on. The directory structure matches some of the directories in /etc/ipsec. d, where we will eventually move all of the items we create. We’ll lock down the permissions so that our private files can’t be seen by other users:
mkdir -p ~/pki/{cacerts, certs, private}
chmod 700 ~/pki
Now that we have a directory structure to store everything, we can generate a root key. This will be a 4096-bit RSA key that will be used to sign our root certificate authority.
Execute these commands to generate the key:
ipsec pki –gen –type rsa –size 4096 –outform pem > ~/pki/private/
Now that we have a key, we can move on to creating our root certificate authority, using the key to sign the root certificate:
ipsec pki –self –ca –lifetime 3650 –in ~/pki/private/ \
–type rsa –dn “CN=VPN root CA” –outform pem > ~/pki/cacerts/
You can change the distinguished name (DN) values to something else to if you would like. The common name here is just the indicator, so it doesn’t have to match anything in your infrastructure.
Now that we’ve got our root certificate authority up and running, we can create a certificate that the VPN server will use.
Step 3 — Generating a Certificate for the VPN Server
We’ll now create a certificate and key for the VPN server. This certificate will allow the client to verify the server’s authenticity using the CA certificate we just generated.
First, create a private key for the VPN server with the following command:
Now, create and sign the VPN server certificate with the certificate authority’s key you created in the previous step. Execute the following command, but change the Common Name (CN) and the Subject Alternate Name (SAN) field to your VPN server’s DNS name or IP address:
ipsec pki –pub –in ~/pki/private/ –type rsa \
| ipsec pki –issue –lifetime 1825 \
–cacert ~/pki/cacerts/ \
–cakey ~/pki/private/ \
–dn “CN=server_domain_or_IP” –san “server_domain_or_IP” \
–flag serverAuth –flag ikeIntermediate –outform pem \
> ~/pki/certs/
Now that we’ve generated all of the TLS/SSL files StrongSwan needs, we can move the files into place in the /etc/ipsec. d directory by typing:
sudo cp -r ~/pki/* /etc/ipsec. d/
In this step, we’ve created a certificate pair that would be used to secure communications between the client and the server. We’ve also signed the certificates with the CA key, so the client will be able to verify the authenticity of the VPN server using the CA certificate. Now that have all of the certificates ready, we’ll move on to configuring the software.
Step 4 — Configuring StrongSwan
StrongSwan has a default configuration file with some examples, but we will have to do most of the configuration ourselves. Let’s back up the file for reference before starting from scratch:
sudo mv /etc/{,. original}
Create and open a new blank configuration file by typing:
sudo nano /etc/
First, we’ll tell StrongSwan to log daemon statuses for debugging and allow duplicate connections. Add these lines to the file:
/etc/nfconfig setup
charondebug=”ike 1, knl 1, cfg 0″
uniqueids=no
Then, we’ll create a configuration section for our VPN. We’ll also tell StrongSwan to create IKEv2 VPN Tunnels and to automatically load this configuration section when it starts up. Append the following lines to the file:
/etc/..
conn ikev2-vpn
auto=add
compress=no
type=tunnel
keyexchange=ikev2
fragmentation=yes
forceencaps=yes
We’ll also configure dead-peer detection to clear any “dangling” connections in case the client unexpectedly disconnects. Add these lines:
conn ikev2-vpn…
dpdaction=clear
dpddelay=300s
rekey=no
Then, we’ll configure the server (left) side IPSec parameters. Add this to the file:
left=%any
leftid=@server_domain_or_IP
leftsendcert=always
leftsubnet=0. 0. 0/0
Note: When configuring the server ID (leftid), only include the @ character if your VPN server will be identified by a domain name:
If the server will be identified by its IP address, just put the IP address in:
leftid=203. 113. 7
Next, we can configure the client (right) side IPSec parameters, like the private IP address ranges and DNS servers to use:
right=%any
rightid=%any
rightauth=eap-mschapv2
rightsourceip=10. 10. 0/24
rightdns=8. 8. 8, 8. 4. 4
rightsendcert=never
Finally, we’ll tell StrongSwan to ask the client for user credentials when they connect:
eap_identity=%identity
The configuration file should look like this:
Save and close the file once you’ve verified that you’ve configured things as shown.
Now that we’ve configured the VPN parameters, let’s move on to creating an account so our users can connect to the server.
Step 5 — Configuring VPN Authentication
Our VPN server is now configured to accept client connections, but we don’t have any credentials configured yet. We’ll need to configure a couple things in a special configuration file called crets:
We need to tell StrongSwan where to find the private key for our server certificate, so the server will be able to authenticate to clients.
We also need to set up a list of users that will be allowed to connect to the VPN.
Let’s open the secrets file for editing:
sudo nano /etc/crets
First, we’ll tell StrongSwan where to find our private key:
/etc/crets: RSA “”
Then, we’ll define the user credentials. You can make up any username or password combination that you like:
/etc/cretsyour_username: EAP “your_password”
Save and close the file. Now that we’ve finished working with the VPN parameters, we’ll restart the VPN service so that our configuration is applied:
sudo systemctl restart strongswan
Now that the VPN server has been fully configured with both server options and user credentials, it’s time to move on to configuring the most important part: the firewall.
Step 6 — Configuring the Firewall & Kernel IP Forwarding
With the StrongSwan configuration complete, we need to configure the firewall to forward and allow VPN traffic through.
If you followed the prerequisite tutorial, you should have a very basic UFW firewall enabled. If you don’t yet have UFW configured, you can create a baseline configuration and enable it by typing:
sudo ufw allow OpenSSH
sudo ufw enable
Now, add a rule to allow UDP traffic to the standard IPSec ports, 500 and 4500:
sudo ufw allow 500, 4500/udp
Next, we will open up one of UFW’s configuration files to add a few low-level policies for routing and forwarding IPSec packets. Before we do, we need to find which network interface on our server is used for internet access. We can find that by querying for the interface associated with the default route:
ip route | grep default
Your public interface should follow the word “dev”. For example, this result shows the interface named eth0, which is highlighted below:
Outputdefault via 203. 7 dev eth0 proto static
When you have your public network interface, open the /etc/ufw/ file in your text editor:
sudo nano /etc/ufw/
Near the top of the file (before the *filter line), add the following configuration block:
/etc/ufw/*nat
-A POSTROUTING -s 10. 0/24 -o eth0 -m policy –pol ipsec –dir out -j ACCEPT
-A POSTROUTING -s 10. 0/24 -o eth0 -j MASQUERADE
COMMIT
*mangle
-A FORWARD –match policy –pol ipsec –dir in -s 10. 0/24 -o eth0 -p tcp -m tcp –tcp-flags SYN, RST SYN -m tcpmss –mss 1361:1536 -j TCPMSS –set-mss 1360
*filter:ufw-before-input – [0:0]:ufw-before-output – [0:0]:ufw-before-forward – [0:0]:ufw-not-local – [0:0]…
Change each instance of eth0 in the above configuration to match the interface name you found with ip route. The *nat lines create rules so that the firewall can correctly route and manipulate traffic between the VPN clients and the internet. The *mangle line adjusts the maximum packet segment size to prevent potential issues with certain VPN clients.
Next, after the *filter and chain definition lines, add one more block of configuration:
/etc/ufw/..
*filter:ufw-before-input – [0:0]:ufw-before-output – [0:0]:ufw-before-forward – [0:0]:ufw-not-local – [0:0]
-A ufw-before-forward –match policy –pol ipsec –dir in –proto esp -s 10. 0/24 -j ACCEPT
-A ufw-before-forward –match policy –pol ipsec –dir out –proto esp -d 10. 0/24 -j ACCEPT
These lines tell the firewall to forward ESP (Encapsulating Security Payload) traffic so the VPN clients will be able to connect. ESP provides additional security for our VPN packets as they’re traversing untrusted networks.
When you’re finished, save and close the file.
Before we restart the firewall, we’ll change some network kernel parameters to allow routing from one interface to another. Open UFW’s kernel parameters configuration file:
We’ll need to configure a few things here:
First, we’ll enable IPv4 packet forwarding.
We’ll disable Path MTU discovery to prevent packet fragmentation problems.
We also won’t accept ICMP redirects nor send ICMP redirects to prevent man-in-the-middle attacks.
The changes you need to make to the file are highlighted in the following code:
/etc/ufw/…
# Enable forwarding
# Uncomment the following line
net/ipv4/ip_forward=1…
# Do not accept ICMP redirects (prevent MITM attacks)
# Ensure the following line is set
net/ipv4/conf/all/accept_redirects=0
# Do not send ICMP redirects (we are not a router)
# Add the following lines
net/ipv4/conf/all/send_redirects=0
net/ipv4/ip_no_pmtu_disc=1
Save the file when you are finished. UFW will apply these changes the next time it starts.
Now, we can enable all of our changes by disabling and re-enabling the firewall:
sudo ufw disable
You’ll be prompted to confirm the process. Type Y to enable UFW again with the new settings.
Step 7 – Testing the VPN Connection on Windows, iOS, and macOS
Now that you have everything set up, it’s time to try it out. First, you’ll need to copy the CA certificate you created and install it on your client device(s) that will connect to the VPN. The easiest way to do this is to log into your server and output the contents of the certificate file:
cat /etc/ipsec. d/cacerts/
You’ll see output similar to this:
Output—–BEGIN CERTIFICATE—–
MIIFQjCCAyqgAwIBAgIIFkQGvkH4ej0wDQYJKoZIhvcNAQEMBQAwPzELMAkGA1UE…
EwbVLOXcNduWK2TPbk/+82GRMtjftran6hKbpKGghBVDPVFGFT6Z0OfubpkQ9RsQ
BayqOb/Q
—–END CERTIFICATE—–
Copy this output to your computer, including the —–BEGIN CERTIFICATE—– and —–END CERTIFICATE—– lines, and save it to a file with a recognizable name, such as Ensure the file you create has the extension.
Alternatively, use SFTP to transfer the file to your computer.
Once you have the file downloaded to your computer, you can set up the connection to the VPN.
Connecting from Windows
First, import the root certificate by following these steps:
Press WINDOWS+R to bring up the Run dialog, and enter to launch the Windows Management Console.
From the File menu, navigate to Add or Remove Snap-in, select Certificates from the list of available snap-ins, and click Add.
We want the VPN to work with any user, so select Computer Account and click Next.
We’re configuring things on the local computer, so select Local Computer, then click Finish.
Under the Console Root node, expand the Certificates (Local Computer) entry, expand Trusted Root Certification Authorities, and then select the Certificates entry:
From the Action menu, select All Tasks and click Import to display the Certificate Import Wizard. Click Next to move past the introduction.
On the File to Import screen, press the Browse button and select the certificate file that you’ve saved. Then click Next.
Ensure that the Certificate Store is set to Trusted Root Certification Authorities, and click Next.
Click Finish to import the certificate.
Then configure the VPN with these steps:
Launch Control Panel, then navigate to the Network and Sharing Center.
Click on Set up a new connection or network, then select Connect to a workplace.
Select Use my Internet connection (VPN).
Enter the VPN server details. Enter the server’s domain name or IP address in the Internet address field, then fill in Destination name with something that describes your VPN connection. Then click Done.
Your new VPN connection will be visible under the list of networks. Select the VPN and click Connect. You’ll be prompted for your username and password. Type them in, click OK, and you’ll be connected.
Connecting from macOS
Follow these steps to import the certificate:
Double-click the certificate file. Keychain Access will pop up with a dialog that says “Keychain Access is trying to modify the system keychain. Enter your password to allow this. ”
Enter your password, then click on Modify Keychain
Double-click the newly imported VPN certificate. This brings up a small properties window where you can specify the trust levels. Set IP Security (IPSec) to Always Trust and you’ll be prompted for your password again. This setting saves automatically after entering the password.
Now that the certificate is important and trusted, configure the VPN connection with these steps:
Go to System Preferences and choose Network.
Click on the small “plus” button on the lower-left of the list of networks.
In the popup that appears, Set Interface to VPN, set the VPN Type to IKEv2, and give the connection a name.
In the Server and Remote ID field, enter the server’s domain name or IP address. Leave the Local ID blank.
Click on Authentication Settings, select Username, and enter your username and password you configured for your VPN user. Then click OK.
Finally, click on Connect to connect to the VPN. You should now be connected to the VPN.
Connecting from Ubuntu
To connect from an Ubuntu machine, you can set up and manage StrongSwan as a service or use a one-off command every time you wish to connect. Instructions are provided for both.
Managing StrongSwan as a Service
Update your local package cache: sudo apt update
Install StrongSwan and the related software sudo apt install strongswan libcharon-extra-plugins
Copy the CA certificate to the /etc/ipsec. d/cacerts directory: sudo cp /tmp/ /etc/ipsec. d/cacerts
Disable StrongSwan so that the VPN doesn’t start automatically: sudo systemctl disable –now strongswan
Configure your VPN username and password in the /etc/crets file: your_username: EAP “your_password”
Edit the /etc/ file to define your configuration.
conn ikev2-rw
right=server_domain_or_IP
# This should match the `leftid` value on your server’s configuration
rightid=server_domain_or_IP
rightsubnet=0. 0/0
rightauth=pubkey
leftsourceip=%config
leftid=username
leftauth=eap-mschapv2
auto=start
To connect to the VPN, type:
sudo systemctl start strongswan
To disconnect again, type:
sudo systemctl stop strongswan
Using a Simple Client for One-Off Connections
Install charon-cmd and related software sudo apt install charon-cmd libcharon-extra-plugins
Move to the directory where you copied the CA certificate: cd <^>/path/to/
Connect to the VPN server with charon-cmd using the server’s CA certificate, the VPN server’s IP address, and the username you configured: sudo charon-cmd –cert –host vpn_domain_or_IP –identity your_username
When prompted, provide the VPN user’s password.
You should now be connected to the VPN. To disconnect, press CTRL+C and wait for the connection to close.
Connecting from iOS
To configure the VPN connection on an iOS device, follow these steps:
Send yourself an email with the root certificate attached.
Open the email on your iOS device and tap on the attached certificate file, then tap Install and enter your passcode. Once it installs, tap Done.
Go to Settings, General, VPN and tap Add VPN Configuration. This will bring up the VPN connection configuration screen.
Tap on Type and select IKEv2.
In the Description field, enter a short name for the VPN connection. This could be anything you like.
In the Server and Remote ID field, enter the server’s domain name or IP address. The Local ID field can be left blank.
Enter your username and password in the Authentication section, then tap Done.
Select the VPN connection that you just created, tap the switch on the top of the page, and you’ll be connected.
Connecting from Android
Send yourself an email with the CA certificate attached. Save the CA certificate to your downloads folder.
Download the StrongSwan VPN client from the Play Store.
Open the app. Tap the “more” icon in the upper-right corner (the three dots icon) and select CA certificates.
Tap the “more” icon in the upper-right corner again. Select Import certificate.
Browse to the CA certificate file in your downloads folder and select it to import it into the app.
Now that the certificate is imported into the StrongSwan app, you can configure the VPN connection with these steps:
In the app, tap ADD VPN PROFILE at the top.
Fill out the Server with your VPN server’s domain name or public IP address.
Make sure IKEv2 EAP (Username/Password) is selected as the VPN Type.
Fill out the Username and Password with the credentials you defined on the server.
Deselect Select automatically in the CA certificate section and click Select CA certificate.
Tap the IMPORTED tab at the top of the screen and choose the CA you imported (it will be named “VPN root CA” if you didn’t change the “DN” earlier).
If you’d like, fill out Profile name (optional) with a more descriptive name.
When you wish to connect to the VPN, click on profile you just created in the StrongSwan application.
Troubleshooting Connections
If you are unable to import the certificate, ensure the file has the extension, and not
If you’re unable to connect to the VPN, check the server name or IP address you used. The server’s domain name or IP address must match what you’ve configured as the common name (CN) while creating the certificate. If they don’t match, the VPN connection won’t work. If you set up a certificate with the CN of, you must use when you enter the VPN server details. Double-check the command you used to generate the certificate, and the values you used when creating your VPN connection.
Finally, double-check the VPN configuration to ensure the leftid value is configured with the @ symbol if you’re using a domain name:
And if you’re using an IP address, ensure that the @ symbol is omitted.
Conclusion
In this tutorial, you’ve built a VPN server that uses the IKEv2 protocol. Now you can be assured that your online activities will remain secure wherever you go!
To add or remove users, just take a look at Step 5 again. Each line is for one user, so adding or removing users is as simple as editing the file.
From here, you might want to look into setting up a log file analyzer, because StrongSwan dumps its logs into syslog. The tutorial How To Install and Use Logwatch Log Analyzer and Reporter on a VPS has more information on setting that up.
You might also be interested in this guide from the EFF about online privacy.
jawj/IKEv2-setup: Set up Ubuntu Server 20.04 (or 18.04) as an …
Table of contents
What?
VPN server
VPN clients
Caveats
How?
Troubleshooting
Users
Upgrades
Bonus paranoia
Why?
Why IKEv2?
Why not Algo?
A Bash script that takes Ubuntu Server 20. 04 LTS or 18. 04 LTS from clean install to production-ready IKEv2 VPN with strongSwan. Comments and pull requests welcome. It may still work on 17. 10, 17. 04 or 16. 10 if you remove the version check, but these are not tested.
The VPN server identifies itself with a Let’s Encrypt certificate, so there’s no need for clients to install private certificates — they can simply authenticate with username and strong password (EAP-MSCHAPv2).
The only cipher set implemented is CNSA/RFC 6379 Suite B with confidentiality/encryption.
The box is firewalled with iptables and configured for unattended security upgrades, and the Let’s Encrypt certificate is set up to auto-renew, so it could be safe to forget about it all until 18. 04 reaches end-of-life in 2023. (Note that iptables setup includes basic rate-limiting, dropping new connections if there have been 60+ connection attempts in the last 5 minutes).
The VPN is tested working with:
macOS 10. 12 – 10. 15, iOS 10 – 13 — Built-in clients. A. mobileconfig profile is generated for Mac and iOS, to set up secure ciphers and enable Connect on demand support.
Windows 10 Pro — Built-in client. PowerShell commands are generated to configure the VPN and secure ciphers.
Ubuntu (17. 04 and presumably others) — Using strongSwan. A Bash script is generated to set this up.
Android — Using the official strongSwan app.
Configuration files, scripts and instructions are sent by email. They are also dropped in the newly-created non-root user’s home directory on the server (this point may be important, because VPS providers sometimes block traffic on port 25 by default and, even if successfully sent, conscientious email hosts will sometimes mark the email as spam).
There’s no IPv6 support — and, in fact, IPv6 networking is disabled — because supporting IPv6 prevents the use of forceencaps, and honestly also because I haven’t got to grips with the security implications (ip6tables rules and so on).
The script won’t work as-is on 16. 04 LTS because the certbot package is outdated, found under the name letsencrypt, and doesn’t renew certificates automatically.
Don’t use this unmodified on a server you use for anything else: it does as it sees fit with various wider settings that may conflict with what you’re doing.
Pick a domain name for the VPN server and ensure that it already resolves to the correct IP by creating the appropriate A record in the DNS and making sure it has propagated. Let’s Encrypt needs this in order to create your server certificate.
Don’t want to use your own domain name here? You could try using the reverse DNS name provided by your server host, or an automatic IP/DNS alias service such as,,,, or (earlier versions of this script used an address by default). However, both of these options may fall foul of Let’s Encrypt’s per-domain rate limit of 50 certificates per week. Note that ephemeral AWS domain names like are not accepted by Let’s Encrypt.
Start with a clean Ubuntu 20. 04 or 18. 04 Server installation. The cheapest VPSs offered by Linode, OVH,, Google, Hetzner and Vultr, and Scaleway’s ARM64-2GB, have all been tested working. On Scaleway, unblock SMTP ports in the admin panel and hard reboot the server first, or your configuration email will not be delivered. On Vultr, port 25 may also be blocked, but you won’t know, and the only way to fix it is to open a support ticket.
Optionally, set up key-based SSH authentication (alternatively, this may have been handled automatically by your server provider, or you may choose to stick with password-based authentication). This may require you to run some or all of the following commands, with appropriate substitutions, on the machine you’re going to be logging in from:
ssh-keygen -t ed25519 -C “” # if you need a new key, ed25519 is the latest and possibly most secure option
ssh-keygen -t rsa -b 4096 -C “” # alternatively, use RSA and go (4, 096 bits) large
ssh # if your host forces a password change before anything else (e. g. Hetzner), do it now, then exit
ssh-copy-id -i ~/ # copy your public key over to the VPN server
ssh # log back in to the server for the next step…
On your new server installation, become root, download the script, give it execute permissions, and run it:
wget chmod u+x. /
You’ll be prompted to enter all the necessary details after the software updates and installations complete. If you are not using key-based SSH authentication, you must pick a really strong password for the login user when prompted, or your server will be compromised.
The part of your session where the script asks you questions should look something like this:
— Configuration: VPN settings —
Network interface: eth0
External IP: 100. 100. 100
** Note: hostname must resolve to this machine already, to enable Let’s Encrypt certificate setup **
Hostname for VPN:
VPN username: george
VPN password (no quotes, please):
Confirm VPN password:
Public DNS servers include:
176. 103. 130. 130, 176. 131 AdGuard 176. 132, 176. 134 AdGuard Family 1. 1. 1, 1. 0. 1 Cloudflare/APNIC 84. 200. 69. 80, 84. 70. 40 8. 8. 8, 8. 4. 4 Google 208. 67. 222. 222, 208. 220. 220 OpenDNS 208. 123, 208. 123 OpenDNS FamilyShield 9. 9. 9, 149. 112. 112 Quad9 77. 88. 8, 77. 1 Yandex 77. 88, 77. 2 Yandex Safe 77. 7, 77. 3 Yandex Family
DNS servers for VPN users (default: 1. 1): 176. 131
— Configuration: general server settings —
Timezone (default: Europe/London):
Email address for sysadmin (e. ):
Desired SSH log-in port (default: 22): 2222
New SSH log-in user name: george
Copy /root/ to new user and disable SSH password log-in [Y/n]? y
New SSH user’s password (e. for sudo):
Confirm new SSH user’s password:
Once you’re up and running, use these commands for some insight into what’s going on:
sudo ipsec statusall # status, who’s connected, etc.
sudo iptables -L -v # how much traffic has been forwarded, dropped, etc.?
sudo tail -f /var/log/syslog # real-time logs of (dis)connections etc.
If you ran this script before 13 September 2021, and used the generated PowerShell commands to set up Windows 10 clients, those clients may be unable to connect owing to a bug in Windows 10. If this is the case, see issue #126 and, if necessary, retrieve and run
Otherwise, if things don’t work out right away…
On the client: make sure you created the connection using the newly emailed. mobileconfig file or PowerShell commands. Setting it up manually via the OS GUI will not work, since it will default to insecure ciphers which the server has not been configured to support. Also note that. mobileconfig files generated with earlier iterations of this script may no longer be compatible, since the configured ciphers have changed from time to time.
On the server: check that network ingress for UDP on ports 500 and 4500 is enabled (on some cloud platforms you’ll have to add appropriate firewall rules to your virtual network). Also check that packet forwarding is enabled (on some cloud platforms this is controlled by a configuration setting that’s off by default).
Check the server logs on strongSwan startup and when you try to connect, and the client logs when you try to connect.
On the server: Log in via SSH, then sudo tail -f /var/log/syslog. To see startup logs, log in to another session and sudo ipsec restart there, then switch back. To see what’s logged during a connection attempt, try to connect from a client.
On the client: On a Mac, open in /Applications/Utilities. If connecting from an iPhone, plug the iPhone into the Mac. Pick the relevant device (in the bar down the left), filter the output (in the box at top right) to nesession, and try to connect. (On Windows or Linux I don’t know where you find the logs — if you know, feel free to write the explanation and send a pull request).
The setup script is now more or less idempotent — you should be able to run it repeatedly with no ill effects — so, when you’ve fixed any issues, simply run it again.
If you have a tricky question about strongSwan, it’s probably better to raise it with the strongSwan team than file an issue here.
To add or change VPN users, it’s:
sudo nano /etc/crets
Edit usernames and passwords as you see fit (but don’t touch the first line, which specifies the server certificate). The line format for each user is:
someusername: EAP “somepassword”
To exit nano it’s Ctrl + O then Ctrl + X, and to have strongSwan pick up the changes it’s:
If you’re on a pre-18. 04 version of Ubuntu, it’s probably easiest to make a record of any changes to crets, blow the whole thing away and reinstall, then reinstate crets.
Note that you may also need to delete and recreate all your client connection settings using the updated PowerShell commands or. mobileconfig file, since there have been a few cipher changes over time.
Your traffic is not logged on the server, but if you’re feeling especially paranoid there are various things you could do to reduce logging further. A simple and somewhat drastic option (once you’ve got everything working) is:
sudo rm /var/log/syslog && sudo ln -s /dev/null /var/log/syslog
sudo rm /var/log/ && sudo ln -s /dev/null /var/log/
We use a similar setup as a corporate VPN at PSYT. And I use this to bounce my personal web browsing via Europe, in the hope of giving Theresa May’s Investigatory Powers Bill the finger.
Fair security
Built-in clients for latest iOS, Mac and Windows (+ trustworthy free install on Android)
Connect on demand support on iOS and Mac
Robust to connection switching and interruptions via MOBIKE
More on IKEv2 at and Why not Algo?
Feel free to use Algo instead. It has similar aims, and now configures WireGuard too. However, it has many more moving parts, and requires several local installation steps before you even start setting up your VPN. This script is intended to be much simpler.
Tutorial Setup IKev2 on Ubuntu 20.04 – Eldernode Blog
The most commonly used protocol today is called Internet Key Exchange (IKE). The first version was released in 1998 and its common name is IKEv1. It should note that the first version of IKE was used by IPsec by default. IKEv1 features upgraded its hidden parts. To upgrade it in 2005, IKEv2 was created. With this update, the protocol became more reliable and more resilient to DOS attacks. IKEv2 is an IPsec-based protocol that stands for Internet Key Exchange Version 2. It is a joint product of Cisco and Microsoft and is compatible with multiple platforms. In this article, we want to introduce you to Tutorial Setup IKev2 on Ubuntu 20. 04. It should note that you can visit the packages available in Eldernode if you wish to purchase an Ubuntu VPS server. How to Setup IKev2 on Ubuntu 20. 04 step by stepSetup IKev2 on Ubuntu 20. 04 | Ubuntu 18. 04Install StrongSwan on Ubuntu 20. 04How to Create a Certificate Authority (Setup IKev2 on Ubuntu 20. 04)How to Generate a Certificate for the VPN ServerHow to Configuring StrongSwanConfiguring VPN AuthenticationHow to Configure the Firewall and Kernel IP ForwardingHow to Connect to IKEv2 from Ubuntu LinuxConclusion How to Setup IKev2 on Ubuntu 20. 04 step by step The IKEv2 protocol is one of the protocols derived from the well-known IPsec protocol, which performs the tunneling process well. There are several versions of IKE for open-source platforms. One of the most important strengths of IKEv2 that distinguishes it from other VPN protocols is the ability to reconnect and reestablish a connection. This means that if a connection is disrupting, IKEv2 can continue the connection and continue the work process. Although many mobile devices prefer to use the L2TP/IPsec protocol combination, IKEv2 can also be a very good alternative. Follow the tutorial on installing, configuring, and running IKEv2 on Ubuntu 20. Setup IKev2 on Ubuntu 20. 04 Installing IKEv2 on Ubuntu 20. 04 is not complicated. In this article, we will teach you to step by step how to configure and setup the IKEv2 VPN server on Ubuntu. Stay with us. Install StrongSwan on Ubuntu 20. 04 The first step is to install StrongSwan. StrongSwan is a free IPSec resource daemon that must be configured as a VPN server. Then you need to install the public key infrastructure component. By doing this you can create a certification authority to validate your infrastructure. Update the local cache using the following commands and install the software: sudo apt update sudo apt install strongswan strongswan-pki How to Create a Certificate Authority (Setup IKev2 on Ubuntu 20. 04) Now that you have successfully installed StrongSwan, let’s move on to creating certificates. Note that an IKEv2 server needs a certificate to identify itself to the client. Now that you have successfully installed StrongSwan, let’s move on to creating certificates. The strongswan-pki package comes with a tool for generating a certification reference and server certifications to help users create certification. You must first create multiple directories to save the assets you are working on. It should be noted that the directory structure is compatible with some of the directories in /etc/ipsec. d. So where we will eventually move all the created items. Here we decide to lock licenses to prevent private files from being seen by other users. To do this, use the following commands: mkdir -p ~/pki/{cacerts, certs, private} chmod 700 ~/pki Now you need to generate a root key. The root key is a 4096-bit RSA key using to sign the root certificate reference. So you can execute the following command to generate the key: ipsec pki –gen –type rsa –size 4096 –outform pem > ~/pki/private/ After you have successfully created the key, you now need to run the following commands to create your root certificate reference using this key to sign the root certificate: ipsec pki –self –ca –lifetime 3650 –in ~/pki/private/ \ –type rsa –dn “CN=VPN root CA” –outform pem > ~/pki/cacerts/ How to Generate a Certificate for the VPN Server After you were able to activate and set up your root certificate license in the previous section, you can now create a certificate that the VPN server can use. It should note that this certificate allows the client to verify the server using CA certification. To do this, first create a private key for the VPN server using the following command: ipsec pki –gen –type rsa –size 4096 –outform pem > ~/pki/private/ In the next step, you need to create and sign the VPN server certificate with the certification reference key that you created in the previous step. Therefore, you must execute the following commands in order. Note: You must change the Common Name (CN) and Subject Alternate Name (SAN) to the DNS or IP address of your VPN server in the following commands. ipsec pki –pub –in ~/pki/private/ –type rsa \ | ipsec pki –issue –lifetime 1825 \ –cacert ~/pki/cacerts/ \ –cakey ~/pki/private/ \ –dn “CN=server_domain_or_IP” –san “server_domain_or_IP” \ –flag serverAuth –flag ikeIntermediate –outform pem \ ~/pki/certs/ Now that you have created all the TLS/SSL files required by StrongSwan, you can move the files to /etc/ipsec. d: sudo cp -r ~/pki/* /etc/ipsec. d/ How to Configuring StrongSwan Let’s back up the file for reference before starting from scratch with the following command: sudo mv /etc/{,. original} In the next step, you can create and open a new empty configuration file by typing the following command: sudo nano /etc/ You first need to tell StrongSwan to record the daemon status and allow duplicate connections to fix the bug. So you need to add the following command to the /etc/ file: config setup charondebug=”ike 1, knl 1, cfg 0″ uniqueids=no The next step is to create a configuration section for the VPN. StrongSwan must also be notified to create the IKEv2 VPN Tunnel. It is then necessary to load this configuration section automatically at startup. Add the following lines to the file:… conn ikev2-vpn auto=add compress=no type=tunnel keyexchange=ikev2 fragmentation=yes forceencaps=yes Note that if the client is unexpectedly disconnected, you must configure the dead-peer connection to clear the “dangling” connections:… conn ikev2-vpn… dpdaction=clear dpddelay=300s rekey=no Next, you need to configure the IPSec server-side parameters: conn ikev2-vpn… left=%any [email protected]_domain_or_IP leftsendcert=always leftsubnet=0. 0. 0/0 Here you need to configure client-side IPSec parameters such as the range of private IP addresses and DNS servers using the following commands:… right=%any rightid=%any rightauth=eap-mschapv2 rightsourceip=10. 10. 0/24 rightdns=8. 8. 8, 8. 4. 4 rightsendcert=never To receive the credential when connecting from the customer, you must enter the following command:… eap_identity=%identity Finally, you need to save the file and exit it. Configuring VPN Authentication In the previous section, we successfully configured the VPN server. But since no credentials have configuring yet, here we need to configure a few items in a special configuration file crets. Open the secrets file using the editor you want: sudo nano /etc/crets By adding the following command to the configuration file, tell StrongSwan where to find your private key:: RSA “” In the next step, you must define the user information using the following command: your_username: EAP “your_password” Save the configuration file and exit it. Then, to apply the changes, you must restart the system using the following command: sudo systemctl restart strongswan How to Configure the Firewall and Kernel IP Forwarding In this section, we intend to complete the StrongSwan configuration to configure the firewall to enable VPN traffic through it. To do this, you must execute the following commands: sudo ufw allow OpenSSH sudo ufw enable Add a rule using the following command to allow UDP traffic to standard IPSec, 500 and 4500 ports: sudo ufw allow 500, 4500/udp To route and send IPSec packets you need to open one of the UFW configuration files and add some low-level policies. Note that you must first use the following command to find out which network interface is using on the server to access the Internet: ip route | grep default The important point here is that your public interface should follow the word “dev“. For example, the following output shows an interface called eth0: default via 203. 113. 7 dev eth0 proto static The next step is to open the /etc/ufw/ file in your text editor: sudo nano /etc/ufw/ The next step is to add the following configuration near the top of the file (before the *filter line): You must change each instance of eth0 in the above configuration to match the interface name you found with the IP path. Now It’s time to add another block of configuration using the following command after *filter and chain definition lines: After making the above changes, save the file and exit it. In order to be able to route from one interface to another, you need to open the UFW kernel configuration file using the following command and change some of the network kernel parameters: sudo nano /etc/ufw/ The changes you need to make to the file are highlighting in the following code: After making the changes, save the file and exit it. Finally, you can enable all your changes by disabling and re-enabling the firewall. To do this you must use the following commands. Note: After executing the following commands, you will be asked to confirm the process. Type Y to re-enabling UFW with the new settings. sudo ufw disable sudo ufw enable How to Connect to IKEv2 from Ubuntu Linux Here’s how to connect to IKEv2 via Ubuntu 20. You can follow the steps below to connect to IKEv2 using the Manage StrongSwan as a service method. You must first update your local package cache using the following command: sudo apt update Then you need to run the following command to install StrongSwan and related software: sudo apt install strongswan libcharon-extra-plugins Next, you need to copy the CA certificate to /etc/ipsec. d/cacerts: sudo cp /tmp/ /etc/ipsec. d/cacerts Another important step is to disable StrongSwan so that the VPN does not start automatically. So to do this you need to get help from the following command: sudo systemctl disable –now strongswan Now you need to configure your VPN username and password in the /etc/crets file: your_username: EAP “your_password” Finally, you need to edit the /etc/ file as follows to define your configuration: You can use the following commands to connect and disconnect to a VPN, respectively: sudo systemctl start strongswan sudo systemctl stop strongswan Conclusion IKEv2, like any other VPN protocol, is responsible for creating a secure tunnel between the user and the VPN server. This process, it is first done by authenticating the user and the server. It is then agreed to which encryption method to use. In this article, we tried to acquaint you step by step with Tutorial Setup IKev2 on Ubuntu 20. If you wish, you can refer to the article How to setup IKev2 on centos 8.
Frequently Asked Questions about ikev2 server ubuntu
How do I use IKEv2 on Ubuntu?
Go to All Programs.Enter into the search: terminal and run the Terminal.Enter the command. … Run the following command to install the applications. … Go to VPN Settings.Click to sign +.Choose IPSec/IKEv2 (strongswan).In the Subscriptions section, choose domain for IKEv2 VPN and look for Username and Password VPN.More items…
How do I make a IKEv2 server?
Go to System Preferences and choose Network. Click on the small “plus” button on the lower-left of the list of networks. In the popup that appears, Set Interface to VPN, set the VPN Type to IKEv2, and give the connection a name. In the Server and Remote ID field, enter the server’s domain name or IP address.
How do I set up strongSwan?
The steps are the same or very similar.Start by opening the Play Store.Enter “strongswan” in the search field, tap on “strongSwan VPN Client” in the search results list.Once you are on the application’s page, tap “Install” button.Then you will see the permissions window, tap “Accept”.More items…