Connect an Alibaba Cloud VPC to an AWS VPC

更新时间:
复制 MD 格式

Connect an Alibaba Cloud Virtual Private Cloud (VPC) to an AWS VPC over an encrypted IPsec-VPN tunnel. You create one dual-tunnel IPsec-VPN connection on Alibaba Cloud and two site-to-site VPN connections on AWS — one per tunnel — so that both tunnels stay active and provide high availability.

This procedure incurs charges on both platforms. Alibaba Cloud charges for the VPN Gateway instance and data transfer. AWS charges for the site-to-site VPN connections and data transfer.

What you'll do

Step Action Platform
1 Create a VPN Gateway instance Alibaba Cloud
2 Create customer gateways, a virtual private gateway, and site-to-site VPN connections AWS
3 Create customer gateways and an IPsec-VPN connection; configure routes Alibaba Cloud
4 Verify connectivity and test failover Both

Estimated time: 30–60 minutes (excluding gateway provisioning, which takes 1–5 minutes).

Example scenario

An enterprise has a VPC in the Alibaba Cloud Germany (Frankfurt) region and a VPC in the AWS Europe (Frankfurt) region and wants to enable encrypted communication between them.

image

Network planning

Important

The CIDR blocks of the networks you want to connect must not overlap.

VPC CIDR blocks

Resource VPC CIDR block vSwitch/subnet Zone Instance IP
Alibaba Cloud VPC 10.0.0.0/16 vSwitch 1: 10.0.0.0/24 Zone B ECS: 10.0.0.223
vSwitch 2: 10.0.10.0/24 Zone C
AWS VPC 192.168.0.0/16 Subnet: 192.168.10.0/24 eu-central-1a EC2: 192.168.10.113

BGP CIDR block planning

Skip this section if you plan to use static routing only.

Both tunnels on the Alibaba Cloud side must use the same Local ASN. The peer BGP ASNs for the two tunnels can differ, but using the same peer BGP ASN for both is recommended.
Resource Connection Tunnel BGP tunnel CIDR block BGP IP address Local ASN
Alibaba Cloud VPN Gateway IPsec-VPN connection Primary tunnel 169.254.116.208/30 169.254.116.210 65530
Standby tunnel 169.254.214.96/30 169.254.214.98
AWS virtual private gateway Site-to-Site VPN Connection 1 Tunnel 1 169.254.116.208/30 169.254.116.209 64512
Tunnel 2 (not used)
Site-to-Site VPN Connection 2 Tunnel 1 169.254.214.96/30 169.254.214.97
Tunnel 2 (not used)
Each BGP tunnel CIDR block must be unique within a VPN Gateway instance.

Prerequisites

Before you begin, make sure you have:

  • A VPC in the Alibaba Cloud Germany (Frankfurt) region with at least two vSwitches in different zones, and an Elastic Compute Service (ECS) instance deployed in it. See Create a VPC with an IPv4 CIDR block.

  • A VPC in the AWS Europe (Frankfurt) region with an EC2 instance deployed in it. See the AWS platform.

Step 1: Create a VPN Gateway instance on Alibaba Cloud

The VPN Gateway is the Alibaba Cloud-side endpoint. After creation, the system assigns two IP addresses to it — one per tunnel — which you use when configuring the AWS side.

  1. Log on to the VPN Gateway console.

  2. In the top navigation bar, select Germany (Frankfurt). The VPN Gateway must be in the same region as the VPC you want to connect.

  3. On the VPN Gateways page, click Create VPN Gateway.

  4. On the purchase page, configure the following settings. For parameters not listed here, keep the default values. For details, see Create and manage a VPN Gateway instance.

    After a VPN Gateway instance is created, you cannot change its associated vSwitches.
    Parameter Description Example value
    Instance Name Name for the VPN Gateway instance. VPN Gateway
    Region Region where the VPN Gateway is located. Germany (Frankfurt)
    Gateway Type Type of the VPN Gateway instance. Standard
    Network Type Network type of the VPN Gateway instance. Public
    Tunnel Tunnel mode for IPsec-VPN connections in this region. Options: Dual-tunnel or Single-tunnel. Dual-tunnel (default)
    VPCVPCVPC VPC to associate with the VPN Gateway instance. VPC in Alibaba Cloud Germany (Frankfurt) region
    vSwitch First vSwitch in the VPC. In dual-tunnel mode, the system creates an elastic network interface (ENI) in each vSwitch for VPC-to-IPsec-VPN traffic. Each ENI occupies one IP address in its vSwitch. First vSwitch in the VPC
    vSwitch 2 Second vSwitch in the VPC, in a different zone. This enables zone-level disaster recovery for the IPsec-VPN connection. For regions with only one zone, you can select any vSwitch — even the same one as vSwitch 1. Second vSwitch in the VPC
    IPsec-VPN Whether to enable the IPsec-VPN feature. Default: Enable. Enable
    SSL-VPN Whether to enable the SSL-VPN feature. Default: Disable. Disable
  5. Click Buy Now and complete the payment.

  6. Return to the VPN Gateways page. Wait until the status changes from Preparing to Active (1–5 minutes). The system assigns two IP addresses to the instance: Keep these IP addresses on hand — you use them in Step 2.

    VPN Gateway name VPN Gateway instance ID IP address
    VPN Gateway vpn-gw8dickm386d2qi2g**** IPsec Address 1 (active tunnel): 8.XX.XX.146
    IPsec Address 2 (standby tunnel): 8.XX.XX.74

