ℹ️ Overview This is the most critical step - configuring Libreswan IPsec on EC2 Customer Gateway to establish VPN tunnels with AWS.

In the Download Configuration dialog
💡 Note: Libreswan is the successor to OpenSwan, configurations are compatible


sudo dnf install libreswan -y
💡 Libreswan: IPsec VPN implementation for Linux, successor to OpenSwan

sudo vi /etc/ipsec.conf

sudo vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
⚠️ Important: IP forwarding is required for Customer Gateway to route traffic between VPN tunnel and local network


sudo sysctl -p

sudo vi /etc/ipsec.d/aws.conf
🔑 Key Parameters:
💡 Important Notes:
auth=esp line (not needed for Amazon Linux)modp1024 to modp2048 (higher security)config setup with uniqueids=no at file startauto=route to auto=start



sudo touch /etc/ipsec.d/aws.secrets

sudo vi /etc/ipsec.d/aws.secrets
🔐 Format:
<Customer Gateway Public IP> <AWS VPN Endpoint IP>: PSK "<pre-shared-key>"

Press ESC and :wq! to save
Verify file:
sudo cat /etc/ipsec.d/aws.secrets

sudo systemctl restart systemd-networkd
sudo systemctl enable ipsec
sudo systemctl start ipsec
sudo systemctl status ipsec
✅ Expected Result: Service status = active (running)

sudo systemctl restart systemd-networkd
sudo systemctl restart ipsec

💡 Check tunnel status:
sudo ipsec status
ping <EC2-Private-IP> -c5
✅ Success: Receiving ping replies through VPN tunnel

ping <Customer-Gateway-Private-IP> -c5
✅ Success: Bidirectional VPN connectivity working!

🏗️ Complete VPN Architecture
AWS VPC (10.10.0.0/16)
├── EC2 Private (10.10.4.x)
↓
Virtual Private Gateway
↓
VPN Tunnel (IPsec) - ESTABLISHED ✅
├── Tunnel 1: UP
└── Tunnel 2: Standby
↓
Customer Gateway (Libreswan)
├── Public IP: x.x.x.x
└── Private IP: 10.11.1.x
↓
VPN VPC (10.11.0.0/16)
💡 Troubleshooting Tips:
sudo journalctl -u ipsec -fsudo ipsec statusip route showsudo ip route add 10.10.4.0/24 dev ens5🔒 Security Notes:
chmod 600 /etc/ipsec.d/aws.secrets✅ Completed: VPN Site-to-Site is successfully configured and operational!