IPv4 gateway

Updated at:

By default, VPC resources with a public IP address can communicate directly with the Internet over IPv4. In enterprise environments, unmanaged Internet access methods — such as business teams assigning public IP addresses to ECS instances without approval — introduce security risks. An IPv4 gateway lets you route all Internet-bound traffic through a single control point via route tables, reducing the security risks of decentralized access.

Why use an IPv4 gateway

Comparison

Direct Internet access (VPC default)

Centralized control with IPv4 gateway

Example

Without an IPv4 gateway, ECS instances access the Internet directly through a static public IP address, an EIP, or an Internet NAT gateway.

Centralized management of all Internet access traffic.

Use cases

A small number of ECS instances need independent, direct Internet access.

Ideal when Internet access requirements change frequently.

Large-scale, multi-tiered network architectures.

Enterprise environments with strict network security and compliance requirements.

Complexity

Simple and fast. No route configuration required.

Requires network planning and route rule configuration.

Flexibility

Each instance is managed independently with no impact on others.

Network policy changes affect all instances in the VPC.

Security

Security relies primarily on the security group rules configured for each instance.

The IPv4 gateway enforces consistent, VPC-wide network policies through centralized control.

Difference between IPv4 gateway and Internet NAT gateway

An IPv4 gateway and an Internet NAT gateway can be used together. See Internet access for details on how these networking components relate to each other.

Component

IPv4 gateway

Internet NAT gateway

Purpose

A VPC boundary component that controls public IPv4 traffic

A Network Address Translation (NAT) device inside the VPC

Scenarios

Centralized control of Internet access traffic

Unified egress for Internet-bound traffic

Provides Internet access

No. Controls traffic only.

Provides Internet access by associating EIPs

(EIPs provide the connectivity; the NAT gateway itself does not provide Internet access.)

After you create an IPv4 gateway, vSwitches fall into two categories:

  • Public vSwitch: The associated route table contains a route entry with Destination CIDR Block set to 0.0.0.0/0 and Next Hop set to the IPv4 gateway. Resources in this vSwitch can access the Internet after associating a public IP address.

  • Private vSwitch: The associated route table does not contain a route pointing to the IPv4 gateway. Resources in this vSwitch cannot directly access the Internet even if they have a public IP address.

When using an Internet NAT gateway together with an IPv4 gateway, deploy the Internet NAT gateway in a public vSwitch. ECS instances in a private vSwitch must have a route pointing to the Internet NAT gateway so their Internet-bound traffic flows through the NAT gateway, which uses its associated public IP address to reach the Internet. Note the following:

  • Make sure the EipBindMode of the Internet NAT gateway is set to NAT mode for compatibility with the IPv4 gateway.

    • Internet NAT gateways created in the console default to NAT mode. When calling CreateNatGateway, set EipBindMode to NAT. After creation, call ModifyNatGatewayAttribute to change the EipBindMode.

    • If an Internet NAT gateway with EipBindMode set to MULTI_BINDED mode already exists, it is incompatible with the IPv4 gateway, and you cannot create an IPv4 gateway.

    • If an IPv4 gateway already exists and you call CreateNatGateway to create an Internet NAT gateway with EipBindMode set to MULTI_BINDED mode, you cannot associate EIPs with that NAT gateway.

  • To prevent resources in private vSwitches from losing Internet access after the IPv4 gateway is activated, complete route configuration before activation.

image

How it works

Control Internet access with an IPv4 gateway

After you create and activate an IPv4 gateway for a VPC, the gateway centrally controls all Internet access traffic. Only vSwitches whose associated route table contains a route pointing to the IPv4 gateway can directly access the Internet. On the VPC details page, check IPv4 Internet Access Mode to verify whether the IPv4 gateway is actively controlling Internet traffic.

Before activation, Internet traffic in the VPC is unaffected. However, a brief network interruption may occur during activation as traffic paths switch over.
image

Delete an IPv4 gateway

Before deletion, disassociate the gateway route table. In the Actions column of the target IPv4 gateway, click Delete, or call DeleteIpv4Gateway. The deletion mode you choose determines how the VPC handles Internet access afterward.

  • Public mode: The system automatically removes all route entries pointing to the IPv4 gateway. The VPC reverts to its initial state, where instances with a public IP address can access the Internet directly.

  • Private mode: You must first manually delete all route entries pointing to the IPv4 gateway from the route tables. After deletion, all VPC resources lose Internet access. To restore direct Internet access, create a new IPv4 gateway and delete it in public mode.

    Important

    After deletion in private mode, all VPC resources lose Internet access regardless of whether they have a public IP address. Proceed with caution.

