Configuring OpenSwan/LibreSwan IPSec Tunnel Between AWS and ON-PREM

TUNNELING AWS-ONPREM

Raju Banerjee
ThoughtPillars@Cloud
5 min readMay 21, 2018

--

IPSEC Tunnel

IntroductionWalk through the creating IPSEC tunnel between AWS and ON-PREM

Site to Site Tunnel between AWS and ON-Prem :

Prerequisite:

Get the connection information from the client :

AWS Setup Configuration :

  1. Select the region from AWS Dashboard, choose the region which is near for your DC, if it’s located in India, choose Mumbai Region from AWS console to avoid latency.
  2. Create a VPC from the AWS Dashboard

3. In the above diagram, we have selected VPC with Public and Private subnet, in this case one subnet will have Internet gateway and other machine will be in private subnet. You can add other subnets as well once the VPC setup done.

4. Now go to your AWS EC2 dashboard console. Select EC2 AMI from the list- Centos or Ubuntu and launch a server with min configuration of 2 core and 4GB RAM.

5. Make sure you have selected the same VPC and Subnets that we have created for this setup. Proceed with launching the machine in public subnet.Once launched, let’s assign a static IP i.e EIP with the machine, so that it won’t change in further. Let’s assume AWS EIP — 35.201.104.15

6. Now time to configure Security group : As it’s very crucial machine make sure we have proper firewall/security rule in place to protect the machine from vulnerabilities.

Open the below ports in the security group :

  1. SSH — 22 for internal office IP
  2. UDP — 4500 to the DC router/firewall/Host IP
  3. UDP — 500 to the DC router/firewall/Host IP

In our case :

7. Time for command line action:

Login into your EC2 machine and execute below commands from a root user :

8. vim /etc/sysctl.conf and change:

And then append below lines in the config file:

9. Now install libreswan or openswan in the EC2 machine using yum :

10. Once installation is done, let’s start configuring As now we have all the connection information, let’s get started with configuring the tunnel

11. Create a connection file, better to create a separate file for each connection :

12. And append the below config and modify accordingly the connection details :

13. Add or modify the config file — sysctl.conf :

vim /etc/sysctl.conf

14. Now add the PSK key that’s been shared :

vim /etc/ipsec.secrets : take a backup and empty the content of the file

15. Once the above service is up, we will now make the network ip

After this command execute :

Once the above steps completed, disable the source and destination check:

  1. Go to ec2 console, right click on the instance and select Networking : change source/destination check disable.
Networking source/destination

2. Now go to VPC section, and Filter your VPC and click on route table add the entry of your destination subnet range and add the target as the instance where we have configured our solution.

Route Table

Vice versa entry will be added in the DC firewall rules as well, to allow AWS network.

Few important commands to check the status of the tunnel for troubleshooting :

Host to Host Tunnel :

In this case, follow the same steps just you don’t have to disable source and destination check and also no need of changing route table.

In you datacentre Box, add the route table to allow traffic from the AWS machine IP :

Something like :

Note: Mentioned IP’s are just example and subjected to change as per your network infrastructure.

Hope this is useful!! Please share your feedback :-)

--

--