Configure static, policy-based, or BGP routes on a VPN gateway to connect your VPC to a data center through IPsec-VPN connections.
Choose a routing method
Static routes vs. BGP routes
|
Category |
Static route |
BGP route |
|
Use cases |
Networks with a small number of routes that change infrequently. |
Networks with a large number of routes that change frequently. |
|
Maintenance |
Medium. Route changes must be configured manually. |
Low. Routes are automatically advertised and learned. |
|
Prerequisites |
None. |
Both the VPN gateway and the local gateway device must support BGP. |
Static routes: Destination-based vs. policy-based
Choose between destination-based and policy-based routes.
|
Category |
Destination-based route |
Policy-based route |
|
Matching criteria |
Destination IP only |
Source IP + Destination IP |
|
Use cases |
General use. Recommended for most users. |
Traffic routing differentiated by source CIDR block. |
|
Priority |
Lower than policy-based routes. |
Higher than destination-based routes. |
Route priority
The VPN gateway matches traffic against routes in this order:
-
The gateway first checks the Policy-based Route Table, matching routes by policy priority, not by the longest prefix match rule.
-
The gateway then checks the Destination-based Route Table, matching routes by the longest prefix match rule.
-
Finally, the gateway checks the BGP Route Table.
Static route configuration
End-to-end overview
Connecting a VPC to a data center through a VPN gateway involves three route tables:
|
Traffic direction |
VPC route table |
VPN gateway route table |
Local gateway device route table |
|
Outbound (VPC to data center) |
Choose one of the following methods:
|
Manually add one route:
|
Ensure the local gateway device has a route to the data center's internal network. If not, add one manually. |
|
Inbound (data center to VPC) |
No configuration is required. |
No configuration is required. |
Manually add two routes: For both routes, set the destination CIDR block to the VPC's CIDR block and the next hop to the active and standby tunnels of the IPsec-VPN connection, respectively. Assign a higher weight to the active tunnel. |
Destination-based route configuration
A destination-based route forwards traffic based on the destination IP address.
Matching rules:
-
Longest prefix match: Traffic matches the route with the longest subnet mask. For example, if both
10.0.0.0/8and10.10.0.0/16routes exist, traffic destined for10.10.10.1will match the10.10.0.0/16route. -
Active/standby routes (for legacy single-tunnel VPN gateways only): Only active routes match; standby routes are skipped. Active/standby route configuration.
Console
Add a destination-based route
Ensure you have created an IPsec-VPN connection associated with a VPN gateway.
-
Go to the VPN Gateway page in the console. Click the ID of the target VPN gateway instance.
-
Navigate to the Destination-based Route Table tab and click Add Route Entry.
-
Destination CIDR Block: Enter the CIDR block of your data center.
-
Next Hop: Select the target IPsec-VPN connection.
-
Advertise to VPC: Select Yes to automatically advertise the route to the VPC system route table. If you select No, you must manually add the route to the VPC route table.
-
Weight: Only legacy single-tunnel VPN gateways support weights. Active/standby route configuration.
-
Delete a destination-based route
Find the target route entry and click Delete in the Actions column.
API
|
API operation |
Description |
|
Creates a destination-based route. |
|
|
Advertises or withdraws a VPN route. |
|
|
Deletes a destination-based route. |
|
|
Modifies the weight (for legacy single-tunnel VPN gateways only). |
|
|
Queries destination-based and BGP routes. |
Policy-based route configuration
A policy-based route matches traffic by both source IP address and destination IP address, and takes priority over destination-based and BGP routes.
Matching order:
-
Policy priority: Routes with the lowest priority value match first.
-
Routes with the same priority: Matched sequentially by creation time. The first match is used.
-
Matching order for same-priority routes is not guaranteed. Assign a unique priority to each policy-based route for deterministic routing.
-
For legacy single-tunnel VPN gateways, active/standby policy-based routes must share the same priority. Only active routes match. Active/standby route configuration.
Console
Add a policy-based route
Ensure you have created an IPsec-VPN connection associated with a VPN gateway.
-
Go to the VPN Gateway page in the console. Click the ID of the target VPN gateway instance.
-
Navigate to the Policy-based Route Table tab and click Add Route Entry.
-
Destination CIDR Block: Enter the CIDR block of your data center.
-
Source CIDR Block: Enter the CIDR block of the associated VPC.
-
Next Hop: Select the target IPsec-VPN connection.
-
Advertise to VPC: Select Yes to automatically advertise the route to the VPC system route table. If you select No, you must manually add the route to the VPC route table.
-
Policy Priority: Range: 1–100. Lower values = higher priority. Default: 10.
-
Weight: Only legacy single-tunnel VPN gateways support weight configuration. Active/standby route configuration.
-
Edit a policy-based route
Find the target route entry and click Edit in the Actions column to modify the Policy Priority or Weight. Only legacy single-tunnel VPN gateways support weight modification.
Delete a policy-based route
Find the target route entry and click Delete in the Actions column.
API
|
API operation |
Description |
|
Creates a policy-based route. |
|
|
Deletes a policy-based route. |
|
|
Modifies the weight. |
|
|
Modifies the policy priority. |
|
|
Modifies the weight and policy priority. |
|
|
Queries policy-based routes. |
Advertise to a VPC route table
Advertise manually added routes to the VPC system route table without configuring them in the VPC console.
-
Routes are advertised only to the VPC system route table, not to custom route tables. To add a route to a custom route table, use Add and delete route entries.
-
If routes with the same destination CIDR block exist in both the policy-based and destination-based route tables, withdrawing the route from one table also withdraws it from the other.
Console
-
When adding a destination-based or policy-based route, you can select to Advertise.
-
For existing route entries, you can click Advertise or Withdraw in the Actions column.
API
Call PublishVpnRouteEntry to advertise or withdraw a route.
Limitations
These limitations apply to both destination-based and policy-based routes:
-
You cannot add a route with the destination CIDR block
0.0.0.0/0. -
Do not add a route to
100.64.0.0/10(including subnets and supernets). This causes IPsec connection or negotiation failures. -
If the system reports a route conflict, see Handle duplicate route errors.
BGP route configuration
BGP (Border Gateway Protocol) lets a VPN gateway and data center peer automatically, learning and distributing routes without manual maintenance.
End-to-end overview
|
Traffic direction |
VPC route table |
VPN Gateway route table |
Local gateway device route table |
|
Outbound (VPC to data center) |
No configuration required. After you enable Automatic Route Propagation for the VPN gateway, the VPC route table automatically learns routes to the data center from the VPN gateway. |
|
You must enable BGP on the local gateway device. When enabled, the device automatically advertises the local network's CIDR blocks to the cloud and learns the VPC's CIDR blocks. |
|
Inbound (data center to VPC) |
No configuration is required. |
BGP route advertisement principles
-
Inbound to cloud: Routes advertised by the data center via BGP → propagated to the VPN gateway → automatically propagated to the VPC system route table (requires route propagation enabled).
-
Outbound from cloud: System route entries in the VPC system route table → automatically learned by the VPN gateway (requires route propagation enabled) → propagated to the data center via BGP.
Procedure
Before you begin, ensure:
-
The VPN gateway supports BGP. Check whether a VPN gateway supports BGP.
-
The gateway device in your data center supports BGP.
Console
-
Specify the data center's ASN in the Customer Gateway
Specify your data center's Autonomous System Number (ASN) when creating a Customer Gateway. If the existing one lacks an ASN, create a new one. Customer Gateway.
-
Enable BGP in the IPsec-VPN connection
-
When creating or editing an IPsec-VPN connection, configure the Customer Gateway, Enable BGP, Local ASN, Tunnel CIDR Block, and Local BGP IP address. For parameter descriptions and procedures, see Enable or disable BGP.
-
The Local ASN for both tunnels must be the same. The peer BGP ASN must also be the same for both tunnels.
-
Set the Routing Mode of the IPsec-VPN connection to Destination Routing Mode.
-
-
Enable route propagation
Enable this feature in the Enable Automatic Route Advertisement column for the target VPN gateway instance. When enabled:
-
The VPN gateway automatically learns system routes from the VPC system route table.
-
The VPN gateway automatically propagates BGP routes from the data center to the VPC system route table.
BGP routes are propagated only to the VPC system route table, not to custom route tables.
-
-
Verify the BGP routes
-
VPN gateway BGP route table: On the VPN gateway instance details page, go to the BGP Route Table tab. The route source is marked as "CLOUD" (cloud-native routes) or "VPN_BGP" (routes learned via BGP).
-
VPC system route table: Check the VPC's system route table for entries of type "Dynamic Route".
-
API
-
Specify the data center's ASN in the Customer Gateway
Call the CreateCustomerGateway operation.
-
Enable BGP in the IPsec-VPN connection
-
Call the CreateVpnConnection operation to create an IPsec-VPN connection.
-
Call the ModifyVpnConnectionAttribute operation to modify the IPsec-VPN connection configuration, and call the ModifyTunnelAttribute operation to modify the tunnel configuration.
-
-
Enable route propagation
Call the ModifyVpnGatewayAttribute operation to enable it.
-
Verify the BGP routes
Call the DescribeVpnRouteEntries operation to query BGP route entries.
Limitations
-
Each VPN gateway BGP route table supports up to 50 routes (expandable to 200; contact your account manager).
-
The VPN gateway does not accept BGP routes where the destination CIDR block is
0.0.0.0/0. -
When BGP is enabled for multiple IPsec-VPN connections on the same VPN gateway, the Local ASN must be the same for all connections.
-
Do not exchange routes between different IPsec-VPN connections.
-
When a VPC is associated with multiple VPN gateways, the gateways do not support BGP peering with each other. Do not exchange routes between different VPN gateways.
-
If a VPC is associated with multiple VPN gateways that all use BGP and connect to the same Customer Gateway, the Local ASN for the IPsec-VPN connections on each VPN gateway must be identical to prevent routing loops.
-
If multiple dual-tunnel IPsec-VPN connections use BGP simultaneously, the destination CIDR blocks of the routes learned by each connection must not overlap.
-
When using an Express Connect circuit and a VPN gateway for active/standby access to a VPC, the local ASN configured on the Border Router (VBR) and the VPN gateway must be the same.
-
If the VPN gateway's VPC belongs to a Cloud Enterprise Network (CEN), enable route overlapping. This is enabled by default for CEN instances created after March 2019.
-
If multiple VPCs in the same CEN connect to the same data center via BGP, dynamic routes may propagate through CEN to other VPCs, causing route flapping. Use static routes instead.
-
VPN gateway in single-tunnel mode: Do not propagate routes for
100.64.0.0/10(including its subnets and supernets). You can avoid this issue by upgrading the IPsec-VPN connection to dual-tunnel mode.
Appendix
Route configuration recommendations
-
Use the same routing method for all IPsec-VPN connections on a VPN gateway. Do not mix destination-based, policy-based, and BGP routes.
-
When configuring BGP routes, set the Routing Mode of the IPsec-VPN connection to Destination Routing Mode.
Check whether a VPN gateway supports BGP
-
Newly created VPN gateways that support dual-tunnel IPsec-VPN connections support BGP by default.
-
For existing VPN gateways: Call the DescribeVpnGateway operation and verify that the
Tagfield contains theVpnEnableBgptag with a value oftrue. -
Upgrade options for unsupported gateways:
- Dual-tunnel mode VPN gateway: Upgrade the VPN gateway (classic type only)
- Single-tunnel mode VPN gateway: Upgrade to dual-tunnel mode
Active/standby route configuration
This section applies only to existing VPN gateways that use single-tunnel mode.
-
To configure active/standby for a legacy single-tunnel VPN gateway, upgrade the IPsec-VPN connection to dual-tunnel mode. Dual-tunnel connections provide active/standby by default without weight configuration.
-
If you still need to configure an active/standby link in single-tunnel mode, follow these steps:
-
The primary route has a weight of
100and the standby route has a weight of0. The destination CIDR blocks must be the same, but the next hops must be different. For policy-based routes, the source CIDR blocks must also be the same. -
Configure a health check for the IPsec-VPN connection to enable automatic failover. You can find this option in the tunnel configuration settings of the IPsec-VPN connection.
-
To modify a route's weight, delete the standby route first, modify the active route's weight, then re-create the standby route. The same process applies when modifying the standby route's weight.
For VPN Gateway instances that have not been upgraded since October 12, 2023, if you need to configure active/standby policy-based routes, ensure that an active/standby link is specified for each CIDR block. If a CIDR block has only one link configured, failover for other CIDR blocks may fail. You can avoid this issue by upgrading the VPN gateway or upgrading the IPsec-VPN connection to dual-tunnel mode. This issue does not affect VPN Gateway instances that were created or upgraded after October 12, 2023.
-
-
After configuration, the route takes effect based on the following rules:
IPsec-VPN connection for active route
IPsec-VPN connection for standby route
Effective route
Up (negotiation succeeded and health check is normal)
Any state
Active route
Down
Up
Standby route
Down
Down
Active route (default)