By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
IT Infras HolicIT Infras HolicIT Infras Holic
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Search
  • Privacy Policy
© 2024. All Rights Reserved.
Font ResizerAa
IT Infras HolicIT Infras Holic
Font ResizerAa
  • News
  • Linux
  • Docker
  • Web Server
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
Search
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Follow US
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
IT Infras Holic > Blog > Cloud Services > Google Cloud Platform (GCP) > How to set up a VPN Site to Site (VPN S2S) between StrongSwan and Google Cloud VPN
Google Cloud Platform (GCP)Cloud ServicesUbuntu

How to set up a VPN Site to Site (VPN S2S) between StrongSwan and Google Cloud VPN

writer
Share
8 Min Read
SHARE

How to set up a VPN Site to Site (VPN S2S) between StrongSwan and Cloud VPN

Requirement

  1. GCP Console
  2. VM with Ubuntu 22.04 or CentOS
  3. VM Directly Connected to IP Public, or
  4. VM Behind NAT, & these port must be forwarded : UDP port 500, UDP port 4500, and allow ESP packets

Topology

strongswan-cloudvpn-topology

VPN Parameter

IPsec parameters

Cloud VPN supports an extensive list of ciphers that can be used per your security policies. The following parameters and values are used in the Gateway’s IPsec configuration for the purpose of this guide.

Parameter Value
IPsec Mode Tunnel mode
Auth protocol Pre-shared-key
Key Exchange IKEv2
Start Auto
Perfect Forward Secrecy (PFS) on

These are the Cipher configuration settings for IKE phase 1 and phase 2 that are used in this guide.

Phase Cipher role Cipher
Phase-1 Encryption aes256
(ike) Integrity sha1
Diffie-Helman modp1024
Phase1 lifetime 28800
Phase-2 Encryption aes256
(esp) Integrity sha1
Diffie-Helman modp1024
Phase2 lifetime 3600

 

Configuring policy-based IPsec VPN

Below is a sample environment to walk you through the setup of a policy-based VPN. Make sure to replace the IP addresses in the sample environment with your own IP addresses.

Cloud VPN

Name Value
Cloud VPN(external IP) 34.101.103.43
VPC CIDR 10.215.10.0/24

strongSwan

Name Value
External IP 104.178.245.31
CIDR Behind strongSwan 10.216.103.0/24

 

Configuration of Google Cloud

To configure Cloud VPN:

In the Cloud Console, select Networking > Create VPN connection.

Click CREATE VPN CONNECTION.

Populate the fields for the gateway and tunnel as shown in the following table, and click Create:

Parameter Value Description
Name gcp-to-strongswan-1 Name of the VPN gateway.
Description VPN tunnel connection between GCP and strongSwan Description of the VPN connection.
Network to-sw The Google Cloud network the VPN gateway attaches to. This network will get VPN connectivity.
Region europe-west4 The home region of the VPN gateway. Make sure the VPN gateway is in the same region as the subnetworks it is connecting to.
IP address gcp-to-strongswan(34.101.103.43) The VPN gateway uses the static public IP address. An existing, unused, static public IP address within the project can be assigned, or a new one created.
Remote peer IP address 104.178.245.31 Public IP address of the on-premises VPN appliance used to connect to the Cloud VPN.
IKE version IKEv2 The IKE protocol version. You can select IKEv1 or IKEv2.
Shared secret RSgu90cStYM60GnE8YajIVnRebRjHQOQ A shared secret used for authentication by the VPN gateways. Configure the on-premises VPN gateway tunnel entry with the same shared secret.
Routing options Policy-based Multiple routing options for the exchange of route information between the VPN gateways. This example uses static routing.
Remote network IP ranges 10.215.10.0/24 The on-premises CIDR blocks connecting to Google Cloud from the VPN gateway.
Local IP ranges 10.216.103.0/24 The Google Cloud IP ranges matching the selected subnet.

 

StrongSwan Setup

Installation of StrongSwan

1
sudo apt update && sudo apt upgrade -y

 

Configure the kernel to enable packet forwarding for IPv4. Edit the configuration file

1
sudo nano /etc/sysctl.conf

Add the following lines at the end of the file.

1
2
3
4
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0

Save and exit the file then run the following command to load settings.

1
sudo sysctl -p

Install strongSwan and supporting dependencies:

1
sudo apt install strongswan strongswan-pki libcharon-extra-plugins libcharon-extauth-plugins libstrongswan-extra-plugins libtss2-tcti-tabrmd0 -y

Set the service to start on boot.

1
2
sudo systemctl enable strongswan-starter
sudo systemctl is-enabled strongswan-starter

Check for the service status

