Brains4Cloud
ESEN
Practice

Topic 7 of 10

D3 · Ensuring the successful operation of a cloud solution

Operating the network

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.

# 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
  • You can remove a secondary range only if no resources use its IP addresses.
  • Before deleting a subnet you must delete everything that uses it: VMs, reserved internal IP addresses, internal forwarding rules, and Cloud NAT gateways.
  • In an auto mode network you can't delete the automatically created subnets. You must convert it to custom mode; the conversion keeps the subnets with their names and ranges and is one-way. Afterwards, gcloud commands must reference the subnet explicitly with --subnet.

Expanding a subnet range

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.

  • For automatically created subnets, the broadest prefix allowed is /16; anything broader would conflict with the other automatic subnets.
  • Proxy-only subnets for load balancers can't be expanded.
  • Afterwards, review anything that depends on the old range: add firewall rules that cover the expanded range and, in GKE, add it to the control plane authorized networks.

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

Static external IP addresses

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.

TypeFor 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
  • Required role: roles/compute.networkAdmin.
  • Only one resource at a time can use a static address, and you can't rename it.
  • A static address that is reserved but unassigned is charged at a higher rate than addresses in use.
  • In the console you can release it only if it isn't in use; with gcloud you can release it even while assigned, and it stays on the resource until the resource is deleted. Once released, you might not get it back.

Static internal IP addresses

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
  • If you omit --addresses, a free address from the subnet is allocated.
  • You can't change the internal IP of an existing VM, whether running or stopped. You can promote its ephemeral address to static.
  • Deleting the resource doesn't release a static internal address: you must release it manually.

Routes

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.

TypeDetail
Subnet routesCreated 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 route0.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 routesCustom. Next hop: gateway, instance, IP, internal passthrough Network Load Balancer, or Classic VPN tunnel. Can apply only to VMs with certain network tags
Dynamic routesLearned through BGP from Cloud Router; applied according to the network's dynamic routing mode
Policy-based routesEvaluated 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
  • Order: special routing paths, policy-based routes, subnet routes, and then, among static and dynamic routes, the most specific destination wins first (10.240.1.0/24 before 10.240.0.0/16), then priority.
  • Priority from 0 (highest) to 65,535 (lowest); default 1000. Several routes with the same destination and priority share traffic (ECMP).
  • The default route is used only when no more specific route matches. Removing it doesn't fully isolate the network, because some special paths don't depend on it.
  • Static routes with tags are never exchanged through VPC Network Peering.

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.

ZoneWhat for
PublicVisible on the internet. To use it, the domain registrar must point to the Cloud DNS name servers
PrivateVisible 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)
ForwardingA private zone that sends queries to target servers, for example on-premises DNS over VPN or Interconnect (outbound forwarding)
PeeringA 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
  • To let on-premises hosts resolve private zones, you create an inbound server policy. Forwarding isn't supported for public zones.
  • Combining a public and a private zone with the same name gives you split horizon: different answers depending on whether the query comes from the VPC or the internet.

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
  • Each gateway belongs to one VPC network, one region, and one Cloud Router. Cloud Router only groups the configuration: traffic doesn't pass through it and it doesn't use BGP for this.
  • --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.
  • Traffic to Google APIs uses Private Google Access even if the VM uses Public NAT.
  • Cloud NAT logging is disabled by default.

Connectivity Tests

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.

Exam scenarios

SituationAnswerWhy
A /24 subnet has run out of IP addresses and can't be recreatedgcloud compute networks subnets expand-ip-range --prefix-lengthExpands without interrupting traffic; can't be undone.
A VM with an ephemeral external IP must keep it even if the VM is deletedPromote the ephemeral IP to staticgcloud compute addresses create --addresses=IP.
VMs without external IPs need to download patches from the internetCloud NAT (Public NAT) in the subnet's regionEgress without external IPs; no unsolicited inbound connections.
VMs without external IPs must call the Cloud Storage APIEnable Private Google Access on the subnetReach Google APIs without an external IP.
Resolve internal names only from the VPCCloud DNS private zone authorized for that VPCVisible only from the networks you specify.
Send traffic for 192.168.0.0/16 through an appliance VMStatic route with --next-hop-instanceThe route with the most specific destination wins.
Check why one VM can't reach another without sending real trafficConnectivity TestsAnalyzes configuration and simulates the packet path.
A reserved external IP address is unusedRelease it with gcloud compute addresses deleteAn unassigned static IP is charged at a higher rate.

Common exam traps

❓ 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?

Ready to test "Operating the network"?

Original questions, each with a full explanation.

Start a mock exam