Step 2: Deploy the VPN on AWS

Important

Both Alibaba Cloud and AWS IPsec-VPN connections support dual-tunnel mode. However, AWS associates both tunnels with the same customer gateway by default, while the two tunnels on the Alibaba Cloud side have different IP addresses. To establish a one-to-one tunnel mapping, create two separate site-to-site VPN connections on AWS, each associated with a different customer gateway.

Configure the AWS side based on your routing method. For specific console steps, refer to the AWS documentation.

Use static routing

  1. Create two customer gateways. Use the two IP addresses of the Alibaba Cloud VPN Gateway instance as the customer gateway IP addresses.

    Create two customer gateways named aliyun1 and aliyun2. Set the BGP ASN to 65530 for both. Use the two public IP addresses of the Alibaba Cloud VPN Gateway instance as the customer gateway IP addresses. Set the type to ipsec.1 for both. After creation, the status of both customer gateways shows Available.

  2. Create a virtual private gateway. Create a virtual private gateway and attach it to the AWS VPC.

    After creation, the virtual private gateway status shows Attached, the type is ipsec.1, and the Amazon ASN is 64512. Record the VPC ID associated with this gateway — you need it in subsequent configurations.

  3. Create two site-to-site VPN connections. Associate each VPN connection with a different customer gateway. The following shows the configuration for one connection — the other uses the second customer gateway with the same remaining settings. Keep the tunnel options at their default values. After creation, note the outside IP address of Tunnel 1 for each VPN connection — you use these in Step 3.

    Set Local IPv4 Network CIDR to the Alibaba Cloud VPC CIDR block and Remote IPv4 Network CIDR to the AWS VPC CIDR block.
    Site-to-site VPN connection Tunnel Outside IP address Associated customer gateway IP
    Site-to-Site VPN Connection 1 Tunnel 1 3.XX.XX.52 8.XX.XX.146
    Site-to-Site VPN Connection 2 Tunnel 1 3.XX.XX.56 8.XX.XX.74

    In the Details section of the site-to-site VPN connection creation page, configure the following parameters:

    • Name tag: Enter vpn-01

    • Target gateway type: Select Virtual private gateway and choose the virtual private gateway you created

    • Customer gateway: Select Existing and choose the customer gateway you created from the Customer gateway ID drop-down list

    • Routing options: Select Static

    • Static IP prefixes: Enter 10.0.0.0/16

    • Local IPv4 network CIDR: Enter 10.0.0.0/16

    • Remote IPv4 network CIDR: Enter 192.168.0.0/16

    On the Tunnel Details tab of the site-to-site VPN connection, you can view the Outside IP address and Inside IPv4 CIDR for each tunnel. At this point, both tunnels show a Down (not connected) status, which is expected.

  4. Enable route propagation. In the route table of the VPC associated with the virtual private gateway, enable route propagation so that routes from the site-to-site VPN connections are automatically propagated to the VPC route table.

    On the Route Table details page, select the Route Propagation tab and confirm that the Propagation column for the target virtual private gateway shows Yes, indicating that automatic route propagation is enabled.