image

Centrally control Internet access

In enterprise environments, unmanaged Internet access methods — such as business teams assigning public IP addresses to ECS instances without approval — make it difficult for operations teams to enforce consistent policies. Use an IPv4 gateway to centralize Internet access control, reducing the security risks of decentralized access.

Console

  1. Go to the VPC console - IPv4 Gateway page. Select the region where your VPC is deployed, then click Create IPv4 Gateway.

  2. Create IPv4 gateway: Select the VPC for which you want to centralize Internet access control.

  3. Activate IPv4 gateway: Select the route tables associated with public vSwitches. The system automatically adds a 0.0.0.0/0 route pointing to the IPv4 gateway, ensuring resources in public vSwitches can access the Internet after associating a public IP address. If the route table already contains a 0.0.0.0/0 route, click Activate Later, update the next hop of that route to the IPv4 gateway, then activate. After activation, VPC Internet access is controlled by the IPv4 gateway.

    • If an ECS instance uses an Internet NAT gateway for Internet access, deploy the ECS instance and the NAT gateway in different vSwitches. Add a 0.0.0.0/0 route pointing to the IPv4 gateway in the route table associated with the NAT gateway vSwitch. Add a route pointing to the NAT gateway in the public vSwitch in the route table associated with the ECS instance vSwitch.

    • If an ECS instance uses a static public IP address or a directly associated EIP, add a 0.0.0.0/0 route pointing to the IPv4 gateway.

API

  • Call CreateIpv4Gateway to create an IPv4 gateway.

  • Call EnableVpcIpv4Gateway to activate the IPv4 gateway. Set RouteTableList to the route table associated with the public vSwitch. If omitted, call CreateRouteEntry to manually add a 0.0.0.0/0 route pointing to the IPv4 gateway.

Terraform

Unlike the console, activating an IPv4 gateway via Terraform does not automatically add a 0.0.0.0/0 route pointing to the IPv4 gateway. You must configure the route manually.

Resource: alicloud_vpc, alicloud_vswitch, alicloud_vpc_ipv4_gateway, alicloud_route_table, alicloud_route_table_attachment, alicloud_vpc_route_entry, alicloud_instance, alicloud_security_group, alicloud_security_group_rule, alicloud_eip_address, alicloud_eip_association, alicloud_nat_gateway, alicloud_snat_entry
Data Sources: alicloud_zones
# Specify the region for the IPv4 gateway
provider "alicloud" {
  region = "cn-hangzhou"
}

# Automatically obtain zones that support vSwitch creation
data "alicloud_zones" "available_zones" {
  available_resource_creation = "VSwitch" # Query zones available for VPC resources
}

# Create a VPC 
resource "alicloud_vpc" "example_vpc" {
  vpc_name   = "example_vpc_name"
  cidr_block = "10.0.0.0/16" # Specify the CIDR block 
}

# Define vSwitch configurations
locals {
  vswitches = {
    vsw1 = {
      name       = "example_vsw1_name"
      cidr_block = "10.0.0.0/24"
      zone_index = 0
    }
    vsw2 = {
      name       = "example_vsw2_name"
      cidr_block = "10.0.1.0/24"
      zone_index = 1
    }
    vsw3 = {
      name       = "example_vsw3_name"
      cidr_block = "10.0.2.0/24"
      zone_index = 0
    }
    vsw4 = {
      name       = "example_vsw4_name"
      cidr_block = "10.0.3.0/24"
      zone_index = 0
    }
  }

  # Define route table configurations
  route_tables = {
    rt1 = {
      name        = "example_rt1_name"
      vswitch_key = "vsw1"
    }
    rt2 = {
      name        = "example_rt2_name"
      vswitch_key = "vsw2"
    }
    rt3 = {
      name        = "example_rt3_name"
      vswitch_key = "vsw3"
    }
    rt4 = {
      name        = "example_rt4_name"
      vswitch_key = "vsw4"
    }
  }

  # Define instance configurations
  instances = {
    instance1 = {
      name        = "example_instance1_name"
      vswitch_key = "vsw1"
    }
    instance2 = {
      name        = "example_instance2_name"
      vswitch_key = "vsw3"
    }
    instance3 = {
      name        = "example_instance3_name"
      vswitch_key = "vsw4"
    }
  }

  # Define EIP configurations
  eips = {
    eip1 = {
      name = "example_eip1_name"
    }
    eip2 = {
      name = "example_eip2_name"
    }
  }

  # Define SNAT entry configurations
  snat_entries = {
    snat1 = {
      instance_key = "instance2"
    }
    snat2 = {
      instance_key = "instance3"
    }
  }
}

