VPC Networks on Google Cloud: Global VPC, Subnets, Routes, Firewall Rules, Private Google Access and Cloud NAT
What Is a VPC on Google Cloud?
A VPC network is your private network inside Google Cloud. A key difference from other clouds: a Google VPC is global. Subnets are regional, and VMs in different regions of the same VPC talk over private IPs across Google's backbone.
text
VPC "prod-vpc" (global)
├─ Subnet app-mumbai 10.10.0.0/20 region asia-south1
├─ Subnet app-singapore 10.20.0.0/20 region asia-southeast1
└─ Routes and firewall rules apply across the whole VPC
Auto Mode vs Custom Mode
| Auto mode | Custom mode | |
|---|---|---|
| Subnets | One per region, created for you from 10.128.0.0/9 | You create the ones you need |
| Use | Quick tests | Production (control IP ranges) |
| Risk | Ranges can overlap with other networks | None if planned |
Delete the default network The
default network has permissive rules. In production, create custom mode VPCs and remove default.
Create a Custom VPC
bash
gcloud compute networks create prod-vpc --subnet-mode=custom
gcloud compute networks subnets create app-mumbai --network=prod-vpc --region=asia-south1 --range=10.10.0.0/20 \
--enable-private-ip-google-access --enable-flow-logs
gcloud compute networks subnets list --network=prod-vpc
- Subnets can be expanded later but not shrunk
- Reserved addresses: first two and last two in each primary range
- Plan ranges so they do not overlap with on-premises or other VPCs you may connect
IP Addresses
| Type | Notes |
|---|---|
| Internal IP | From the subnet range. Free. Used inside the VPC |
| External IP | Public. Ephemeral or reserved static. Charged |
| Alias IP ranges | Extra ranges for containers (used by GKE) |
| IPv6 | Dual-stack subnets supported |
Firewall Rules
- Rules are stateful (replies are allowed automatically) and apply at the VM network interface
- Two implied rules: allow all egress, deny all ingress (lowest priority)
- Each rule has direction, priority (0 to 65535, lower wins), action, targets and source/destination
- Targets can be all instances, network tags or service accounts (service accounts are the more secure choice)
bash
gcloud compute firewall-rules create allow-web --network=prod-vpc --direction=INGRESS --priority=1000 \
--action=ALLOW --rules=tcp:80,tcp:443 --target-tags=web --source-ranges=0.0.0.0/0
gcloud compute firewall-rules create allow-ssh-iap --network=prod-vpc --allow=tcp:22 --source-ranges=35.235.240.0/20 --target-tags=ssh-iap
gcloud compute firewall-rules create deny-db-from-web --network=prod-vpc --direction=EGRESS --action=DENY --rules=tcp:5432 --target-tags=web --priority=900
Tip
35.235.240.0/20 is the range IAP uses to reach VMs for SSH tunnelling.
- Hierarchical firewall policies at organization or folder level apply guardrails everywhere
- Network firewall policies are the modern grouped form and can use FQDNs, geographies and threat intelligence
- Turn on Firewall Rules Logging to see allowed and denied traffic
Routes
- Every VPC has a default route to the internet gateway (0.0.0.0/0) and subnet routes
- Custom static routes and dynamic routes (from Cloud Router with BGP) steer traffic to VPNs, appliances or interconnects
- The most specific route wins
Private Access and Cloud NAT
| Feature | Purpose |
|---|---|
| Private Google Access | VMs without external IPs reach Google APIs (Cloud Storage, BigQuery) over Google's network |
| Cloud NAT | VMs without external IPs make outbound internet connections (updates, external APIs). It is a managed service, not a VM. No inbound connections |
| Private Service Connect | Private endpoints for Google APIs and published services (next lessons) |
bash
gcloud compute routers create nat-router --network=prod-vpc --region=asia-south1
gcloud compute routers nats create nat-config --router=nat-router --region=asia-south1 --auto-allocate-nat-external-ips --nat-all-subnet-ip-ranges
Monitoring the Network
- VPC Flow Logs: samples of traffic per subnet
- Network Intelligence Center: topology, connectivity tests, performance dashboard, firewall insights
- Packet Mirroring for deep inspection
bash
gcloud network-management connectivity-tests create web-to-db --source-instance=projects/my-proj/zones/asia-south1-a/instances/web-1 \
--destination-instance=projects/my-proj/zones/asia-south1-a/instances/db-1 --destination-port=5432 --protocol=TCP
Practice
- Create a custom VPC with subnets in two regions
- Launch a VM without a public IP and reach it through IAP
- Use Cloud NAT so the private VM can run
apt update - Write firewall rules by service account instead of tags
- Run a connectivity test between two VMs
Conclusion
A Google VPC is global with regional subnets. Use custom mode, plan non-overlapping ranges, control traffic with stateful firewall rules, give private VMs Google API access and Cloud NAT, and monitor with flow logs and Network Intelligence Center.
Quick Summary: VPC; modes; create; IPs; firewall; routes; private access; monitoring.