Use BGP dynamic routing

  1. Create two customer gateways. Use the two IP addresses of the Alibaba Cloud VPN Gateway instance as the customer gateway IP addresses. Register the BGP Autonomous System Number (ASN) of the Alibaba Cloud IPsec-VPN connection.

    In the Customer Gateways page of the AWS VPN console, create two customer gateways:

    • aliyun1: BGP ASN 65530, IP address is the first public IP of the Alibaba Cloud VPN Gateway instance.

    • aliyun2: BGP ASN 65530, IP address is the second public IP of the Alibaba Cloud VPN Gateway instance.

    Both gateway types are ipsec.1, and both statuses show Available.

  2. Create a virtual private gateway. Create a virtual private gateway, specify the BGP ASN for the AWS side, and attach the gateway to the AWS VPC.

    After creation, confirm that the virtual private gateway status is Attached, it is associated with the target VPC, and the Amazon ASN is 64512.

  3. Create two site-to-site VPN connections. Associate each VPN connection with a different customer gateway. The following shows the configuration for one connection. For the second connection, set Tunnel 1 Inside IPv4 CIDR to 169.254.214.96/30; all other settings are the same. After creation, view the tunnel details to get the outside IP addresses and BGP IP addresses.

    Set Local IPv4 Network CIDR to the Alibaba Cloud VPC CIDR block and Remote IPv4 Network CIDR to the AWS VPC CIDR block.

    Configure the key parameters on the VPN connection creation page:

    • Target gateway type: Select Virtual private gateway

    • Customer gateway: Select Existing and choose the customer gateway you created in the Customer gateway ID field

    • Routing options: Select Dynamic (requires BGP)

    • Local IPv4 network CIDR: Enter 10.0.0.0/16

    • Remote IPv4 network CIDR: Enter 192.168.0.0/16

    • Tunnel 1 inside IPv4 CIDR: Enter 169.254.116.208/30

    • Tunnel 1 pre-shared key: Enter a custom pre-shared key

    After creating the site-to-site VPN connection, click the Tunnel Details tab on the VPN connection page to view tunnel information. Record the Outside IP address and Inside IPv4 CIDR of Tunnel 1 (in this example, 169.254.116.208/30). You need this information when configuring the IPsec-VPN connection on the Alibaba Cloud side. At this point, both tunnels show a Down (not connected) status, which is expected.

  4. Get the pre-shared key and BGP IP addresses for the Alibaba Cloud side. Download the VPN configuration file for the Alibaba Cloud VPN Gateway from the AWS console. The file contains the pre-shared keys and BGP IP addresses you need for Step 3. When downloading, select Generic for Vendor and IKEv2 for IKE version. See Download the configuration file. View the pre-shared key: View the Alibaba Cloud BGP IP address: The outside IP addresses, BGP IP addresses, and associated customer gateway IP addresses for Tunnel 1 of each VPN connection:

    If you specified a pre-shared key when creating the site-to-site VPN connection, you don't need to look it up in the configuration file. If you used a system-generated key, find it in the file. The pre-shared keys on the Alibaba Cloud and AWS sides must match.
    Site-to-site VPN connection Tunnel Outside IP address AWS BGP IP address Alibaba Cloud BGP IP address Associated customer gateway IP
    Site-to-Site VPN Connection 1 Tunnel 1 3.XX.XX.52 169.254.116.209 169.254.116.210 8.XX.XX.146
    Site-to-Site VPN Connection 2 Tunnel 1 3.XX.XX.56 169.254.214.97 169.254.214.98 8.XX.XX.74
    IPSec Tunnel #1
    =====================================
    
    #1: Internet Key Exchange Configuration
    
    Configure the IKE SA as follows:
    Please note, these sample configurations are for the minimum requirement...
    Category "VPN" connections in the GovCloud region have a minimum requirement...
    You will need to modify these sample configuration files to take advantage...
    NOTE: If you customized tunnel options when creating or modifying your ...
    
    Higher parameters are only available for VPNs of category "VPN," and not...
    The address of the external interface for your customer gateway must be a...
    Your customer gateway may reside behind a device performing network a...
    To ensure that NAT traversal (NAT-T) can function, you must adjust your f...
    If not behind NAT, and you are not using an Accelerated VPN, we recomm...
      - IKE version              : IKEv2
      - Authentication Method     : Pre-Shared Key
      - Pre-Shared Key            : xxx38iNi
      - Authentication Algorithm  : sha1
      - Encryption Algorithm      : aes-128-cbc
      - Lifetime                  : 28800 seconds
      - Phase 1 Negotiation Mode  : main
      - Diffie-Hellman            : Group 2
    #3: Tunnel Interface Configuration
    
    Your Customer Gateway must be configured with a tunnel interface that is
    associated with the IPSec tunnel. All traffic transmitted to the tunnel
    interface is encrypted and transmitted to the Virtual Private Gateway.
    
    The Customer Gateway and Virtual Private Gateway each have two addresses that relate
    to this IPSec tunnel. Each contains an outside address, upon which encrypted
    traffic is exchanged. Each also contain an inside address associated with
    the tunnel interface.
    
    The Customer Gateway outside IP address was provided when the Customer Gateway
    was created. Changing the IP address requires the creation of a new
    Customer Gateway.
    
    The Customer Gateway inside IP address should be configured on your tunnel
    interface.
    
    Outside IP Addresses:
      - Customer Gateway                : 8.xxx.146
      - Virtual Private Gateway         : 3.xxx.52
    
    Inside IP Addresses
      - Customer Gateway                : 169.254.116.210/30
      - Virtual Private Gateway         : 169.254.116.209/30
  5. Enable route propagation. In the route table of the VPC associated with the virtual private gateway, enable route propagation so that routes from the site-to-site VPN connections are automatically propagated to the AWS VPC route table.

    On the Route Table details page, select the Route Propagation tab and confirm that the Propagation column for the target virtual private gateway shows Yes, indicating that automatic route propagation is enabled.

