You can use the SNAT and DNAT features of a VPC NAT gateway with Express Connect to enable communication between an on-premises data center (IDC) and a VPC using static private IP addresses.
Example scenario
This topic uses the scenario shown in the following figure. An enterprise has deployed a VPC and vSwitches in the China (Shanghai) region. Multiple ECS instances are created in the vSwitches. The enterprise's on-premises data center is connected to Alibaba Cloud through Express Connect and a virtual border router (VBR). The VPC and the data center can communicate over Cloud Enterprise Network (CEN).
This scenario requires communication between the VPC and the on-premises data center to use static private IP addresses. You can use the SNAT and DNAT features of a VPC NAT gateway to meet this requirement.
Procedure
Make sure that you have created the required resources, including a VPC, vSwitches, ECS instances, an Express Connect physical connection, a VBR, a CEN instance, and a Transit Router instance.
Before you create a VPC connection on a Transit Router, make sure that the VPC has at least one vSwitch in a zone supported by the Transit Router. The vSwitch must have at least one available IP address.
Step 1: Create VPC and VBR connections
Create a VBR connection and a VPC connection on the Transit Router to establish private communication between your on-premises data center and the VPC.
-
Log on to the Cloud Enterprise Network console.
-
On the CEN Instance page, click the ID of the target CEN instance.
-
On the Basic Settings > Transit Router tab, find the target Transit Router instance and click Create Connection in the Actions column.
If this is the first time you perform this operation, the system automatically creates a service-linked role named AliyunServiceRoleForCEN. This role allows the Transit Router to create an elastic network interface (ENI) on a vSwitch in the VPC.
-
Network Type: Select VPC.
-
Region: Select the region where the VPC is deployed.
-
Account: Select the account type to which the VPC belongs.
-
Billing Method: The default value is Pay-As-You-Go. For more information, see Billing.
-
Networks: Select the VPC that you want to connect.
-
vSwitch: Select at least two vSwitches in zones supported by the Transit Router.
-
Advanced Settings: Keep the default settings and select the three advanced options.
-
-
On the Connection with Peer Network Instance page, click Create More Connections. Configure the following parameters to create a VBR connection, and then click OK.
-
Network Type: Select Virtual Border Router (VBR).
-
Region: Select the region where the VBR is deployed.
-
Account: Select the account type to which the VBR belongs.
-
Networks: Select the VBR that you want to connect.
-
Advanced Settings: Keep the default settings and select the three advanced options.
-
-
After the connections are created, you can view the VPC and VBR connections on the Intra-Region Connections tab.
Step 2: Configure VBR route
Add a route to the VBR that points to the on-premises data center.
-
Go to the Virtual Border Router (VBR) page in the Express Connect console. In the top navigation bar, select the target region.
-
On the Routes tab, click Add Route Entry.
-
Next Hop Type: Select the type of the next hop. In this example, select Physical Connection.
-
Destination CIDR Block: Enter the IP address of the server in the on-premises data center: 172.16.10.137.
-
Next Hop: Select the physical connection interface to which the traffic is routed.
-
Step 3: Create a VPC NAT gateway
-
Go to the Create VPC NAT Gateway page.
-
Region: Select the region where you want to create the VPC NAT gateway. In this example, select China (Shanghai).
-
Network and Zone: Select the VPC and vSwitch for the VPC NAT gateway. You cannot change these settings after the instance is created.
-
-
On the Confirm page, confirm the parameters, agree to the terms of service, and then click Activate Now.
Step 4: Add a system route for VPC1
Make sure that the vSwitches of the ECS instances in VPC1 are associated with the system route table. If a vSwitch is associated with a custom route table, add the route entry to that custom route table.
Log on to the VPC console.
-
Go to the VPCs page. In the top navigation bar, select the target region.
-
Click the ID of the target VPC to open its details page. On the Resource Management tab, click the link under Route Tables.
-
Click the ID of the route table for which the Route Table Type is System. On the Custom Route tab, click Add Route Entry.
-
Destination CIDR Block: Enter the destination CIDR block to which traffic is forwarded. Enter the IP address of the server in the on-premises data center: 172.16.10.137.
-
Next Hop Type: Select NAT Gateway.
-
NAT Gateway: Select the VPC NAT gateway that you created.
-
Step 5: Create and configure a custom route table
-
Go to the Route Tables page of the VPC console. In the top navigation bar, select the target region.
-
Click Create Route Table.
-
VPC: Select the VPC to which the route table belongs. In this example, select VPC1.
-
Associated Resource Type: Select vSwitch.
-
-
Find the route table, click Bind in the Associated Resource column, and then click Associate vSwitch. Select the vSwitch to which the VPC NAT gateway belongs.
-
On the Route Entry List > Custom Route tab, click Add Route Entry.
-
Destination CIDR Block: Enter the destination CIDR block to which traffic is forwarded. Enter the IP address of the server in the on-premises data center: 172.16.10.137.
-
Next Hop Type: Select Transit Router.
-
Transit Router: Select the VPC connection that is attached to the Transit Router.
-
Step 6: Create SNAT and DNAT entries
-
Create an SNAT entry to allow ECS instances in the VPC to access the on-premises data center.
-
Create a DNAT entry to allow the on-premises data center to access ECS instances in the VPC.
-
Go to the VPC NAT Gateway page in the NAT Gateway console. In the top navigation bar, select the target region.
-
Find the target VPC NAT gateway, click SNAT in the Actions column, and then click Create SNAT Entry.
-
SNAT Entry: Select Specify vSwitch. From the Select vSwitch list, select the vSwitch where the ECS instance is located.
-
Select NAT IP Address: Select the NAT IP address used to access external private networks. Select the default NAT IP address.
-
-
On the DNAT tab, click Create DNAT Entry.
-
Select NAT IP Address: Select the NAT IP address used to receive requests from external private networks. In this example, select the default NAT IP address.
-
Select Private IP Address: Select the destination private IP address. You can Select by ECS or ENI to choose the private IP address of ECS1, or you can enter it manually.
-
Port Settings: Select the DNAT mapping method. In this example, select Specific Port. Set Frontend Port to 22, Backend Port to 22, and Protocol to TCP.
-
Step 7: Configure the on-premises IDC route
On your on-premises gateway device, configure a route that points to the VPC.
The following route is for reference only. The actual command might vary based on the vendor and model of your device.
ip route 192.168.0.0 255.255.0.0 10.0.0.2
Step 8: Test connectivity
-
Log on to ECS1, which is in VSW1.
-
Run the
ping <IP address of the server in the on-premises data center>command to test whether ECS1 can access the server. If you receive reply packets, the connection is established. -
Log on to the server in your on-premises data center and run the
ssh root@<NAT_IP>command, whereis the default NAT IP address of the VPC NAT gateway. Then, enter the logon password for ECS1. A successful login confirms that the server in the on-premises data center can connect to ECS1.