# Create multiple vSwitches
resource "alicloud_vswitch" "example_vsw" {
  for_each = local.vswitches

  vswitch_name = each.value.name
  cidr_block   = each.value.cidr_block
  vpc_id       = alicloud_vpc.example_vpc.id
  zone_id      = data.alicloud_zones.available_zones.zones[each.value.zone_index].id
}

# Create multiple custom route tables
resource "alicloud_route_table" "example_route_table" {
  for_each = local.route_tables

  route_table_name = each.value.name
  vpc_id           = alicloud_vpc.example_vpc.id
}

# Associate route tables with vSwitches
resource "alicloud_route_table_attachment" "example_route_table_attachment" {
  for_each = local.route_tables

  vswitch_id     = alicloud_vswitch.example_vsw[each.value.vswitch_key].id
  route_table_id = alicloud_route_table.example_route_table[each.key].id
}

# Specify instance type
variable "instance_type" {
  default = "ecs.e-c1m1.large"
}

# Specify image ID
variable "image_id" {
  default = "aliyun_3_x64_20G_alibase_20221102.vhd"
}

# Create a security group
resource "alicloud_security_group" "example_security_group" {
  security_group_name = "example_security_group_name"
  vpc_id              = alicloud_vpc.example_vpc.id
}

# Create a security group rule. Modify the protocol and port as needed.
resource "alicloud_security_group_rule" "allow_internet" {
  type              = "ingress"
  ip_protocol       = "icmp"
  nic_type          = "intranet"
  policy            = "accept"
  port_range        = "-1/-1"
  priority          = 1
  security_group_id = alicloud_security_group.example_security_group.id
  cidr_ip           = "0.0.0.0/0"
}

# Create multiple ECS instances
resource "alicloud_instance" "example_instance" {
  for_each = local.instances

  instance_name        = each.value.name
  vswitch_id           = alicloud_vswitch.example_vsw[each.value.vswitch_key].id
  instance_type        = var.instance_type
  image_id             = var.image_id
  system_disk_category = "cloud_essd"
  security_groups      = [alicloud_security_group.example_security_group.id]
  instance_charge_type = "PostPaid"           # Pay-as-you-go billing
  spot_strategy        = "SpotWithPriceLimit" # Spot instance with price cap
}

# Create multiple EIPs
resource "alicloud_eip_address" "example_eip" {
  for_each = local.eips

  address_name = each.value.name
  isp          = "BGP"
  netmode      = "public"
  bandwidth    = "1"
  payment_type = "PayAsYouGo"
}

# Associate the ECS instance with an EIP
resource "alicloud_eip_association" "example_eip_ecs_association" {
  allocation_id = alicloud_eip_address.example_eip["eip1"].id
  instance_type = "EcsInstance"
  instance_id   = alicloud_instance.example_instance["instance1"].id
}

# Create an Internet NAT gateway
resource "alicloud_nat_gateway" "example_natgw" {
  nat_gateway_name = "example_natgw_name"
  vpc_id           = alicloud_vpc.example_vpc.id
  vswitch_id       = alicloud_vswitch.example_vsw["vsw2"].id
  nat_type         = "Enhanced"
  eip_bind_mode    = "NAT" # EIP binding mode must be NAT
  payment_type     = "PayAsYouGo"
}

# Associate the EIP with the Internet NAT gateway
resource "alicloud_eip_association" "example_eip_natgw_association" {
  allocation_id = alicloud_eip_address.example_eip["eip2"].id
  instance_type = "NAT"
  instance_id   = alicloud_nat_gateway.example_natgw.id
}

# Add a route pointing to the NAT gateway
resource "alicloud_route_entry" "example_rt3_route" {
  route_table_id        = alicloud_route_table.example_route_table["rt3"].id
  destination_cidrblock = "0.0.0.0/0"
  nexthop_type          = "NatGateway"
  nexthop_id            = alicloud_nat_gateway.example_natgw.id
}