Step 3: Deploy the VPN Gateway on Alibaba Cloud

With the AWS side ready, configure the Alibaba Cloud side to complete the IPsec-VPN connection.

Create customer gateways

  1. Log on to the VPN Gateway console.

  2. In the left-side navigation pane, choose Interconnections > VPN > Customer Gateways.

  3. In the top navigation bar, select Germany (Frankfurt). The customer gateway and the VPN Gateway must be in the same region.

  4. On the Customer Gateways page, click Create Customer Gateway.

  5. In the Create Customer Gateway panel, configure the following settings and click OK. Create two customer gateways using the outside IP addresses of Tunnel 1 from each AWS site-to-site VPN connection. For parameters not listed here, keep the default values. See Customer gateways.

    Important

    Use only the outside IP address of Tunnel 1 from each AWS site-to-site VPN connection. The outside IP address of Tunnel 2 is not used. After the IPsec-VPN connection is created, Tunnel 2 of each AWS site-to-site VPN connection remains disconnected by default.

    Parameter Description Customer Gateway 1 Customer Gateway 2
    Name Name for the customer gateway. Customer Gateway 1 Customer Gateway 2
    IP Address Outside IP address of the AWS tunnel. 3.XX.XX.52 3.XX.XX.56
    ASN BGP ASN of the AWS virtual private gateway. Required for BGP dynamic routing. 64512 64512

