A NAT Gateway gives private subnets of a VPC outbound IPv4 internet access without a public IPv4 address on each interface. Traffic through it leaves from the gateway’s one public IPv4 address, which you can allowlist elsewhere. In the console, open Private Networks, then NAT Gateways.
- Outbound only. Instances behind a gateway open connections to the internet and get the replies. Nothing on the internet can open a connection to the gateway’s address.
- One address, fixed. The gateway’s public IPv4 address is assigned when you create the
gateway, before it’s
active, and doesn’t change until you delete the gateway. - Routes decide. Creating a gateway changes no routes. A subnet uses a gateway only once its route table has a route to it.
- IPv4 only. IPv6 isn’t translated. A subnet’s IPv6 internet path is a
::/0route to the VPC’s Network Gateway. - Firewalls are unchanged. An instance’s outbound firewall rules apply to the internet destination as they do without a gateway. The gateway needs no rule of its own.
The public subnet
A gateway lives in a subnet you choose, and that subnet must be public:
- its VPC has an attached Network Gateway, and
- the subnet’s route table routes
0.0.0.0/0to that Network Gateway.
Keep 4 addresses free in the subnet. The subnets that use the gateway are other subnets of the same VPC: a route table associated with the gateway’s own subnet can’t route to it.
Create a gateway
| Action | Console | API | CLI |
|---|---|---|---|
| List (by VPC) | NAT Gateways | ListNatGateways ?vpc= |
ezgh compute nat-gateways list --vpc <vpc> |
| Create | Create NAT Gateway | CreateNatGateway { name, vpc, subnet } |
ezgh compute nat-gateways create <name> --vpc <vpc> --subnet <subnet> |
| Rename | Edit | UpdateNatGateway { name } |
ezgh compute nat-gateways update <gateway> --name <name> |
| Delete | Delete | DeleteNatGateway |
ezgh compute nat-gateways delete <gateway> |
ezgh compute nat-gateways create egress --vpc main --subnet public --waitCreate and delete are asynchronous: each answers 202 with the gateway, provisioning or
deleting. Read the gateway until its status is active; a deleted gateway answers 404. The
CLI’s --wait does this for you. Give a gateway by ID (nat_…) or, in the CLI, by name.
| Field | Meaning |
|---|---|
vpc, subnet |
The VPC it serves (vpc_…) and the public subnet it’s in (sbn_…). Fixed |
publicIpv4Addresses |
[{ id, address }]: the public IPv4 address (pip_…) its traffic leaves from |
status |
provisioning, active or deleting |
| Refusal | When |
|---|---|
409 network_gateway_required |
Create: the VPC has no attached Network Gateway |
409 subnet_not_public |
Create: the subnet’s route table has no 0.0.0.0/0 route to the Network Gateway |
409 quota_exceeded |
Create: the project is at its NAT Gateway quota |
Route a subnet through the gateway
Point the private subnet’s route table at the gateway. The destination is 0.0.0.0/0, or any IPv4
range outside the VPC’s ranges:
| Console | API | CLI |
|---|---|---|
| Add route, then the NAT Gateway as its target | SetRoutes { routes: [{ destination, target: { type: "natGateway", id: "nat_…" } }] } |
ezgh compute route-tables routes set <table> <destination> --target <nat_…> |
ezgh compute route-tables create private --vpc main
ezgh compute subnets update app --route-table private
ezgh compute route-tables routes set private 0.0.0.0/0 --target nat_4k2m9x0a7qpeThe route’s state is blackhole until the gateway is active, and again once the gateway is
deleted. A blackhole route drops its traffic. Routes are never removed for you: deleting a gateway
leaves its routes in their tables until you change or remove them.
| Refusal | When |
|---|---|
400 invalid_request |
The destination is an IPv6 range |
409 route_table_conflict |
The table is associated with the gateway’s own subnet |
409 vpc_has_no_gateway |
The gateway is in another VPC than the route table |
What a gateway depends on
While a gateway exists, these are refused with 409 nat_gateway_in_use, which names the gateway:
- detaching the VPC’s Network Gateway;
- removing the
0.0.0.0/0route from the route table of the gateway’s subnet; - deleting the gateway’s subnet or VPC;
- disassociating or releasing the gateway’s public IPv4 address.
Delete the gateway first. Its public IPv4 address is released with it.
Connections
| Limit | Value |
|---|---|
| Idle timeout, established TCP connection | 3,600 seconds |
| Idle timeout, UDP | 30 seconds; 120 seconds for a flow with traffic in both directions |
| Idle timeout, ICMP | 30 seconds |
| Concurrent connections to one destination address and port | About 64,000 |
| Public IPv4 addresses per gateway | 1 |
- A connection idle for longer than its timeout is dropped. Send keepalives on connections that stay open and quiet for longer.
- TCP port 25 isn’t forwarded. Connections to port 25 through a gateway fail.
- Connections can reset during maintenance. Open connections through a gateway can be reset when the gateway is maintained or its capacity changes. New connections work again within seconds. Applications should reconnect.
Limits
| Limit | Value | |
|---|---|---|
| NAT Gateways per project | 5 | Quota network.natGatewaysPerProject |
IAM
| Action | On |
|---|---|
network.natGateways.list, network.natGateways.create |
The project |
network.natGateways.get, network.natGateways.update, network.natGateways.delete |
The NAT Gateway |
NetworkFullAccess has them all; NetworkReadOnlyAccess and ReadOnlyAccess have the list and
view actions. Routing a subnet through a gateway needs network.routeTables.updateRoutes on the
route table. See IAM.