StrongSwan Gateway VPN Server on Ubuntu
Last updated
Last updated
A VPN allows you to access the Internet safely and securely on an untrusted public Wi-Fi network. You can connect to remote VPN servers using the encrypted connection and surf the web anonymously.
strongSwan is free, open-source, and the most widely-used IPsec-based virtual private network implementation, allowing you to create an encrypted secure tunnel between two or more remote networks.
strongSwan uses the IKEv2 protocol, which allows for direct IPSec tunneling between the server and the client. strongSwan stands for Strong Secure WAN and supports both versions of automatic keying exchange in IPsec VPN, IKE V1 and V2.
Update the system :
Use the IPsec command-line utility to create your IPsec private key.
Create and sign the root certificate with the configurations included below. Ensure you replace the value of the CN
configuration with your own desired name for your StrongSwan VPN server.
Generate the StrongSwan VPN server’s private key and save it to /etc/ipsec.d/private/server.key.pem
. This command ensures root permissions for file creation, and suppresses terminal output.
Generate the host server certificate. There are two ways to generate the certificate, however, they cannot be mixed. The two ways are as follows:
Use a local resolver, like DNS, your hosts’ file, or another resolver.
Use a static host gateway server by providing its IPv4 address.
Local Resolver Method
Gateway Server or IPV4 Address
Important Locations for Key Management for Strongswan :
Use your preferred text editor to edit your /etc/sysctl.conf
file. The configurations to add enable packet forwarding for IPsec and StrongSwan on your Ubuntu system. Add the following parameters in the end of config file
Reload the config changes using the following command:
Now for the safer side if something goes wrong we first take the config backup
Make the new config file :
Configure the StrongSwan file. Open your /etc/ipsec.conf
file and add the configurations included in the example file below.
Within the context of StrongSwan, the gateway host server (your Ubuntu server) is referred to as left resources. External hosts connecting to the StrongSwan VPN are referred to as right resources.
Create authentication and access secrets. Access control and authentication require that StrongSwan clients provide a username and password. This information is contained in the /etc/ipsec.secrets
file.
Using a text editor, create a the /etc/ipsec.secrets
file with the following contents:
Save and close the file. Then, restart the strongSwan service and enable it to start at reboot:
You can also verify the strongSwan certificates using the following command:
Your StrongSwan server is now ready to receive client connections. To check the status of the IPsec tunnel created by StrongSwan, use the following command:
We will consider adding clients on windows & Linux OS in this section
Install the StrongSwan client and required plugins.
Download or copy the StrongSwan host gateway VPN server’s certificate. The certificate is located on the VPN server in /etc/ipsec.d/cacerts/ca.cert.pem
. Store the copied or downloaded certificate in the client’s /etc/ipsec.d/cacerts
directory.
Add the IPsec secrets file to the StrongSwan client. Using a text editor, add the /etc/ipsec.secrets
file. The credentials for this user must exactly match those created on the StrongSwan VPN server.
Create or modify the /etc/ipsec.conf
configuration file. The file can be configured to support a host gateway VPN server configured for a resolver/DNS or to support access via an IPv4 address. Refer to the example configuration below that corresponds to your StrongSwan VPN server.
Resolver DNS based :
To start the StrongSwan client VPN, use the following command:
Verify the StrongSwan connection from the client to server, use the following command:
To enable connection on boot :
To connect to a StrongSwan VPN gateway server, your Windows 10 system needs a copy of the gateway VPN server’s certificate.
Import the VPN gateway server’s certificate that is located in /etc/ipsec.d/certs/server.cert.pem
. The certificate must be marked as a VPN Root Certificate.
Use the Microsoft Management Console/MMC to configure the VPN’s IPsec information.
Open the Run dialog box, (Windows_key-R), or press the Windows key, and enter into the lower-left dialog box, mmc.exe
. This starts the Microsoft Management Console/MMC.
From the File menu of the MMC, scroll to Add or Remove Snap-in. Select Certificates from the list, and click Add.
The Snap-in asks for the account type to manage. From the list that appears, choose Computer account.
Then, choose Local Compute unless you manage other computers that also use this certificate. Click Finish, and the process is completed.
The Console Root MMC displays a list of certificate types on the left side of the MMC, and in the middle, a list of certificates pertaining to the selection on the left.
On the left of the MMC, open Trusted Root Certificate Authorities, then click the Certificates folder that appears directly under Trusted Root Certificate Authorities.
From the MMC Action menu, choose All Tasks, then Import. The Certificate Import Wizard appears. Choose Local Machine, then browse to the location where the server.cert.pem
file was imported, and select it.
The Certificate Import Wizard asks where to import the certificate. The wizard recognizes the type, and places the certificate into the Trusted Root Certification Authorities certificate store. Click Finish to complete the certificate import process.
Connecting a Windows Client to the StrongSwan Gateway VPN Server
The client authentication process relies on the ipsec.secrets
file located on the gateway VPN server.
To configure a new VPN connection on your Windows computer, launch the Control Panel from the Windows menu by pressing the Windows key. Then, select Network and Sharing Center.
Choose Setup a new connection or network and then, select Connect to a workplace. Next, select Choose Use my Internet Connection (VPN).
During this step, you need some details about your gateway VPN server. You should know the server’s DNS name if that’s how it was configured in the ipsec.conf
file. If, however, you used an IPv4 address when configuring the leftid
value in the ipsec.conf
file, provide the server’s IPv4 address. Finally, you enter a username and password that matches the VPN server’s ipsec.secrets
entry.
Start the VPN by clicking its name from the Taskbar Networks list of choices.
To terminate your VPN connection, click the VPN again and you have disconnected another network.