Create an IPsec-VPN connection

  1. In the left-side navigation pane, choose Interconnections > VPN > IPsec Connections.

  2. On the IPsec Connections page, click Bind VPN Gateway.

  3. On the Create IPsec-VPN Connection page, configure the following settings and click OK.

    Parameter Description Example value
    IPsec-VPN Connection Name Name for the IPsec-VPN connection. IPsec-VPN connection
    Region Region where the VPN Gateway is deployed. Germany (Frankfurt)
    Attach a VPN Gateway VPN Gateway instance to associate with the IPsec-VPN connection. VPN Gateway (created in Step 1)
    Routing Mode How traffic is routed through the tunnel. Destination-based Routing routes by destination IP. Traffic Of Interest Pattern routes by source and destination IP pair. Static routing: select Traffic Of Interest Pattern (Recommended). Set Local Network to 10.0.0.0/16 and Remote Network to 192.168.0.0/16. BGP dynamic routing: select Destination-based Routing (recommended).
    Effective Immediately Whether to start IKE negotiation immediately after configuration. Yes: negotiation starts immediately. No: negotiation is triggered by traffic. Yes
    Enable BGP Whether to use BGP dynamic routing. Disabled by default. To use BGP, enable it after the connection is created and add BGP configurations separately. Disabled (static routing). Enable after creation for BGP.
    Tunnel 1Customer Gateway Customer gateway for the active tunnel. Customer Gateway 1
    Tunnel 1Pre-Shared Key Authentication key for the active tunnel. 1–100 characters: digits, letters, and special characters ` ~!@#$%^&*()_-+={}[]|;:',.<>/?``. Must match the key configured on the connected AWS tunnel. Same as the AWS tunnel pre-shared key
    Tunnel 1Encryption Configurations IKE, IPsec, DPD, and NAT traversal settings. Under IKE Configurations, set SA Life Cycle (seconds) to 28800. Under IPsec Configurations, set SA Life Cycle (seconds) to 3600. Keep all other values at their defaults. See Configure IPsec-VPN connections.
    Tunnel 2Customer Gateway Customer gateway for the standby tunnel. Customer Gateway 2
    Tunnel 2Pre-Shared Key Authentication key for the standby tunnel. Must match the key on the connected AWS tunnel. Same as the AWS tunnel pre-shared key
    Tunnel 2Encryption Configurations IKE, IPsec, DPD, and NAT traversal settings. Same as Tunnel 1: IKE SA Life Cycle 28800 s, IPsec SA Life Cycle 3600 s.
  4. In the Created message, click Cancel.

Configure VPN Gateway routes

Static routing

After you create an IPsec-VPN connection, if you selected Policy-based Routing for Routing Mode, the system automatically creates a policy-based route in the VPN Gateway instance with an Unpublished state. Publish the route to the VPC:

  1. In the left-side navigation pane, choose Interconnections > VPN > VPN Gateways.

  2. In the top navigation bar, select the region where the VPN Gateway resides.

  3. On the VPN Gateways page, click the ID of the VPN Gateway.

  4. On the details page, click the Policy-based Route Table tab. Find the route and click Advertise in the Actions column.

  5. In the Advertise Route dialog box, click OK.

BGP dynamic routing

  1. Add BGP configurations to the IPsec-VPN connection.

    1. In the left-side navigation pane, choose Interconnections > VPN > IPsec Connections.

    2. On the IPsec Connections page, click the ID of the IPsec-VPN connection.

    3. In the IPsec Connections section, turn on Enable BGP. In the BGP Configuration dialog box, configure the following settings and click OK.

      Parameter

      Description

      Value

      Local ASN

      Autonomous system number for the IPsec-VPN connection.

      65530

      Tunnel 1Tunnel CIDR Block

      CIDR block for the active tunnel.

      169.254.116.208/30

      Tunnel 1Local BGP IP address

      BGP IP address for the active tunnel. Must be within the tunnel CIDR block.

      169.254.116.210

      Tunnel 2Tunnel CIDR Block

      CIDR block for the standby tunnel.

      169.254.214.96/30

      Tunnel 2Local BGP IP address

      BGP IP address for the standby tunnel. Must be within the tunnel CIDR block.

      169.254.214.98

  2. Enable automatic BGP route propagation for the VPN Gateway.

    1. In the left-side navigation pane, choose Interconnections > VPN > VPN Gateways.

    2. On the VPN Gateways page, find the VPN Gateway instance. In the Actions column, choose More > Enable Automatic BGP Propagation.

    3. In the Enable Automatic BGP Propagation dialog box, click OK.

Step 4: Verify connectivity

Check the VPN connection status

Before running end-to-end tests, confirm that the IPsec-VPN connection is established:

  1. In the VPN Gateway console, go to Interconnections > VPN > IPsec Connections.

  2. Find the IPsec-VPN connection you created. Confirm that the tunnel status shows Connected.

If the status is not Connected, check:

  • That the pre-shared keys on both sides match.

  • That the IKE SA Life Cycle and IPsec SA Life Cycle values match on both sides (28800 s and 3600 s respectively).

  • That security group rules and network ACLs on both the Alibaba Cloud and AWS sides allow traffic between the two VPC CIDR blocks.

Test end-to-end connectivity

Before testing, verify that the network ACLs and security group rules on both platforms allow traffic between the two VPCs.
  1. Log on to an ECS instance in the Alibaba Cloud VPC. See Select a remote connection method for an ECS instance.

  2. Run ping to reach the AWS EC2 instance:

    ping <private IP address of the AWS EC2 instance>

    If the ECS instance receives replies, the two VPCs can communicate.

    [root@iZgw8cpobl xxx Z ~]# ping 192.168.10.113
    PING 192.168.10.113 (192.168.10.113) 56(84) bytes of data.
    64 bytes from 192.168.10.113: icmp_seq=1 ttl=126 time=5.12 ms
    64 bytes from 192.168.10.113: icmp_seq=2 ttl=126 time=5.64 ms
    64 bytes from 192.168.10.113: icmp_seq=3 ttl=126 time=4.97 ms
    64 bytes from 192.168.10.113: icmp_seq=4 ttl=126 time=5.08 ms
    ^Z
    [1]+  Stopped                 ping 192.168.10.113
    [root@iZgw8cp xxx kZ ~]#

Test high-availability failover

A dual-tunnel IPsec-VPN connection provides automatic failover: if the active tunnel fails, traffic switches to the standby tunnel.

  1. Stay logged on to the ECS instance and run a continuous ping:

    ping <private IP address of the AWS EC2 instance> -c 10000
  2. Interrupt the active tunnel by changing its pre-shared key on the Alibaba Cloud side. A key mismatch causes the tunnel to drop.

  3. Watch the ping output. After a brief interruption, traffic automatically resumes through the standby tunnel.

To monitor tunnel traffic, go to the Monitoring tab of the IPsec-VPN connection in the Alibaba Cloud console. See Monitor an IPsec-VPN connection.

What's next