Configure IPSec VPN Gateway to Connect to External Systems using Strongswan
Create a new Virtual Machine on the same network as the rest of the cluster nodes. This machine will be used as a gateway to access the external IPs. This machine will need a public IP. The preferred OS is Ubuntu Server 20.04 or higher.
The rest of this guide will assume the following:
10.10.0.0/24
- the local network subnet.192.168.0.0/24
- the external network subnet which we are trying to reach over VPN.10.10.0.15
- the internal IP of the VPN gateway machine from Step 1.3.10.x.x
- Public IP of the VPN gateway machine from Step 1.4.10.y.y
- Public IP of VPN tunnel of the external Network.
VPN Gateway Setup:
Enable IP Forwarding on the node.
Create a file
/etc/sysctl.d/60-ip-forward.conf
with the following contents:Run this to apply the above config:
Install and configure Strongswan.
Install Strongswan, run:
Take backup of ipsec.conf, run:
Edit the /etc/ipsec.conf with the following contents:
Create
/etc/ipsec.secrets
with the following content:Start strongswan tunnel, run:
Check status by running:
Configure iptables (firewall).
Install
iptables-persistent
, run:Set default forward policy as DROP, run:
For each node that is allowed to access the external network, run the following: (The following is only an example, change it according to your system. To get the network interface names run:
ip link
)Enable NAT forwarding; run
Save the iptables changes for the next boot, run: (Make sure to run this whenever you change something on iptables)
Add an IP Route on all the other nodes that need to access the VPN, to hop over the VPN Gateway node. (If a global routing table exists on the network, this rule can be added there instead.)
Last updated