Topic 7 of 10
Exam section 3.3 covers day-to-day network changes: adding or expanding subnets, reserving IP addresses, configuring routes, Cloud DNS, and Cloud NAT. VPC networks, firewall rules, and load balancers are covered in domain D2.
Contents
# Add a subnet to an existing network gcloud compute networks subnets create subnet-eu --network=prod-vpc \ --range=10.20.0.0/24 --region=europe-west1 # Add or remove a secondary range gcloud compute networks subnets update subnet-eu --region=europe-west1 \ --add-secondary-ranges=pods=10.30.0.0/20 gcloud compute networks subnets update subnet-eu --region=europe-west1 \ --remove-secondary-ranges=pods # Convert an auto mode network to custom mode gcloud compute networks update prod-vpc --switch-to-custom-subnet-mode
--subnet.You expand the primary IPv4 range of an existing subnet by shortening its prefix length (for example, from /24 to /20). It takes a few minutes and doesn't interrupt traffic in the subnet.
gcloud compute networks subnets expand-ip-range subnet-eu \ --region=europe-west1 --prefix-length=20
Can't be undone
You can't shrink a primary range afterwards. Google recommends expanding conservatively (you can always expand again) and considering networks connected through peering or VPN so ranges don't overlap.
By default, a VM without an external IP address can only send packets to internal destinations. Enabling Private Google Access on the subnet lets those VMs reach the external IP addresses of Google APIs and services (and App Engine). It only applies to interfaces without an external IP.
gcloud compute networks subnets update subnet-eu --region=europe-west1 \ --enable-private-ip-google-access
External IP addresses are ephemeral or static. In general, an ephemeral address is released when you stop or delete the resource. A static address is a reserved resource that stays yours until you release it.
| Type | For which resources |
|---|---|
| Regional IPv4 (/32) | VMs and regional load balancers |
| Global IPv4 (/32) or IPv6 (/64) | Global load balancers |
| Regional IPv6 (/96) | VMs and supported regional load balancers; comes from the subnet's external IPv6 range |
# Reserve a new regional address gcloud compute addresses create web-ip --region=europe-west1 # Reserve a global address for a global load balancer gcloud compute addresses create lb-ip --global --ip-version=IPV4 # Promote an in-use ephemeral address to static gcloud compute addresses create web-ip --addresses=34.0.0.10 --region=europe-west1 # Release an address gcloud compute addresses delete web-ip --region=europe-west1
roles/compute.networkAdmin.Reserving an internal address takes it out of the subnet's dynamic allocation pool, so you always use the same IP even if you delete and recreate the resource. They are regional.
gcloud compute addresses create db-ip --region=europe-west1 \ --subnet=subnet-eu --addresses=10.20.0.50
--addresses, a free address from the subnet is allocated.A route has a single destination prefix and a single next hop. The routing table is defined at the VPC network level and there is no physical router: it's a distributed virtual mechanism.
| Type | Detail |
|---|---|
| Subnet routes | Created and removed automatically with each subnet range (including peered networks). You can't create a static route equal to or inside a subnet route |
| System-generated default route | 0.0.0.0/0 to default-internet-gateway, created with the network. Gives internet egress to VMs with external IPs and to public Cloud NAT. Can be removed or replaced |
| Static routes | Custom. Next hop: gateway, instance, IP, internal passthrough Network Load Balancer, or Classic VPN tunnel. Can apply only to VMs with certain network tags |
| Dynamic routes | Learned through BGP from Cloud Router; applied according to the network's dynamic routing mode |
| Policy-based routes | Evaluated before all others; match on source, destination, or protocol |
gcloud compute routes create to-onprem --network=prod-vpc \ --destination-range=192.168.0.0/16 \ --next-hop-instance=appliance-vm --next-hop-instance-zone=europe-west1-b \ --priority=800 --tags=needs-appliance
A managed global DNS service that publishes your zones and records without running your own DNS servers. It supports IAM permissions at the project and zone level.
| Zone | What for |
|---|---|
| Public | Visible on the internet. To use it, the domain registrar must point to the Cloud DNS name servers |
| Private | Visible only from the VPC networks you authorize. With Shared VPC it's created in the host project (or in a service project with cross-project binding) |
| Forwarding | A private zone that sends queries to target servers, for example on-premises DNS over VPN or Interconnect (outbound forwarding) |
| Peering | A private zone that resolves names using another VPC network's resolution order |
gcloud dns managed-zones create internal-zone --description="Internal" \ --dns-name=corp.internal. --visibility=private --networks=prod-vpc gcloud dns record-sets create db.corp.internal. --zone=internal-zone \ --type=A --ttl=300 --rrdatas=10.20.0.50
Address translation for outbound traffic from VMs, GKE clusters, Cloud Run, Cloud Run functions, App Engine standard, and regional internet NEGs. It only allows responses to established connections: it doesn't allow unsolicited inbound connections. It's a distributed, software-defined service with no proxy VMs.
Public NAT
Resources without external IPs reach the internet through a shared set of external IPs. Depends on a static route with the default-internet-gateway next hop.
Private NAT
Translation between private networks: other VPCs on an NCC hub, on-premises networks, or other clouds, even with overlapping subnets.
gcloud compute routers create nat-router --network=prod-vpc --region=europe-west1 gcloud compute routers nats create nat-config --router=nat-router \ --region=europe-west1 --nat-all-subnet-ip-ranges --auto-allocate-nat-external-ips
--nat-custom-subnet-ip-ranges limits it to certain subnets. Manual IP assignment lets you give a third party a fixed list of source IPs.A diagnostics tool that checks connectivity between two endpoints (a VM, GKE cluster, forwarding rule, internet IP…). It analyzes your configuration and simulates the path a packet would take through the VPC, VPN tunnels, or VLAN attachments; in some cases it also sends real packets to measure latency and loss. It helps find inconsistent or obsolete configuration, such as a firewall rule or route that blocks traffic. It uses the Network Management API.
| Situation | Answer | Why |
|---|---|---|
| A /24 subnet has run out of IP addresses and can't be recreated | gcloud compute networks subnets expand-ip-range --prefix-length | Expands without interrupting traffic; can't be undone. |
| A VM with an ephemeral external IP must keep it even if the VM is deleted | Promote the ephemeral IP to static | gcloud compute addresses create --addresses=IP. |
| VMs without external IPs need to download patches from the internet | Cloud NAT (Public NAT) in the subnet's region | Egress without external IPs; no unsolicited inbound connections. |
| VMs without external IPs must call the Cloud Storage API | Enable Private Google Access on the subnet | Reach Google APIs without an external IP. |
| Resolve internal names only from the VPC | Cloud DNS private zone authorized for that VPC | Visible only from the networks you specify. |
| Send traffic for 192.168.0.0/16 through an appliance VM | Static route with --next-hop-instance | The route with the most specific destination wins. |
| Check why one VM can't reach another without sending real traffic | Connectivity Tests | Analyzes configuration and simulates the packet path. |
| A reserved external IP address is unused | Release it with gcloud compute addresses delete | An unassigned static IP is charged at a higher rate. |
❓ Can you shrink a subnet range after expanding it?
No. Expansion can't be undone; expand conservatively.
❓ Does expanding a subnet interrupt its VMs' traffic?
No. It takes a few minutes, but traffic in the subnet isn't interrupted.
❓ Does Cloud NAT let someone on the internet connect to a VM without an external IP?
No. It only translates outbound traffic and its responses; unsolicited inbound connections aren't allowed.
❓ Can you convert a custom mode network to auto mode?
No. Only auto to custom, and it's one-way.
❓ Does deleting a VM release its static internal IP?
No. You must release it manually; until then it stays reserved.
❓ Does Cloud NAT need a Cloud Router?
Yes, each gateway is associated with a Cloud Router, even though traffic doesn't pass through it.
Did you get this topic?
Test what you just learned
The app-subnet subnet (10.10.0.0/24) in a custom mode network has run out of free IP addresses. You need to add more VMs in the same subnet without interrupting the ones already running. What do you do?
Original questions, each with a full explanation.
Start a mock exam