Setting Up a Site-to-Site VPN Between AWS Mumbai and Singapore Regions

AWS Site-to-Site VPN enables seamless, secure connectivity between your on-premises environment (or customer-end resources) and AWS. In this guide, we'll configure a Site-to-Site VPN between two VPCs: one in Mumbai (representing AWS) and another in Singapore (representing the customer-end).

By default, instances that we launch into an Amazon VPC can't communicate with our own (corporate or home network) network. To enable the communication, we have to establish a Site-to-Site VPN connection.

VPN Connection: A secure connection between our on-premises equipment and our VPCs.

VPN Tunnel: An encrypted link where data can pass from the customer network to or from AWS. Each VPN connection includes two VPN tunnels, which we can simultaneously use for high availability.

Customer Gateway: An AWS resource that provides information to AWS about our customer gateway device.

Customer Gateway Device: A physical or software application on the customer's side.

Steps to Set Up the Site-to-Site VPN

Step 1: Create Two VPCs

  1. Mumbai Region (AWS Side)

    • Open the VPC Console and switch to the Mumbai region.

    • Click Create VPC and configure:

      • CIDR Block: 10.0.0.0/16

      • Name Tag: Mumbai-VPC

    • Add a public subnet: 10.0.1.0/24.

    • Attach an internet gateway and update the route table for internet access.

  2. Singapore Region (Customer End)

    • Switch to the Singapore region.

    • Create another VPC:

      • CIDR Block: 192.168.0.0/16

      • Name Tag: Singapore-VPC

    • Add a public subnet: 192.168.1.0/24.

    • Attach an internet gateway and update the route table for internet access.

Step 2: Launch EC2 Instances in Both Regions

  1. Mumbai Region EC2 (AWS Side)

    • Launch an Amazon Linux EC2 instance in Mumbai-VPC.

    • Instance Type: t2.micro

    • Subnet: 10.0.1.0/24

    • Security Group:

      • Allow SSH (TCP:22) for remote access.

      • Allow ICMP (for ping testing).

    • Download the key pair for SSH access.

  2. Singapore Region EC2 (Customer Side)

    • Launch an Amazon Linux EC2 instance in Singapore-VPC.

    • Instance Type: t2.micro

    • Subnet: 192.168.1.0/24

    • Security Group:

      • Same as above: SSH and ICMP rules.

Step 3: Create a Virtual Private Gateway (Mumbai Region)

  1. Switch to the Mumbai region.

  2. In the VPC Console, go to VPN Connections > Virtual Private Gateways.

  3. Click Create Virtual Private Gateway:

    • Name Tag: Mumbai-VGW.

    • ASN: Leave as default or use a custom ASN.

  4. Attach the Virtual Private Gateway to the Mumbai-VPC:

    • Go to Actions > Attach to VPC and select Mumbai-VPC.

Step 4: Create a Customer Gateway (Mumbai Region)

  1. Stay in the Mumbai region and go to Customer Gateways in the VPC Console.

  2. Click Create Customer Gateway:

    • Name Tag: Singapore-CGW.

    • Routing Type: Static.

    • Enter the public IP of the Singapore EC2 instance.

  3. Click Create Customer Gateway.

Step 5: Create a Site-to-Site VPN Connection

  1. In the Mumbai region, go to VPN Connections.

  2. Click Create VPN Connection:

    • Name Tag: Mumbai-SiteToSite-VPN.

    • Target Gateway: Select Mumbai-VGW.

    • Customer Gateway: Select Singapore-CGW.

    • Routing Options: Enter the customer-end subnet CIDR (192.168.0.0/16) for static routing.

  3. Click Create VPN Connection and wait for it to be created.

  4. Select the VPN connection and click Download Configuration:

    • Choose your router platform or generic vendor.

    • Save the configuration file for later use.

Step 6: Configure Route Tables (Mumbai Region)

  1. In the Mumbai region, go to Route Tables under the VPC Console.

  2. Select the route table associated with the Mumbai-VPC public subnet.

  3. Enable Route Propagation:

    • Go to the Route Propagation tab.

    • Add the Mumbai-VGW.

Step 7:Setup on machine of customer end ( Singapore Region )

Configuring Both Tunnels for AWS Site-to-Site VPN Using Openswan on ec2 on singapore region

  1. Switch to the root user:

     sudo su
    
  2. Install Openswan:

     yum install openswan -y
    
  3. Update the configuration file:
    Open /etc/ipsec.conf and ensure the following line is uncommented (if not already):

     include /etc/ipsec.d/*.conf
    
  4. Enable IP forwarding:
    Update /etc/sysctl.conf with the following values:

     net.ipv4.ip_forward = 1
     net.ipv4.conf.all.accept_redirects = 0
     net.ipv4.conf.all.send_redirects = 0
    

    Apply changes by restarting the network service:

     service network restart
    

Step 2: Create Tunnel Configuration

You need to create a separate configuration for each tunnel under /etc/ipsec.d/.

  1. For Tunnel 1:
    Create a file named /etc/ipsec.d/aws-vpn-tunnel1.conf with the following contents:

     Tunnel1
         authby=secret
         auto=start
         left=%defaultroute
         leftid=<Customer Gateway Public IP>
         right=<AWS VGW Tunnel1 Public IP>
         type=tunnel
         ikelifetime=8h
         keylife=1h
         phase2alg=aes128-sha1;modp1024
         ike=aes128-sha1;modp1024
         keyingtries=%forever
         keyexchange=ike
         leftsubnet=<Customer VPC CIDR>
         rightsubnet=<AWS VPC CIDR>
         dpddelay=10
         dpdtimeout=30
         dpdaction=restart_by_peer
    
  2. For Tunnel 2:
    Similarly, create /etc/ipsec.d/aws-vpn-tunnel2.conf:

     bashCopy codeconn Tunnel2
         authby=secret
         auto=start
         left=%defaultroute
         leftid=<Customer Gateway Public IP>
         right=<AWS VGW Tunnel2 Public IP>
         type=tunnel
         ikelifetime=8h
         keylife=1h
         phase2alg=aes128-sha1;modp1024
         ike=aes128-sha1;modp1024
         keyingtries=%forever
         keyexchange=ike
         leftsubnet=<Customer VPC CIDR>
         rightsubnet=<AWS VPC CIDR>
         dpddelay=10
         dpdtimeout=30
         dpdaction=restart_by_peer
    

Step 3: Configure Shared Secrets

  1. Open /etc/ipsec.d/aws-vpn.secrets and add shared secrets for both tunnels:

     <Customer Gateway Public IP> <AWS Tunnel1 Public IP>: PSK "shared_secret_for_tunnel1"
     <Customer Gateway Public IP> <AWS Tunnel2 Public IP>: PSK "shared_secret_for_tunnel2"
    
  2. Ensure the shared secret matches the one provided in the AWS VPN configuration file.

Step 4: Enable and Start the IPsec Service

  1. Enable the IPsec service:

     chkconfig ipsec on
    
  2. Start the IPsec service:

     service ipsec start
    
  3. Check the status of the service:

     service ipsec status
    

Test connectivity between the instances:

  • From the Singapore EC2 instance, ping the private IP of the Mumbai EC2 instance.

  • From the Mumbai EC2 instance, ping the private IP of the Singapore EC2 instance.