# Add a route pointing to the NAT gateway
resource "alicloud_route_entry" "example_rt4_route" {
  route_table_id        = alicloud_route_table.example_route_table["rt4"].id
  destination_cidrblock = "0.0.0.0/0"
  nexthop_type          = "NatGateway"
  nexthop_id            = alicloud_nat_gateway.example_natgw.id
}

# Create SNAT entries
resource "alicloud_snat_entry" "example_snat_entry" {
  for_each = local.snat_entries

  snat_table_id = alicloud_nat_gateway.example_natgw.snat_table_ids
  source_cidr   = alicloud_instance.example_instance[each.value.instance_key].primary_ip_address
  snat_ip       = alicloud_eip_address.example_eip["eip2"].ip_address
}

# Create an IPv4 gateway
resource "alicloud_vpc_ipv4_gateway" "example_ipv4gw" {
  ipv4_gateway_name = "example_ipv4gw_name"
  vpc_id            = alicloud_vpc.example_vpc.id
  enabled           = true
}

# Add a route pointing to the IPv4 gateway
resource "alicloud_route_entry" "example_rt1_route" {
  route_table_id        = alicloud_route_table.example_route_table["rt1"].id
  destination_cidrblock = "0.0.0.0/0"
  nexthop_type          = "Ipv4Gateway"
  nexthop_id            = alicloud_vpc_ipv4_gateway.example_ipv4gw.id
}

# Add a route pointing to the IPv4 gateway
resource "alicloud_route_entry" "example_rt2_route" {
  route_table_id        = alicloud_route_table.example_route_table["rt2"].id
  destination_cidrblock = "0.0.0.0/0"
  nexthop_type          = "Ipv4Gateway"
  nexthop_id            = alicloud_vpc_ipv4_gateway.example_ipv4gw.id
}

Privately used public CIDR block

VPCs use RFC 1918 private CIDR blocks by default: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. When a VPC connects to an on-premises data center or another VPC that uses a non-RFC 1918 CIDR block (for example, 30.0.0.0/16), cloud resources with Internet access send requests to the non-standard block over the public Internet rather than following the configured private route.

After you create and activate an IPv4 gateway, it centrally controls Internet access and all traffic is forwarded based on route tables. vSwitches must have a 0.0.0.0/0 route pointing to the IPv4 gateway for their resources to access the Internet. Based on the longest prefix match rule, traffic destined for ECS02 matches the 30.0.0.0/16 route and is forwarded to the peer VPC instead of going through the Internet.

image

Console

  1. Go to the VPC console - IPv4 Gateway page. Select the region where your VPC is deployed, then click Create IPv4 Gateway.

  2. Create IPv4 gateway: Select the VPC that needs to access the non-standard private CIDR block.

  3. Activate IPv4 gateway: Select the route table associated with the vSwitch that needs to access the non-standard private CIDR block. The system automatically adds a 0.0.0.0/0 route pointing to the IPv4 gateway, enabling resources in the vSwitch to reach the non-standard CIDR block via more specific routes.

    • Make sure the route table does not already contain a 0.0.0.0/0 route. If it does, click Activate Later, delete that route, and then activate.

    • After activation, the IPv4 gateway centrally controls Internet access and all traffic is forwarded based on route tables.

API

Terraform

Unlike the console, activating an IPv4 gateway via Terraform does not automatically add a 0.0.0.0/0 route pointing to the IPv4 gateway. You must configure the route manually.

Resource: alicloud_vpc, alicloud_vswitch, alicloud_vpc_ipv4_gateway, alicloud_route_table, alicloud_route_table_attachment, alicloud_vpc_route_entry, alicloud_instance, alicloud_security_group, alicloud_security_group_rule, alicloud_eip_address, alicloud_eip_association, alicloud_vpc_peer_connection
Data Sources: alicloud_zones
In this example, the VPCs in the peering connection belong to the same account. For a cross-account peering connection, also create an alicloud_vpc_peer_connection_accepter so the peer account accepts the connection request.
# Specify the region for the IPv4 gateway
provider "alicloud" {
  region = "cn-hangzhou"
}

# Automatically obtain zones that support vSwitch creation
data "alicloud_zones" "available_zones" {
  available_resource_creation = "VSwitch" # Query zones available for VPC resources
}

