A virtual private network is used to create a private network from a public internet connection to protect your identity. VPN uses an encrypted tunnel to send and receive data securely.
strongSwan is one of the most famous VPN software that supports different operating systems including, Linux, OS X, FreeBSD, Windows, Android, and iOS. It uses IKEv1 and IKEv2 protocol for secure connection establishment. You can extend its functionality with built-in plugins.
In this tutorial, we will explain step-by-step instructions on how to set up a KEv2 VPN Server with StrongSwan on Ubuntu 20.04.
Prerequisite
• Two systems running Ubuntu 20.04 server • A root password is configured on both servers
Install StrongSwan
By default, StrongSwan is available in the Ubuntu 20.04 default repository. You can install it with other required components using the following command:
left=%any - The %any is to indicate that the server will use the private address where it receives the traffic for the rest of the connection.
leftid=@server_domain - controls the domain name that the server will present to the clients and Keep the @ when using the domain name. If your server will be reachable through the IP address, then you should use the IP.
leftcert=server.cert.pem - is the path to the public certificate for the server that was configured previously. It's necessary so that the server will be able to authenticate itself with clients.
leftsendcert=always - to ensure that any client that connects to the server will receive a copy of the public certificate when setting up the initial connection.
leftsubnet=0.0.0.0/0 - tells that all the clients behind the server will be reachable.
After the server side, we can see the client-side configuration:
right=%any so that the server will accept all the incoming connections from any remote client.
rightid=%any to ensure that the server will not reject connections from clients that provide an identity before the encrypted tunnel is established.
rightauth=eap-mschapv2 to configure the authentication method that the clients will use to authenticate to the server.
rightsourceip=10.10.10.0/24 to the network address that will be used to assign the private IP addresses to clients
rightdns=8.8.8.8,8.8.4.4 the Google’s public DNS resolvers but you can change them if you want
rightsendcert=never to indicate to the server that clients do not need to send a certificate to authenticate themselves.
Next, you will need to define the EAP user credentials and the RSA private keys for authentication.
You can set up it by editing the file /etc/ipsec.secrets:
nano /etc/ipsec.secrets
Add the following line:
: RSA "server.key.pem"
vpnsecure : EAP "password"
Then restart the StrongSwan service as follows:
systemctl restart strongswan-starter
To enable StrongSwan to start in system boot, type:
systemctl enable strongswan-starter
Verify the status of the VPN server, type:
systemctl status strongswan-starter
Enable Kernel Packet Forwarding
Next, you will need to configure the kernel to enable packet forwarding by editing /etc/sysctl.conf file:
Save and close the file then reload the new settings using the following command:
sysctl -p
Install and Configure StrongSwan Client
In this section, we will install the StrongSwan client on the remote machine and connect to the VPN server.
First, install all the required packages with the following command:
apt install strongswan libcharon-extra-plugins -y
Once all the packages are installed, stop the StrongSwan service with the following command:
systemctl stop strongswan-starter
Next, you will need to copy the ca.cert.pem file from the VPN server to /etc/ipsec.d/cacerts/ directory. You can copy it using the SCP command as shown below:
The above output indicates that a VPN connection is established between client and server, and the IP address 10.10.10.1 assign to the client machine.
You can also verify your new IP address with the following command:
ip a
You should get the following output:
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:00:68:f5:20:9e brd ff:ff:ff:ff:ff:ff
inet 104.245.32.158/25 brd 104.245.32.255 scope global eth0
valid_lft forever preferred_lft forever
inet 10.10.10.1/32 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::200:68ff:fef5:209e/64 scope link
valid_lft forever preferred_lft forever
Conclusion
In this guide, we learned how to set up a StrongSwan VPN server and client on Ubuntu 20.04. You can now protect your identity and secure your online activities.
If this resource helped you, let us know your care by a Thanks Tweet.
Did you find this article helpful?
We are glad you liked the article. Share with your friends.
Comments