A route table consists of multiple routing policies that control the outbound traffic direction of subnets in the VPC. Each subnet can only be associated with one route table, while each route table can be associated with multiple subnets. You can create multiple route tables for subnets with different traffic routes.
Type
There are two types of route tables: default and custom.
- Default route table: When you create a VPC, the system automatically generates a default route table, which will be associated with subnets created later if no custom route table is selected. You cannot delete the default route table, but you can add, delete, and modify routing policies in it.
- Custom route table: You can create or delete a custom route table in the VPC. This custom route table can be associated with all the subnets to apply the same routing policy.
Note:
You can associate a route table when creating a subnet, or changing the route table after a subnet is created.
Routing Policies
A route table controls traffic routes by using routing policies. A routing policy consists of the destination, next hop type, and next hop:
- Destination: Specifies the destination IP range to which you want to forward the traffic. It should be an IP range. If you want to enter a single IP address, set the mask to
32(for example,172.16.1.1/32). The destination cannot be an IP range of the VPC where the route table resides, because the local route already allows private network interconnection in this VPC. - Next hop type: Indicates the egress of data packets for the VPC. The next hop type of VPC supports NAT Gateway, Peering Connection, VPN Gateway, Direct Connect Gateway, CVM, and others.
- Next hop: Specifies the next hop instance (identified by the next hop ID) to which the traffic is forwarded, such as a NAT gateway in the VPC.
Routing Policy Priority
When there are multiple routing policies in a route table, the following routing priority applies, from high to low:
- Traffic within the VPC: Traffic within the VPC is matched first.
- Exact match route (the longest prefix match): When there are multiple routes in the route table that can match the destination IP, the route with the longest (exact) mask is matched to determine the next hop.
- Public IP address: If no routing policy is matched, a CVM instance can access the internet through its public IP address.
Priority of NAT Gateway and EIP
When a subnet is associated with a NAT gateway, and the CVM instance in the subnet has a public IP address (or EIP), the CVM instance accesses the internet through the NAT gateway by default (Because the priority of the exact match route is higher than that of the public IP address.). However, you can set a routing policy to allow the CVM instance to access the internet through its public IP address. For more information, see Adjusting the Priorities of NAT Gateways and EIPs.