# Specify instance type
variable "instance_type" {
  default = "ecs.e-c1m1.large"
}

# Specify image ID
variable "image_id" {
  default = "aliyun_3_x64_20G_alibase_20221102.vhd"
}

# Create a VPC
resource "alicloud_vpc" "example_vpc1" {
  vpc_name   = "example_vpc1_name"
  cidr_block = "10.0.0.0/16" # Specify the CIDR block 
}

# Create a VPC
resource "alicloud_vpc" "example_vpc2" {
  vpc_name   = "example_vpc2_name"
  cidr_block = "30.0.0.0/16" # Specify the CIDR block 
}

# Create a vSwitch
resource "alicloud_vswitch" "example_vsw1" {
  vswitch_name = "example_vsw1_name"
  cidr_block   = "10.0.1.0/24"
  vpc_id       = alicloud_vpc.example_vpc1.id
  zone_id      = data.alicloud_zones.available_zones.zones.0.id
}

# Create a vSwitch
resource "alicloud_vswitch" "example_vsw2" {
  vswitch_name = "example_vsw2_name"
  cidr_block   = "30.0.1.0/24"
  vpc_id       = alicloud_vpc.example_vpc2.id
  zone_id      = data.alicloud_zones.available_zones.zones.1.id
}

# Create a security group
resource "alicloud_security_group" "example_security_group1" {
  security_group_name = "example_security_group1_name"
  vpc_id              = alicloud_vpc.example_vpc1.id
}

# Create a security group rule. Modify the protocol and port as needed.
resource "alicloud_security_group_rule" "allow_internet1" {
  type              = "ingress"
  ip_protocol       = "icmp"
  nic_type          = "intranet"
  policy            = "accept"
  port_range        = "-1/-1"
  priority          = 1
  security_group_id = alicloud_security_group.example_security_group1.id
  cidr_ip           = "0.0.0.0/0"
}

# Create a security group
resource "alicloud_security_group" "example_security_group2" {
  security_group_name = "example_security_group2_name"
  vpc_id              = alicloud_vpc.example_vpc2.id
}

# Create a security group rule. Modify the protocol and port as needed.
resource "alicloud_security_group_rule" "allow_internet2" {
  type              = "ingress"
  ip_protocol       = "icmp"
  nic_type          = "intranet"
  policy            = "accept"
  port_range        = "-1/-1"
  priority          = 1
  security_group_id = alicloud_security_group.example_security_group2.id
  cidr_ip           = "0.0.0.0/0"
}

# Create an ECS instance
resource "alicloud_instance" "example_instance1" {
  instance_name        = "example_instance1_name"
  vswitch_id           = alicloud_vswitch.example_vsw1.id
  instance_type        = var.instance_type
  image_id             = var.image_id
  system_disk_category = "cloud_essd"
  security_groups      = [alicloud_security_group.example_security_group1.id]
  instance_charge_type = "PostPaid"
  spot_strategy        = "SpotWithPriceLimit"
}

# Create an EIP
resource "alicloud_eip_address" "example_eip" {
  address_name = "example_eip_name"
  isp          = "BGP"
  netmode      = "public"
  bandwidth    = "1"
  payment_type = "PayAsYouGo"
}

# Associate the ECS instance with an EIP
resource "alicloud_eip_association" "example_eip_ecs_association" {
  allocation_id = alicloud_eip_address.example_eip.id
  instance_type = "EcsInstance"
  instance_id   = alicloud_instance.example_instance1.id
}

# Create an ECS instance
resource "alicloud_instance" "example_instance2" {
  instance_name        = "example_instance2_name"
  vswitch_id           = alicloud_vswitch.example_vsw2.id
  instance_type        = var.instance_type
  image_id             = var.image_id
  system_disk_category = "cloud_essd"
  security_groups      = [alicloud_security_group.example_security_group2.id]
  instance_charge_type = "PostPaid"
  spot_strategy        = "SpotWithPriceLimit"
}

# Create a custom route table
resource "alicloud_route_table" "example_route_table1" {
  route_table_name = "example_route_table1_name"
  vpc_id           = alicloud_vpc.example_vpc1.id
}

# Associate the route table with the vSwitch
resource "alicloud_route_table_attachment" "example_route_table_attachment1" {
  vswitch_id     = alicloud_vswitch.example_vsw1.id
  route_table_id = alicloud_route_table.example_route_table1.id
}

# Create a custom route table
resource "alicloud_route_table" "example_route_table2" {
  route_table_name = "example_route_table2_name"
  vpc_id           = alicloud_vpc.example_vpc2.id
}

# Associate the route table with the vSwitch
resource "alicloud_route_table_attachment" "example_route_table_attachment2" {
  vswitch_id     = alicloud_vswitch.example_vsw2.id
  route_table_id = alicloud_route_table.example_route_table2.id
}

# Create a VPC peering connection
resource "alicloud_vpc_peer_connection" "example_vpc_peer" {
  peer_connection_name = "example_vpc_peer_name"
  vpc_id               = alicloud_vpc.example_vpc1.id
  accepting_ali_uid    = "1234****" # The ID of the account that owns the peer VPC. This example creates a same-account peering connection. For cross-account peering, create an alicloud_vpc_peer_connection_accepter so the peer account accepts the request.
  accepting_region_id  = "cn-hangzhou"
  accepting_vpc_id     = alicloud_vpc.example_vpc2.id
}

# Configure a route for the peering connection
resource "alicloud_route_entry" "example_peer_route1" {
  route_table_id        = alicloud_route_table.example_route_table1.id
  destination_cidrblock = "30.0.0.0/16"
  nexthop_type          = "VpcPeer"
  nexthop_id            = alicloud_vpc_peer_connection.example_vpc_peer.id
}

# Configure a route for the peering connection
resource "alicloud_route_entry" "example_peer_route2" {
  route_table_id        = alicloud_route_table.example_route_table2.id
  destination_cidrblock = "10.0.0.0/16"
  nexthop_type          = "VpcPeer"
  nexthop_id            = alicloud_vpc_peer_connection.example_vpc_peer.id
}

# Create an IPv4 gateway
resource "alicloud_vpc_ipv4_gateway" "example_ipv4gw" {
  ipv4_gateway_name = "example_ipv4gw_name"
  vpc_id            = alicloud_vpc.example_vpc1.id
  enabled           = true
}

# Add a route pointing to the IPv4 gateway
resource "alicloud_route_entry" "example_igw_route" {
  route_table_id        = alicloud_route_table.example_route_table1.id
  destination_cidrblock = "0.0.0.0/0"
  nexthop_type          = "Ipv4Gateway"
  nexthop_id            = alicloud_vpc_ipv4_gateway.example_ipv4gw.id
}

Inbound Internet traffic redirection (third-party security devices)

An IPv4 gateway can only centrally control outbound Internet traffic. For inbound traffic entering the VPC, associate a gateway route table with the IPv4 gateway to redirect inbound traffic to a security device for deep inspection and filtering, preventing malicious attacks and unauthorized access. Combined with custom route tables, you can also redirect outbound traffic to the security device for comprehensive inbound and outbound protection.

An IPv4 gateway can only be associated with a gateway route table (a border gateway type route table). Each VPC supports only one IPv4 gateway and one gateway route table, in a one-to-one binding.
To configure inbound traffic redirection, modify the system route entry in the gateway route table and set the next hop of the target vSwitch CIDR block to the security device. The gateway route table does not support creating custom routes via Add Route Entry.

Single-point architecture

image

GWLB high-availability architecture

In a single-point architecture, a security device failure affects the availability of your entire system. Deploy security devices behind a Gateway Load Balancer (GWLB) for high availability and to eliminate single points of failure.

image

Inbound IPv4 Internet traffic path

Outbound IPv4 Internet traffic path

1. IPv4 traffic enters the business VPC through the IPv4 gateway.

2. The gateway route table directs the traffic to the GWLBe.

3. The GWLBe forwards the traffic to the GWLB, which distributes it to a security device.

4. After inspection, the traffic returns to the GWLB, then to the GWLBe through PrivateLink.

5. The route table for the GWLBe subnet forwards the traffic to the business server.

1. The route table for the business server subnet directs traffic to the GWLBe.

2. The GWLBe forwards the traffic to the GWLB, which distributes it to a security device.

3. After inspection, the traffic returns to the GWLB, then to the GWLBe through PrivateLink.

4. The route table for the GWLBe subnet forwards the traffic to the IPv4 gateway.

5. The IPv4 gateway routes the traffic to the Internet.

