Google Cloud Tutorial · Networking · Lesson 18 of 27

Cloud NAT, Private Google Access and Cloud DNS

Giving private VMs and nodes outbound access without public IPs, reaching Google APIs privately, and DNS.

Members can save this page, take notes and track progress. See membership · Sign in

Private by default

Production VMs and GKE nodes usually have no external IP addresses. They still need two kinds of outbound access:

  • Google APIs (Cloud Storage, BigQuery, Artifact Registry): enable Private Google Access on the subnet, or create a Private Service Connect endpoint for a private IP address that reaches Google APIs.
  • The internet (package repositories, partner APIs): add Cloud NAT to a Cloud Router in the region.
gcloud compute routers create nat-router --network=acme-vpc --region=europe-west1
gcloud compute routers nats create nat-euw1 --router=nat-router --region=europe-west1 \
  --auto-allocate-nat-external-ips --nat-all-subnet-ip-ranges --enable-dynamic-port-allocation

NAT ports

Each VM gets a share of the NAT IP's source ports (64 by default with static allocation). A busy VM that opens many connections to the same destination can run out, causing dropped connections; dynamic port allocation or more NAT IPs fix it.

Cloud NAT port allocation trade-offTry it yourself
ports_per_ip = 64512                       # usable source ports per NAT IP
for min_ports in [64, 1024, 4096]:
    vms_per_ip = ports_per_ip // min_ports
    print(f"{min_ports:5} ports per VM -> one NAT IP serves {vms_per_ip:4} VMs, "
          f"each with up to {min_ports} parallel connections to one destination")

Output

   64 ports per VM -> one NAT IP serves 1008 VMs, each with up to 64 parallel connections to one destination
 1024 ports per VM -> one NAT IP serves   63 VMs, each with up to 1024 parallel connections to one destination
 4096 ports per VM -> one NAT IP serves   15 VMs, each with up to 4096 parallel connections to one destination

Cloud DNS

Cloud DNS hosts public zones and private zones visible only to chosen VPC networks, plus forwarding and peering zones for hybrid DNS with on-premises.

Test yourself

A private VM with no external IP needs to read from Cloud Storage. What do you enable?

  1. A public IP on the VM
  2. Private Google Access on its subnet
  3. VPC peering with Google
  4. Cloud CDN
Show answer

Answer: Private Google Access on its subnet

Private Google Access lets internal-only VMs reach Google APIs.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake