Connecting Alibaba Cloud to AWS with High Availability VPN

By Geoffrey Gao, Delivery Engineer II

This article discusses about a high availability VPN solution for connecting AWS VPC to Alibaba Cloud VPC network, with traffic being directed through the Internet. Users with accounts in both AWS and Alibaba Cloud can make a secure and high availability VPN connection to achieve a multi-cloud architecture.

The article is intended for IT engineers, network administrators, or software engineers who already have a basic understanding of AWS and Alibaba Cloud VPC network components, and familiar with VPN technology for connecting two isolated private network.

This document do not cover the best practise for IPv6.

We will be using AWS VPN Gateway and strongSwan project to build the VPN connection.


You should have:

  1. A certain familiarity with AWS and Alibaba Cloud
  2. Good understanding of the principles of networking, from setting IP addresses and firewalling by iptable tool
  3. Knowledge of the basic concepts of authentication based on public-key cryptography and a public-key infrastructure (PKI)

Specifically, I’m assuming that you have a VPC in each cloud, with the following configurations

  1. Non-overlapping networks in each VPC
  2. Public (and optionally private) subnets
  3. A routing table to route internet traffic for your public subnets via an Internet interface
  4. Appropriate security groups and attachments

High Availability VPN Connection between Alibaba Cloud and AWS

As we are going to connect a VPC in AWS to a VPC Alibaba Cloud to set up a multi-cloud infrastructure, we need to plan the network IPv4 CIDR block ahead to avoid the address block overlapping by these two VPCs. The architecture is shown below:

Configure strongSwan Servers in Alibaba Cloud

Configure two strongSwan servers in Alibaba Cloud VPC (vpc_ali)

For this discussion, we shall assume that vpc_ali is located in us-west-1 and has a network block of

Create a VPC on Alibaba Cloud with CIDR of (vpc_ali)

Create a public subnet in the vpc_ali with CIDR of

Launch two new ecs.n4.small instance in the public subnet of Alibaba Cloud VPC without default EIP attached.

Choose a CentOS 7u2 x86_64 Image

For now, ensure that your Security Groups are configured to permit SSH from your local workstation. We’ll need to reconfigure them later once both endpoints have been created.

Attach a new EIP to each the instance

Create a HAVIP address in the subnet with IP of and associate to an EIP.

SSH to the two ECS instance and install StrongSwan and its dependencies:

Enable IP forwarding by doing the following as root

Install Keepalived server in these two ECS instance

Configure keepalived in Master(ali_ecs1) and in Slave(ali_ecs2)

In the file, add the following content.

Save and exit the vi editor, and run the following commands:

The priority item of the Master need to be larger than the Slave, so you will need to change some of the configurations when you configure in a Slave server. This includes the state, priority number, virtual_ipaddress, unicast_src_ip, and unicast_peer

Run the following command to start the service:

Configure Routing

Navigate to your VPC console and bind the HAVIP to the two ECS instances:

We need to tell our VPCs how to route to AWS by VPN server with HAVIP bound, so we add a route rule in VRoute configuration:

Configuring AWS

Having created two strongSwan ECS instances with a known public HAVIP address, it’s time to create the other end of our tunnel in AWS VPC. For this discussion, we shall assume that vpc_aws is located in us-west-2 and has a network block of

A VPC on AWS with CIDR of (vpc_aws)

A public subnet in the VPC with CIDR block of

it has a route table item of route to internet gateway

Configure AWS VPN gateway for connecting to Alibaba Cloud,

  1. Navigate to the VPC Dashboard in the AWS Console
  2. Make sure you are in the correct region(us-west-2)
  3. Select the ‘Virtual Private Gateways’ menu item
  4. Click ‘Create Virtual Private Gateway’
  5. Give your new VGW a name
  6. Select ‘Yes, Create’
  7. Once your VGW has been created, select it, and then click ‘Attach to VPC’
  8. Select the target VPC from the VPC drop-down list
  9. Select the ‘Customer Gateways’ menu item
  10. Click ‘Create Customer Gateway’
  11. Give your CGW a name
  12. Set routing to Static
  13. Set the public IP address of the remote end of the VPN connection, i.e. the VOIP of the Alibaba Cloud strongSwan instance.
  14. Click ‘Yes, Create’
  15. Select the ‘VPN Connections’ menu item
  16. Click ‘Create VPN Connection’
  17. Name: Give your VPN connection a name
  18. Virtual Private Gateway: Select the VGW you created in step 4
  19. Customer Gateway: Select ‘Existing’ and choose the CGW you created in step 8
  20. Routing Options: Static
  21. Static IP Prefixes: Set the CIDR block of your VPC you wish to make available over the VPN tunnel, e.g. for the entire VPC network
  22. Click ‘Yes, Create’

VPN Connections:

There two VPN tunnel created:

Once the VPN has been created, right-click on the entry and select the option to download the configuration file. Select the generic configuration option. This will save a text file to your local workstation with the information that will be needed to configure the strongSwan instance in the Alibaba Cloud VPC.

Now SSH to Alibaba Cloud ECS instances to configure strongSwan tunnels. Open the strongSwan IPSec file and edit it:

Configure the file as follows:

Configure the secret keys /etc/strongswan/ipsec.secrets

Restart strongSwan and make sure the service is running.

Testing the VPN Tunnel

Now that we have both ends of the tunnel created, we need to ensure that they can talk to each other.

Create another Alibaba Cloud ECS and AWS EC2 instances in the corresponding subnet then SSH to the ECS instance and ping AWS EC2 instance by private IP address for an ICMP testing.

Check the AWS VPN connection tunnel status on the console, the status of one of the tunnels already turn to UP.

Update Security Groups

Now, we’ll create a Security Group (or modify an existing one) to contain rules to permit the public traffic necessary to set up the IPSec tunnel. Configure your security group as per the table below.

You don’t need to do anything particular on the AWS side to permit traffic; this was addressed implicitly behind the scenes when you created the Customer Gateway earlier on. You’ll just need to make sure that any security groups on either side of the tunnel explicitly allow traffic from the opposite network.


Hopefully you have been able to follow the steps above to bring up your own IPSec tunnel between Alibaba Cloud VPC and AWS VPC. AWS VPNs provide two tunnels for redundancy as AWS may perform maintenance on one of the tunnels from time to time. Having two established tunnels allows you to keep communicating over the VPN during these maintenance windows.

Further Reading



Follow me to keep abreast with the latest technology news, industry insights, and developer trends.