If you need to centrally manage Internet access for instances in a virtual private cloud (VPC), you can use IPv4 gateways and subnet routing. This topic describes how to create an IPv4 gateway and configure routes to complete the preceding task.
Prerequisites
A VPC and a vSwitch are created. For more information, see Create and manage a VPC and Create and manage a vSwitch.
Limits
After you enable an IPv4 gateway for a VPC, you must configure the IPv4 gateway. Resources in the VPC cannot access the Internet until the configuration of the IPv4 gateway is complete.
Instances in a VPC can access the Internet only when an IPv4 gateway in the VPC is activated and routes that point to the IPv4 gateway are added to a route table of the VPC.
A VPC that uses an IPv4 gateway cannot contain elastic IP addresses (EIPs) in cut-through mode.
After you enable the IPv4 gateway feature for a VPC, you cannot disable the feature. For more information, see IPv4 gateway overview.
Create an IPv4 gateway and associate it with a VPC
For more information about the regions that support IPv4 gateways, see Feature release and supported regions.
The IPv4 gateway can be created if it is compatible with the Internet NAT gateway in the VPC. Otherwise, the IPv4 gateway fails to be created. You can change the mode of the Internet NAT gateway to make it compatible with IPv4 gateways before you create an IPv4 gateway. For more information about how to change the mode of an Internet NAT gateway, see Change the mode of an Internet NAT gateway.
Log on to the VPC console.
In the top navigation bar, select the region where you want to create an IPv4 gateway.
In the left-side navigation pane, click IPv4 Gateway.
On the IPv4 Gateway page, click Create IPv4 Gateway.
In the Create IPv4 Gateway dialog box, set the following parameters and click Create.
Parameter
Description
Region
Displays the region where you want to create the IPv4 gateway.
VPC
Select the VPC with which you want to associate the IPv4 gateway.
NoteThe IPv4 gateway feature is an advanced VPC feature. If the VPC does not support the IPv4 gateway feature, contact Alibaba Cloud engineers.
Name
Enter a name for the IPv4 gateway.
Description
Enter a description for the IPv4 gateway.
On the IPv4 Gateway page, view the created IPv4 gateway.
After you create an IPv4 gateway, it is in the Available state.
Activate the IPv4 gateway
You need to activate the IPv4 gateway before it can forward traffic. You can use the IPv4 gateway to centrally manage Internet access for instances in the VPC only after the IPv4 gateway is activated.
Log on to the VPC console.
In the top navigation bar, select a region.
In the left-side navigation pane, click IPv4 Gateway.
On the IPv4 Gateway page, find the IPv4 gateway that you want to activate and click Activate in the Actions column.
Add routes that point to the IPv4 gateway to a route table of the VPC
You need to configure routes that point to the IPv4 gateway in the VPC route table so that instances in the VPC can access the Internet.
Log on to the VPC console.
In the left-side navigation pane, click Route Tables.
On the Route Table page, find the VPC route table and click its ID.
The route table is the one that is associated with the instances that require access to the Internet through the IPv4 gateway.
On the details page of the route table, choose and click Add Route Entry.
In the Add Route Entry panel, set the following parameters and click OK.
Parameter
Description
Name
Enter a name for the custom route.
Destination CIDR Block
Enter 0.0.0.0/0.
Next Hop Type
Select IPv4 Gateway.
IPv4 Gateway
Select an IPv4 gateway from the drop-down list.
Optional operations
Create a gateway route table and modify routes
A route table associated with an IPv4 gateway is referred to as a gateway route table. You can modify routes to control traffic from the IPv4 gateway to the VPC. You can create only one gateway route table in a VPC.
Log on to the VPC console.
In the top navigation bar, select the region where you want to create a route table.
In the left-side navigation pane, click Route Tables.
On the Route Tables page, click Create Route Table.
On the Create Route Table page, set the following parameters and click OK.
Parameter
Description
Resource Group
Select the resource group to which the route table belongs.
VPC
Select the VPC to which the route table belongs.
In this example, the VPC to which the IPv4 gateway belongs is selected.
Associated Resource Type
Select the type of the resource with which you want to associate the route table.
vSwitch: The route table is associated with a vSwitch. In this case, the route table serves as a custom route table and is used to manage traffic within the vSwitch.
Border Gateway: The route table is associated with an IPv4 gateway. In this case, the route table serves as a gateway route table and is used to control traffic from the IPv4 gateway to the VPC.
In this example, Border Gateway is selected.
Name
Enter a name for the route table.
Description
Enter a description for the route table.
After the gateway route table is created, view it on the Route Tables page.
On the Route Tables page, find the gateway route table and click its ID.
On the tab, find the system route that you want to modify and click Edit in the Actions column.
In the Edit Route Entry dialog box, set the following parameters and click OK.
Parameter
Description
Destination CIDR Block
Displays the destination CIDR block of traffic. You cannot modify Destination CIDR Block.
Next Hop Type
Select the next hop type. Valid values:
Local: Traffic destined for the destination CIDR block is routed to the VPC.
ECS Instance: Traffic destined for the destination CIDR block is routed to the specified ECS instance.
ENI: Traffic destined for the destination CIDR block is routed to the specified elastic network interface (ENI).
ImportantIf the next hop type is set to ENI or ECS Instance, you must first change the next hop type to Local, change the next hop type to ENI or ECS Instance, and then change the next hop. You cannot directly change the next hop when the next hop type is set to ENI or ECS Instance.
Resource Group
Select the resource group to which the next hop belongs.
If Next Hop Type is set to ECS Instance or ENI, this parameter is required.
ECS Instance or ENI
Select an instance as the next hop.
If Next Hop Type is set to ECS Instance or ENI, you must select an instance as the next hop.
Name
Enter a new name for the route.
Description
Enter a new description for the route table.
Associate the gateway route table with the IPv4 gateway
After the gateway route table is created, associate it with the IPv4 gateway. Then, you can configure routes to manage traffic from the IPv4 gateway to the VPC.
Log on to the VPC console.
In the top navigation bar, select the region where the IPv4 gateway is deployed.
In the left-side navigation pane, click IPv4 Gateway.
On the IPv4 Gateway page, find the IPv4 gateway that you want to manage and click its ID.
On the details page of the IPv4 gateway, click Bind in the Gateway Route Entries tab.
In the Associate Route Table dialog box, select the gateway route table that you want to associate and click OK.
In the Associated with Route Table section of the Gateway Route Entries tab, you can view the gateway route table associated with the IPv4 gateway.
Disassociate the gateway route table from the associated IPv4 gateway
Log on to the VPC console.
In the top navigation bar, select the region where the IPv4 gateway is deployed.
In the left-side navigation pane, click IPv4 Gateway.
On the IPv4 Gateway page, find the IPv4 gateway that you want to manage and click its ID.
On the IPv4 gateway details page, click Replace Associated Route Table in the Gateway Route Entries tab.
In the Associate Route Table dialog box, select Disassociate Route Table and click OK.
Delete an IPv4 gateway
Before you delete an IPv4 gateway from a VPC, you must disassociate the gateway route table associated with the IPv4 gateway and delete the routes that point to the IPv4 gateway from the route tables of the VPC. For more information about how to delete custom routes, see Create and manage route tables.
After you delete the IPv4 gateway, cloud resources in the VPC cannot communicate with the Internet. Proceed with caution.
Log on to the VPC console.
In the top navigation bar, select the region where the IPv4 gateway is deployed.
In the left-side navigation pane, click IPv4 Gateway.
On the IPv4 Gateway page, find the IPv4 gateway that you want to delete and click Delete in the Actions column.
In the Delete message, click OK.
Related operations
Operation | Procedure |
Modify an IPv4 gateway |
|
Replace the gateway route table that is associated with an IPv4 gateway |
|
Modify a gateway route table |
|
References
CreateIpv4Gateway: creates an IPv4 gateway.
EnableVpcIpv4Gateway: activates an IPv4 gateway.
CreateRouteTable: creates a gateway route table.
AssociateRouteTableWithGateway: associates an IPv4 gateway with a gateway route table.
DissociateRouteTableFromGateway: disassociates an IPv4 gateway from a gateway route table.
DeleteIpv4Gateway: deletes an IPv4 gateway.
UpdateIpv4GatewayAttribute: modifies the information about an IPv4 gateway.
UpdateGatewayRouteTableEntryAttribute: modifies the information about a gateway route table.