1
2
3
4
5
6
7
8
9
10
11
$ systemctl status strongswan-starter
● strongswan-starter.service - strongSwan IPsec IKEv1/IKEv2 daemon using ipsec.>
     Loaded: loaded (/lib/systemd/system/strongswan-starter.service; enabled; v>
     Active: active (running) since Wed 2022-10-19 20:40:14 EAT; 2min 1s ago
   Main PID: 2647 (starter)
      Tasks: 18 (limit: 9457)
     Memory: 5.7M
        CPU: 41ms
     CGroup: /system.slice/strongswan-starter.service
             ├─2647 /usr/lib/ipsec/starter --daemon charon --nofork
             └─2655 /usr/lib/ipsec/charon

 

Configure IPSEC Preshared Key

Add the Key to /etc/ipsec.secrets file

1
sudo nano /etc/ipsec.secrets

Add the key:

the syntax is : <peer IP> : PSK “preshared key”

1
34.101.103.43 : PSK "RSgu90cStYM60GnE8YajIVnRebRjHQOQ"

Save and exit the file.

Configure IPSEC conf File

Make a copy of the configuration file then set up the VPN configuration on that file.

1
2
sudo cp /etc/ipsec.conf /etc/ipsec.conf.orig
sudo nano /etc/ipsec.conf

Add the following details to the file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
config setup
       charondebug="all"
       uniqueids=yes
conn SiteA-SiteB
       type=tunnel
       auto=start
       keyexchange=ikev2
       authby=secret
       left=34.101.103.43
       leftsubnet=10.215.10.0/24
       right=104.178.245.31
       rightsubnet=10.216.103.0/24
       ike=aes256-sha1-modp1024!
       esp=aes256-sha1!
       aggressive=no
       keyingtries=%forever
       ikelifetime=28800s
       lifetime=3600s
       dpddelay=30s
       dpdtimeout=120s
       dpdaction=restart

Using Multiple Subnet or Host

add additional subnet or host to leftsubnet or rightsubnet, separate by comma

Save and exit the file.

Glosary

  • config setup specifies general configuration information for IPSec which applies to all connections.
  • charondebug = “all” defines how much Charon debugging output should be logged.
  • uniqueids = yes states whether a particular participant ID should be kept unique.
  • conn SiteA-SiteB is the connection name.
  • authby=secret specifies how the connection is authenticated.
  • auto=start allows the connection to start by default.
  • type=tunnel is the type of connection.
  • left=138.201.255.67 is the public IP address of server A.
  • leftsubnet=192.168.200.43/24 is the subnet/private IP of server A.
  • right=95.217.16.14 is the public IP address of server B/remote server.
  • rightsubnet=192.168.200.130/24 is the subnet/private IP of server B.
  • ike=aes256-sha1-modp1024 is the type of encryption when the Internet key exchange.
  • keyexchange=ikev2 is the Internet key exchange version.
  • ikelifetime=28800s is the time before the re-authentication of keys.
  • esp=aes256-sha1! is the encapsulation security suite of protocols.
  • aggressive states whether to use Aggressive or Main Mode.
  • keyingtries states the number of attempts that should be made to negotiate a connection.
  • lifetime defines how long a particular instance of a connection should last, from successful negotiation to expiry.
  • dpddelay specifies the time interval with which exchanges are sent to the peer.
  • dpdtimeout specifies the timeout interval to delete connections in case of inactivity.
  • dpdaction states how to use the Dead Peer Detection(DPD) protocol to manage the connection.

 

If you have an active firewall, configure it to add the rules

1
sudo iptables -t nat -A POSTROUTING -s 10.216.103.0/24 -d 10.215.10.0/24 -j MASQUERADE

 

Restart the VPN

1
sudo ipsec restart

You can start and stop IPsec with the following command

1
2
3
sudo ipsec stop
sudo ipsec start
 

Setup Routing on Strongswan Local network

Login to VM in the same network with strongswan VM, for example VM 10.216.103.100

Add routing to GCP side Network via Strongswan VM as gateway

1
ip route add 10.215.10.0/24 via 10.216.103.105

Don't forget to set permanent routing so it will permanent even when you restart the VM, read this

Test connection from both side, if you still cannot reach GCP side from Strongswan side, try open/ setup Firewall in GCP

You Might Also Like

Install Cyberpanel on Ubuntu 22.04

UFW Linux Firewall Cheatsheet

How to Uninstall CloudMonitor Agent (Alibaba CLoud)

TAGGED: gcp, site2site, strongswan, ubuntu, vpn
Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Telegram Copy Link
Previous Article UFW Linux Firewall Cheatsheet UFW Linux Firewall Cheatsheet
Next Article How to map SFTP as a drive on Windows 10 How to map SFTP as a drive on Windows 10
5 Comments
  • Kang Gali says:
    March 30, 2023 at 9:05 pm

    top

    Reply
  • boostaro says:
    January 9, 2024 at 7:00 am

    Thanks for thr great article!

    Reply
  • uc satın al says:
    January 13, 2024 at 1:35 am

    Thanks for thr great article!

    Reply
  • Aida Jones says:
    March 24, 2024 at 12:53 am

    I am not real superb with English but I line up this very easygoing to read.

    Reply
  • uc satın al says:
    April 3, 2024 at 11:03 am

    Thank you so much!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest News

bash
Monitoring File & Directory Changes using Bash Script
Linux Application
vulnerability
Vulnerability Checker CVE-2024-3094
Linux
wiki.js
Unleashing the Potential of Knowledge Management with Wiki.js
Application Linux
Install Apache Guacamole
How to Install Apache Guacamole with Docker Compose
Application Linux
Follow US
© 2024
activity notes activity notes
Welcome Back!

Sign in to your account

Lost your password?