To configure the gateway route table: find the system route for the target vSwitch CIDR block, click Edit in the Actions column, and set the next hop to the GWLBe. After saving, the route entry appears on the Custom Route tab.

Console

Associate a gateway route table

On the details page of the target IPv4 gateway, click Bind. Alternatively, on the Associated Border Gateway tab of the target gateway route table details page, click Associate Border Gateway and select the target IPv4 gateway.

Disassociate a gateway route table

On the details page of the target IPv4 gateway, or on the Associated Border Gateway tab of the target gateway route table details page, click Unbind.

API

Terraform

Resource: alicloud_vpc_gateway_route_table_attachment
# Specify the region where the IPv4 gateway is deployed
provider "alicloud" {
  region = "cn-hangzhou"
}

# Specify the IPv4 gateway ID
variable "ipv4_gateway_id" {
  default = "ipv4gw-hp3v******" # Replace with the actual IPv4 gateway ID
}

# Specify the gateway route table ID
variable "route_table_id" {
  default = "vtb-hp3w******" # Replace with the actual gateway route table ID
}

# Associate the gateway route table
resource "alicloud_vpc_gateway_route_table_attachment" "example_attachment" {
  ipv4_gateway_id = var.ipv4_gateway_id
  route_table_id  = var.route_table_id
}

Additional information

Limits

  • Each VPC supports only one IPv4 gateway, and an IPv4 gateway can be associated with only one VPC.

  • You cannot create an IPv4 gateway if any resource in the VPC uses EIP cut-through mode.

    For example, if an Internet NAT gateway in the VPC has its EIP binding mode set to multi-EIP-to-ENI mode, it is incompatible with the IPv4 gateway. Call ModifyNatGatewayAttribute to change the EipBindMode to NAT mode for compatibility.

  • In a shared VPC scenario, only the resource owner can create, modify, or delete an IPv4 gateway. Resource users do not have these permissions.

  • When an EIP or Anycast EIP is associated with a private-facing CLB instance:

    • In the following regions, Internet access traffic is also subject to IPv4 gateway restrictions. Supported regions are subject to change.

      Asia Pacific - China: China (Hangzhou), China (Shanghai), China (Qingdao), China (Hohhot), China (Ulanqab), China (Shenzhen), China (Guangzhou), China (Chengdu), China (Hong Kong)
      Asia Pacific - Other: Japan (Tokyo), Malaysia (Kuala Lumpur), Indonesia (Jakarta), Malaysia (Johor), Thailand (Bangkok), Philippines (Manila)
      Europe and Americas: UK (London), France (Paris), US (Virginia), US (Silicon Valley)
      Middle East: SAU (Riyadh - Partner Region)
      • A private-facing CLB deployed in a public vSwitch can access the Internet after associating a public IP address.

      • A private-facing CLB deployed in a private vSwitch cannot access the Internet even with a public IP address. Configure a route pointing to an Internet NAT gateway to route Internet-bound traffic through the NAT gateway and use its associated public IP address for Internet access.

        image
    • In other regions, Internet access traffic is not subject to IPv4 gateway restrictions.

Billing

IPv4 gateways are free of charge.

Internet traffic costs are generated by the associated public IP addresses (such as EIPs or static public IP addresses of ECS/CLB instances). See the billing documentation for the respective product.

Supported regions

Area

Regions

Asia Pacific - China

China (Hangzhou), China (Shanghai), China (Nanjing - Local Region, Closing Down), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Hohhot), China (Ulanqab), China (Shenzhen), China (Heyuan), China (Guangzhou), China (Chengdu), China (Zhongwei), China (Hong Kong), China (Wuhan - Local Region), China (Fuzhou - Local Region, Closing Down)

Asia Pacific - Others

Japan (Tokyo), South Korea (Seoul), Singapore (Singapore), Malaysia (Kuala Lumpur), Indonesia (Jakarta), Philippines (Manila), Thailand (Bangkok), Malaysia (Johor)

Europe & Americas

Germany (Frankfurt), UK (London), France (Paris), US (Silicon Valley), US (Virginia), Mexico, and Brazil (São Paulo)

Middle East

UAE (Dubai) and SAU (Riyadh - Partner Region)

Quotas

Quota name

Description

Default limit

Adjustable

None

The maximum number of IPv4 gateways per VPC.

1

No

The maximum number of gateway route tables per IPv4 gateway.

1