
This article explains how to connect an On-Premises network to a Vultr Virtual Private Cloud (VPC) network using Internet Protocol Security (IPsec) to create a site-to-site tunnel. Internet Key Exchange (IKE) V2 is used to create and authenticate the secure IPsec tunnel between hosts as it supports more features, is more secure, and faster than IKEV1.
IPsec is a group of network protocols that create a secure connection between two or more devices by authenticating and encrypting packets over Internet Protocol (IP) networks such as the Internet. To establish a Virtual Private Network (VPN) tunnel between devices, IPSec uses multiple protocols, including the following.
Before you begin, make sure you have:
An active Vultr account. If not, sign up for one today.
An On-Premises or office network with a static public IP address.
An active domain name. This article uses vpn.example.com. Replace all occurrences with your actual domain name.
IPsec IKEV2 requires valid SSL certificates for host authentication within a tunnel. For production, an active domain name masks the main server IP address and is used in self-signed certificates.
This article follows the example network simulation in the graphic below. The On-Premises network has two hosts as deployed with the local network address 192.168.1.0/24 and the public network with example IP address 192.0.2.0/24. The Vultr VPC has two hosts with the local network address 203.0.113.0/24, and the public IP address 198.51.100.0/24.
Replace all example IP addresses used in this article with your real-world public and private IP addresses on both networks, respectively.
In a single Vultr location:
At the On-Premises network:
To set up IPsec on the server, install an open-source implementation tool such as Openswan, Libreswan, or strongSwan on the server. For purposes of this article, install strongSwan (strong secure wan), which uses the native IPsec stack, and is actively maintained. It supports both Internet Key exchange (IKE) protocols, IKEV1 and IKEV2 protocols, to create an IPsec tunnel between two or more hosts.
Update the server.
Install strongSwan and all required packages.
Enable strongSwan to start at boot time.
Start strongSwan.
Verify that the strongSwan daemon is up and running.
Verify the IPsec tunnel status.
Output:
A valid SSL certificate allows the server to identify itself to clients and mask its public IP address. For compatibility with the strongSwan configurations, generate self-signed SSL certificates on the server using the strongswan-pki utility.
Create a private key for the root Certificate Authority (CA).
Create and sign the root CA using the key generated above.
Create the VPN server private key.
Generate and sign the VPN server certificate using the CA key using the following command. Replace vpn.example.com with your actual domain name.
Back up the original IPsec configuration file.
Create a new configuration file.
Using a text editor, open and edit the file.
Add the following configurations to the file. Replace vpn.example.com with your domain name.
Save and close the file.
Here is what key configuration lines represent:
auto=: The automatic operation starts with the IPsec daemon, start loads and starts up the IPsec connection, add loads a connection but does not start it, ignore ignores the connection until started by the user.type=: The type of IPsec connection, tunnel represents host to host, transport host to host transport mode, drop discards all signifying packets.keyexchange=: Method of exchange to use in the IPsec connection, ike defaults to ikev2, ikev1 assigns IKEV1 to the connection.leftauth=: The local server authentication type, accepted values include pubkey, psk, xauth, and eap.left=: The local server's public IP address.leftcert=: Server certificate located in the /etc/ipsec.d/certs directory.leftsubnet=: Local IP address of the Vultr VPC network interface.right=: The Remote Server's public IP address. For this article, the On-Premises server's IP address.rightid=: How the remote On-Premises server authenticates. vultruser represents the username in your secrets file. Other accepted values can be the IP address, or a fully qualified domain name (FQDN)rightsubnet=: The Local On-Premises network behind the main server or gateway.rightauth=: The remote server authentication type, IKEV2 supports multiple methods such as eap-mschapv2, IKEV1 only supports XAuth.Back up the original IPsec secrets file.
Create a new secrets file.
Open and edit the file.
Add the following configurations to the file. Replace vpn.example.com with your domain name.
Save and close the file.
You can create multiple users in the user : EAP password format.
Restart the IPsec daemon.
To allow the On-Premises server to communicate with hosts on your Vultr VPC network, enable kernel packet forwarding on the server as described below.
Back up the original sysctl.conf configuration file.
Add new forwarding rules to the file using the following command.
Reload kernel settings using the sysctl utility.
View all the server network interfaces.
Your output should look like the one below.
Using the iptables utility, forward all incoming network requests to the VPC network interface.
To enable internet access on the IPsec tunnel, also forward network traffic to the public network interface.
Restart the IPsec daemon.
By default, Uncomplicated Firewall (UFW) is pre-configured, and active on Vultr Ubuntu servers, configure the firewall to allow IPsec traffic to the server.
Verify that the firewall is running.
If inactive, activate it using the following command.
Allow IPsec connections on UDPs port 500, and 4500.
Verify the rules in your firewall table.
Your output should look like the one below.
Restart the firewall to load changes.
Using SSH, access the Debian Vultr VPC application server.
Ping the main Vultr server VPC address.
Output:
Press Control + C to stop the utility replies.
Verify your VPC network interface IP address.
Define a route to the On-Premises network with the main Vultr VPC server as the next hop.
Apply the above configuration on all hosts in the Vultr VPC network.
For purposes of this article, set up a basic web application on the server. First, install Nginx as the web server application.
Start Nginx.
Create a new index.html file in the /var/www/html web root directory.
Open and edit the file.
Add the following contents to the file.
Save and close the file.
Allow HTTP traffic on port 80 through the firewall.
Restart Nginx.
This section describes configurations you should apply on the main On-Premises server. These should be like those set on the main Vultr VPC server to create an IPsec tunnel successfully.
Use SSH to access a terminal session of your On-Premises server, or open a terminal session (Ctrl + Alt + T) if the server runs a desktop environment.
Install strongSwan and its extra plugins.
Using a secure terminal file transfer utility such as SCP or SFTP, connect to the Vultr VPC server and download the ca.cert.pem file to your server.
Back up the IPsec configuration file.
Create a new configuration file.
Open and edit the file.
Add the following configurations to the file. Replace 192.0.2.2 with your static public server IP address, and 192.168.1.1/24 with your actual local On-Premises network.
Save and close the file.
Back up the IPsec secrets file.
Create a new file.
Open and edit the file.
Add the following configurations to the file.
Save and close the file.
Make sure the username and password records match (except for the certificate directive) with those in the Vultr VPC server ipsec.secrets file.
Restart the IPsec daemon.
Allow SSH port 22 through the firewall.
Enable UFW on the On-Premises Ubuntu server if it's inactive.
Allow IPsec UDP ports 500 and 4500.
Verify the rules in your firewall table.
Restart the firewall to load changes.
Back up the original systcl.conf file.
Create and edit a new configuration file.
Add forwarding rules to the file using the following command.
Save and close the file.
Verify changes and reload settings.
View the server network interfaces, and keep note of the local interface.
Using iptables, forward incoming requests to the local network interface.
Access the Windows client machine on the host network.
Open the Windows command prompt or PowerShell from the start menu.
Ping the main On-Premises server local interface address.
Output:
Add a static route to the Vultr VPC network with the main OnPremises server as the next hop.
View the Windows routing table.
This section describes steps to test a successful connection between the On-Premises network and the Vultr VPC. If you have followed all steps correctly, you should be able to ping the main Vultr VPC server network address and access the internet through the IPsec tunnel. Likewise, the Vultr server should reach your On-Premises server's private address.
Hosts on both the On-Premises network must be able to reach hosts in the Vultr VPC. For this article, the Windows client machine should be able to reach the Debian application server. Likewise, the Debian server should be able to reach the Windows client machine.
Access the main On-Premises server.
Restart the IPsec daemon.
Connect to the IPsec tunnel profile as defined in your configuration file.
A successful connection output should look like the one below:
If the tunnel connection fails, details of the error display in your command output.
Verify the IPsec tunnel status.
Your output should look like the one below:
Using the ping utility, test the connection to the Vultr VPC interface.
Output:
Test the connection to your Vultr VPC web application server.
Output:
Access the main Vultr VPC server.
Verify that the IPsec tunnel is up.
Output:
Ping the main On-Premises server private IP address.
Output:
Ping the Windows client machine.
Output:
Access the Vultr VPC application server.
Ping the main On-Premises server private IP address.
Ping the Windows client machine.
Access the On-Premises Windows client machine.
Open the Windows command prompt.
Ping the Debian application server.
Output:
Using a web browser such as Chrome, visit the Vultr web application server VPC address.
Your Web Application should display in the browser window.
Road Warriors are devices that are not directly connected to the On-Premises Network. For example, multiple remote users who work from home, another office, or a public place such as a coffee shop or restaurant.
This section describes how you can allow Road Warriors to access the On-Premises to Vultr VPC network tunnel resources. These include a secure Internet connection through the VPC server and the ability to reach all hosts on both sides of the tunnel.
Access the main Vultr VPC server.
Back up the IPsec configuration file.
Open and edit the IPsec configuration file.
Add the following configurations at the end of the file.
Save and close the file.
The above configuration creates a new IPsec tunnel profile with different settings from the main On-Premises to Vultr VPC tunnel.
Open and edit the ipsec.secrets file.
Add the following directives at the end of the file to add new users.
Save and close the file.
Your edited file should look like the one below.
Restart IPsec.
Verify the IPsec status and confirm that the main On-Premises to Vultr tunnel is active.
If disconnected, re-establish the tunnel using the following command.
This section describes how Road Warriors can connect to the main Vultr VPC through a different IPsec tunnel that interconnects to the main On-Premises network tunnel. IPsec supports all types of devices, and on a smartphone, you should download the strongSwan application from the respective device store.
For a road warrior to successfully establish a tunnel connection, you must import the Vultr VPC server certificate to the device, then enter a valid username and password combination as set in the ipsec.secrets file. This article connects a macOS road warrior device to the Vultr VPC network through the following steps.
Open the Terminal application.
Using SCP, download the Vultr VPC server chain.pem certificate.
Enter your server SSH password when prompted.
Open the mac Finder Application.
Navigate to the directory where you downloaded the server certificate.
Double-click the certificate to open the Keychain access application and add it to your trusted server certificates.
In the Keychain access window, click Certificates in the left bottom Category section.
Enter your domain name in the search field to reveal your server certificate on the list.
Double-click the server certificate to open a separate pop-up window.
Expand Trust, and click the drop-down field next to IP Security (IPsec), then select Always Trust from the list of options.
Close the window and enter your mac user password to update settings.
Open System Preferences and navigate to Network.
Click the + create a new service symbol in the bottom left corner.
Click the Interface: drop-down and select VPN from the list.
Keep IKEV2 as the VPN type, and enter a custom Service Name: for your network.
Enter your domain name in the Server Address:, Remote ID: fields, then, enter your username in the Local ID: field.
Click Authentication Settings…, keep Username selected, then enter your username and associated password.
Click Apply, then click Connect to establish a connection to the Vultr VPC server.
When successful, open the Terminal app, then ping the main On-Premises server local address.
Ping the On-Premises Windows host.
Ping the Vultr VPC web application server.
All requests should be successful, and users should be able to access both On-Premises, and Vultr VPC networks.
On other devices, such as Windows, or Linux desktop, find the VPN network settings from your Network and Sharing menu.
Define static routes on each direct local network host with the main server as the next hop.
Setup proper iptables forwarding to the correct local network interface on both main tunnel servers.
Install and configure the iptables persistent package to load forwarding rules even after a restart.
Verify that you set the correct leftsubnet= and rightsubnet= network values in both main server configuration files.
Verify that you set the correct rightid, and the ipsec.secrets file settings are correct on both servers.
You have configured and connected your On-Premises network to a Vultr Virtual Private Cloud (VPC). The IPsec tunnel remains connected until the daemon receives a user action, such as shutting down or restarting the tunnel.
IPsec also supports multiple gateway devices, such as routers and firewalls, if your On-Premises network uses a static address on the main gateway interface, please visit the router documentation to connect your network to the Vultr VPC. For more information, please visit the following articles.
0 Comments
Be the first to comment and share your perspective with the community.