Every kind of address in a VPC
Builds on2. Private and public addresses
A VM's network card can carry several addresses, and other resources have addresses of their own. The one column to watch is the second: whether the address actually exists inside the VM.
| # | Address | On the VM's card? | Comes from | Scope | Kadé's example | Chapter |
|---|---|---|---|---|---|---|
| 1 | Primary internal IPv4 | yes | The subnet's primary range | Regional | 10.10.1.10 on kade-api-1 | 3 |
| 2 | Alias IP range | yes | The subnet's primary or secondary range | Regional | none yet (section 08) | 2, 3 |
| 3 | External IPv4 | no | Google's public pool, mapped by 1:1 NAT | Regional | the old 34.87.120.15 | 3 |
| 4 | IPv6 (internal or external) | yes | The subnet's /64; no NAT | Regional | none; Kadé is IPv4 only | 3 |
| 5 | Internal load balancer IP | - | A subnet's primary range, held by a forwarding rule | Regional | none yet | 11 |
| 6 | Global external IP | - | Google's anycast pool | Global | load balancer 34.120.88.10 | 3, 11 |
| 7 | Regional external IP for a service | - | Google's pool in one region | Regional | Cloud NAT 34.87.200.7 | 3, 7 |
| 8 | Global internal IP | - | Any free internal range outside your subnets | Global | a Private Service Connect endpoint for Google APIs | 9 |
Only rows 6 and 8 are global, and no address is zonal. Even when a zonal VM holds an address, the address belongs to a region, so it can outlive the VM's zone (section 07).
The external IP is not on the VM
Builds on10. NAT, and 1:1 NAT
The internal IP is real in every sense: it is on the network card, it shows in ip addr, and the app can bind to it. The external IP is only a mapping kept by the data plane on the VM's host (chapter 1.2). It is the 1:1 NAT from the fundamentals course, done beside every VM instead of in a box at the edge.
- Run by Google
- Your VPC
- Allowed traffic and replies
The external IP is attached as an "access config" of type ONE_TO_ONE_NAT on the VM's network card. The name says exactly what it is.
Wide by design - scroll it sideways.
Four things follow from this, and each one causes real bugs:
| # | Consequence | What goes wrong | Do this instead |
|---|---|---|---|
| 1 | The VM does not know its external IP | An app that reads its own address to build URLs or callbacks gets 10.10.1.10 | Ask the metadata server (gcloud check below), or use a DNS name |
| 2 | The app cannot bind to the external IP | listen 34.87.120.15:8080 fails: that address is not on any interface (Fundamentals ch 31) | Bind to 0.0.0.0 or the internal IP |
| 3 | Outside services see the external IP | An allow-list (PayGate, a partner, Cloud SQL authorized networks) must hold the external IP, not the internal one. The VM never sees that address, so it is easy to get wrong | Use a static IP for anything an allow-list depends on (section 03) |
| 4 | Firewall rules on the receiving side see the sender's external IP | If one of your own VMs calls another through an external IP, the internal allow rule does not match (section 06) | Use internal IPs between your own VMs |
Ephemeral and static
Every internal and external address is either ephemeral (it belongs to the VM for a while) or static (a named address resource you own until you release it). The two kinds behave very differently for internal and external addresses:
| # | Ephemeral internal | Static internal | Ephemeral external | Static external | |
|---|---|---|---|---|---|
| 1 | Comes from | Next free address in the subnet | An address you reserve in a subnet | Google's pool, when the VM starts | An address you reserve |
| 2 | VM stopped and started | same address | same address | new address | same address |
| 3 | VM deleted | Released | Kept, ready to reuse | Released | Kept, ready to reuse |
| 4 | Listed by addresses list | No | Yes | No | Yes |
| 5 | Cost | Free | Free | Charged while the VM runs | Charged while in use; charged more while idle |
Row 2 is Kadé's outage: an ephemeral external address does not survive a stop. Ephemeral internal addresses do, which is why kade-db has kept 10.10.2.5 so far. It would lose it only if the VM were deleted and recreated.
So the rule is simple: if anything depends on an address, make it static. A DNS record, an allow-list, a partner's config, or an app setting all count.
Try it: what happens to the address?
The address
What happens
Same address. Ephemeral internal addresses stay with the VM across stop and start. This is why kade-db has kept 10.10.2.5 so far.
Regional and global external addresses
A static external address is reserved as either regional or global (chapter 1.1), and one cannot be used where the other is needed:
| # | Scope | Used by | Kadé's example | Tier |
|---|---|---|---|---|
| 1 | Regional | VMs, Cloud NAT, regional load balancers, VPN gateways, in one region | kade-nat-ip 34.87.200.7 in asia-southeast1 (chapter 7) | Premium or Standard |
| 2 | Global | Global external load balancers only | kade-lb-ip 34.120.88.10 | Premium only |
Network tiers: Premium and Standard
Builds on12. How routing works across the internet
Every external address has a network tier. The tier decides where traffic joins or leaves Google's network, and so how much of the trip happens on the public internet. Premium is the path from chapter 1.1: the shopper enters Google at the nearest edge and rides the backbone to Singapore. Standard skips that edge.
- Run by Google
- Your VPC
The difference is who carries the packet. Premium: Google, from near the user. Standard: the public internet, until close to your region.
Wide by design - scroll it sideways.
| # | Premium | Standard | |
|---|---|---|---|
| 1 | Where traffic enters and leaves Google | The Google edge nearest the user | Near your GCP region |
| 2 | Rest of the trip | Google's private backbone | The public internet, through other providers |
| 3 | Latency and consistency | Lower and steadier | Higher and more variable |
| 4 | Outbound data price | Higher | Lower |
| 5 | Global load balancers and global IPs | Supported | Not supported; regional only |
| 6 | Good for | Anything users wait on | Batch jobs, bulk downloads, tools where the path does not matter |
The tier is set per address or resource, and a project has a default tier (Premium unless changed). A resource and its address must use the same tier, which is why a global load balancer can only ever have a Premium address. Everything shopper-facing at Kadé is Premium.
Between your own VMs, always use internal addresses
A common mistake is one VM calling another (or itself) through an external IP, often because the external address was copied into a config file. It works, which is why it goes unnoticed. But the packet goes out through 1:1 NAT and comes back in as if it came from the internet:
| # | kade-api-1 → 10.10.2.5:5432 | kade-api-1 → kade-db's external IP (if it had one) | |
|---|---|---|---|
| 1 | Source kade-db sees | 10.10.1.10 | kade-api-1's external IP, or the NAT IP |
| 2 | Firewall rule needed on kade-db | An internal rule for 10.10.0.0/16 | A rule that allows an external address, and so is open wider than it should be |
| 3 | Cost | Internal traffic pricing | Counted as traffic leaving the zone, even inside one zone |
| 4 | Needs | Nothing extra | Both VMs to have external IPs, or NAT |
The same applies to a VM calling its own external IP, which usually means a setting that should say localhost or an internal name. The fix is always the same: internal IPs or internal DNS names (chapter 8) between your own machines.
Choosing and keeping internal addresses
By default a VM gets the next free address in its subnet. You can choose one when you create the VM, or reserve one ahead of time so nothing else takes it:
| # | Goal | How |
|---|---|---|
| 1 | Pick an address when creating a VM | --private-network-ip=10.10.1.20, or pass the name of a reserved address |
| 2 | Keep an address that is already in use | Promote it: reserve the same address in the same subnet (section 03) |
| 3 | Hold an address for something that does not exist yet | Reserve it now; it stays yours until you use or release it |
For Kadé, that means promoting kade-db's 10.10.2.5 now, so the hardcoded address is safe until chapter 8 gives it a name, and reserving 10.10.1.20 for kade-worker, which arrives in chapter 10.
A reserved internal address belongs to its subnet, so to the region, not to the VM's zone (section 01). That matters for a zonal VM like kade-db. If it ever has to be rebuilt in another zone, after a zone failure or simply a move, it can come back with the same address:
- Google's: the region and its zones
- The reserved address
- kade-db, old and new
The address outlives the zone. Once the old VM is deleted, a new one in any zone of the region can take it.
Wide by design - scroll it sideways.
The new VM asks for it by name: --private-network-ip=kade-db-ip. This keeps the address, not the data. kade-db's disk is zonal and stays in zone b, so the new VM needs a snapshot (global) or a regional disk. Cloud SQL with high availability (chapter 9) handles both for you.
Alias IPs in practice
Chapter 2 introduced alias IP ranges. Adding one, or moving it from one VM to another, is a change to the VM's network card through GCP, not inside the OS:
| # | Step | Command (short form) |
|---|---|---|
| 1 | Give kade-api-1 the extra address 10.10.1.100 | network-interfaces update kade-api-1 --aliases="10.10.1.100/32" |
| 2 | Take it away from kade-api-1 | network-interfaces update kade-api-1 --aliases="" |
| 3 | Give it to kade-api-2 | network-interfaces update kade-api-2 --aliases="10.10.1.100/32" |
On Google's standard images, the guest agent adds the alias to the OS's local routing table, so the VM accepts traffic for it without any manual setup. This remove-then-add move is the GCP way to do what gratuitous ARP did on a real LAN (chapter 1.2 section 10). For automatic failover, an internal load balancer with health checks is still the better tool (chapter 11).
IP forwarding and the anti-spoofing check
By default, the data plane checks every packet a VM sends and receives:
- A VM may only send packets whose source is one of its own addresses.
- A VM may only receive packets whose destination is one of its own addresses.
Anything else is dropped on the host. This is what stops one VM from pretending to be another. The canIpForward setting (--can-ip-forward when creating a VM) turns the check off, so the VM can pass traffic on for other machines. Only something built to forward traffic needs it: a router VM, a VPN appliance, or a self-built NAT VM.
| # | Question | Answer |
|---|---|---|
| 1 | Does Kadé need it? | No. Cloud NAT and Cloud VPN are managed services, so Kadé never runs its own forwarding VM |
| 2 | Why check for it? | A VM with forwarding on can relay traffic it should not. Security benchmarks (CIS 4.6) flag it |
| 3 | Can it be changed later? | It used to be creation-only. Today you can change it by exporting the VM's config, editing canIpForward, and applying it with update-from-file, which restarts the VM |
IPv6 in GCP, briefly
Builds on30. IPv6
Kadé stays on IPv4, so this is only what is different in GCP:
| # | Point | Detail |
|---|---|---|
| 1 | Where it lives | A dual-stack subnet gets a /64; each VM network card gets a /96 from it, handed out by DHCPv6 |
| 2 | Internal or external | Chosen per subnet. Internal addresses come from the VPC's /48 in fd20::/20; external ones are real internet addresses |
| 3 | No NAT | An external IPv6 address is really on the VM and shows in ip addr, unlike external IPv4 (section 02) |
| 4 | Limits | Custom mode networks only; external IPv6 needs Premium tier |
| 5 | Firewall | IPv6 needs its own rules. An IPv4 rule never matches IPv6 traffic |
Back to Kadé
Commands in this chapter
Commands 1 to 5 are read-only. Commands 6 to 10 change the project.
List reserved addresses
- What it shows: Every static address in the project, internal and external, with its status.
- What to look for:
RESERVEDexternal addresses nobody uses (billed while idle), and important addresses missing from the list, which means they are ephemeral.
gcloud compute addresses listSee a VM's internal and external addresses
- What it shows:
networkIP(on the card) and anyaccessConfigswithnatIP(the 1:1 NAT mapping). - What to look for: An
accessConfigsblock on a VM that should not have an external IP.
gcloud compute instances describe kade-api-1 --zone=asia-southeast1-a \ --format="yaml(networkInterfaces)"Ask a VM for its own external IP
- What it shows: The external IP, as the metadata server knows it. Run inside the VM.
- What to look for: Empty output means no external IP.
curl -s -H "Metadata-Flavor: Google" \ http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ipFind VMs with IP forwarding on
- What it shows: VMs where the anti-spoofing check is off.
- What to look for: An empty list, unless you run a router or appliance on purpose.
gcloud compute instances list --filter="canIpForward=true"See the project's default network tier
- What it shows: The tier used when a resource does not say.
- What to look for:
PREMIUM, or empty, which also means Premium.
gcloud compute project-info describe --format="value(defaultNetworkTier)"Promote kade-db's address to static (changes the project)
- What it shows: Reserves the address kade-db already uses, so it survives the VM being rebuilt.
- What to look for:
kade-db-ipappears in command 1 with statusIN_USE. kade-db keeps running throughout.
gcloud compute addresses create kade-db-ip \ --region=asia-southeast1 --subnet=sn-data --addresses=10.10.2.5Reserve an internal address for later (changes the project)
- What it shows: Holds
10.10.1.20for kade-worker. - What to look for: Status
RESERVEDuntil a VM uses it. Internal reservations are free.
gcloud compute addresses create kade-worker-ip \ --region=asia-southeast1 --subnet=sn-app --addresses=10.10.1.20Promote an ephemeral external IP (changes the project)
- What it shows: The fix for this chapter's outage: keep the external IP a VM already has, so a restart does not change it.
- What to look for: The same address, now listed as static. Shown for a VM that still has an external IP; replace the address and region with your own.
gcloud compute addresses create kade-api-ip \ --addresses=34.87.121.204 --region=asia-southeast1Remove an external IP from a VM (changes the project)
- What it shows: Deletes the access config, so the VM has no external IP.
- What to look for: No
accessConfigsin command 2. An ephemeral address is gone for good; a static one returns toRESERVEDand starts costing the idle rate.
gcloud compute instances delete-access-config kade-api-1 \ --zone=asia-southeast1-a --access-config-name="external-nat"Move an alias IP between VMs (changes the project)
- What it shows: Removes the alias from kade-api-1, then gives it to kade-api-2.
- What to look for: The alias appears under
aliasIpRangeson kade-api-2 in command 2. Traffic to it stops briefly between the two steps.
gcloud compute instances network-interfaces update kade-api-1 \ --zone=asia-southeast1-a --aliases=""gcloud compute instances network-interfaces update kade-api-2 \ --zone=asia-southeast1-b --aliases="10.10.1.100/32"