Overview and What You Will Learn
A GCP VPC is a global resource, and in a custom-mode VPC you create the regional subnets yourself instead of getting one in every region. In this lab, you will inspect the default auto-mode VPC, remove it, build a custom-mode VPC with only the subnets you need, prove that VMs in two regions talk over private IPs, and expand a subnet that has outgrown its range.
- Explain the global VPC model compared with AWS and Azure regional networks
- Compare auto-mode and custom-mode VPCs
- Remove the default network safely
- Create subnets in specific regions with non-overlapping ranges
- Expand a subnet's IP range without downtime
Why This Matters in Production
Production projects should use a custom-mode VPC because the default auto-mode VPC places a subnet in every region, and each one must then be covered by your address plan and security reviews. An engineer coming from AWS expects a VPC tied to one region and finds dozens of unrequested subnets in regions the workload will never use. A platform team at a company like Spotify avoids this by deleting the default network and defining only the regions and ranges it has planned.
Core Principles
A single GCP VPC spans all regions, while an AWS VPC or Azure VNet is tied to one region. Subnets are regional inside the VPC, so VMs in different regions of the same VPC talk over private IPs with no peering or VPN. A custom-mode VPC starts empty so you control every range, and subnet ranges inside one VPC can never overlap, even across regions.
10.0.1.0/24"] S2["subnet-us-central1
10.0.2.0/24"] end S1 <-->|private IP| S2 classDef tool fill:#326CE5,color:#FFFFFF classDef app fill:#D1FAE5,color:#1E293B class S1,S2 tool class VM1,VM2 app
| Aspect | Auto-mode VPC | Custom-mode VPC |
|---|---|---|
| Subnets | One per region, created for you | None until you create them |
| IP ranges | Fixed, from 10.128.0.0/9 | Chosen by you |
| Best for | Quick experiments | Production |
RememberPlan the full address space before creating the first subnet. Overlapping ranges block VPC peering and VPN connections later.
Detailed Step-by-Step Practical Lab
- Create a project and look at the default auto-mode VPC:
gcloud projects create mumbai-vpc-lab-2026 --name="VPC Design Lab"gcloud billing projects link mumbai-vpc-lab-2026 \ --billing-account=012345-6789AB-CDEF01gcloud config set project mumbai-vpc-lab-2026gcloud services enable compute.googleapis.com gcloud compute networks subnets list --network=default- Delete the default network. Its firewall rules must go first, and its subnets are removed together with the network because auto-mode subnets cannot be deleted one by one:
gcloud compute firewall-rules list \ --filter="network:default" \ --format="value(name)" | \ xargs -r gcloud compute firewall-rules delete --quiet gcloud compute networks delete default --quiet- Create a custom-mode VPC. It starts with zero subnets:
gcloud compute networks create vpc-prod --subnet-mode=custom- Add only the subnets you actually need:
gcloud compute networks subnets create subnet-asia-south1 \ --network=vpc-prod \ --region=asia-south1 \ --range=10.0.1.0/24 gcloud compute networks subnets create subnet-us-central1 \ --network=vpc-prod \ --region=us-central1 \ --range=10.0.2.0/24- Confirm exactly two subnets exist, not one per region:
gcloud compute networks subnets list --network=vpc-prod- A new custom-mode VPC has no allow rules, so open internal ICMP and SSH through Identity-Aware Proxy (IAP), then start one VM in each region without external IPs:
gcloud compute firewall-rules create vpc-prod-allow-internal-icmp \ --network=vpc-prod \ --allow=icmp \ --source-ranges=10.0.0.0/8 gcloud compute firewall-rules create vpc-prod-allow-iap-ssh \ --network=vpc-prod \ --allow=tcp:22 \ --source-ranges=35.235.240.0/20 gcloud compute instances create mumbai-prod-vm-1 \ --zone=asia-south1-a --machine-type=e2-micro \ --subnet=subnet-asia-south1 --no-address \ --image-family=debian-12 --image-project=debian-cloud gcloud compute instances create iowa-prod-vm-1 \ --zone=us-central1-a --machine-type=e2-micro \ --subnet=subnet-us-central1 --no-address \ --image-family=debian-12 --image-project=debian-cloud- Ping the Iowa VM from the Mumbai VM over its private IP. It works with no peering or VPN because both subnets belong to one global VPC:
IOWA_IP=$(gcloud compute instances describe iowa-prod-vm-1 \ --zone=us-central1-a \ --format="value(networkInterfaces[0].networkIP)") gcloud compute ssh mumbai-prod-vm-1 \ --zone=asia-south1-a \ --tunnel-through-iap \ --command="ping -c 3 $IOWA_IP"- Expand a subnet that is running out of addresses. This is non-disruptive, but the range can only grow and must not overlap another subnet:
# Grow 10.0.1.0/24 to 10.0.0.0/23, which contains the old range.# 10.0.2.0/24 is untouched, so there is no overlap.gcloud compute networks subnets expand-ip-range subnet-asia-south1 \ --region=asia-south1 \ --prefix-length=23 \ --quiet gcloud compute networks subnets describe subnet-asia-south1 \ --region=asia-south1 \ --format="value(ipCidrRange)"- Clean up in reverse order of creation:
gcloud compute instances delete mumbai-prod-vm-1 --zone=asia-south1-a --quietgcloud compute instances delete iowa-prod-vm-1 --zone=us-central1-a --quietgcloud compute firewall-rules delete vpc-prod-allow-internal-icmp --quietgcloud compute firewall-rules delete vpc-prod-allow-iap-ssh --quietgcloud compute networks subnets delete subnet-asia-south1 --region=asia-south1 --quietgcloud compute networks subnets delete subnet-us-central1 --region=us-central1 --quietgcloud compute networks delete vpc-prod --quietgcloud projects delete mumbai-vpc-lab-2026 --quietProduction Best Practices & Common Pitfalls
Common MistakeRunning production on the default auto-mode VPC. It creates a subnet in every region whether you need it or not, and its fixed ranges can collide later when you connect to an on-premises network or another VPC.
TipPlan CIDR ranges with generous headroom and leave gaps between them. A /24 can be expanded later only if the larger range does not collide with a neighboring subnet.
RememberIf you cannot delete the default network, convert it with
gcloud compute networks update default --switch-to-custom-subnet-mode. The conversion is one-way and cannot be reversed.
- Use private IPs across regions. Resources in different regions of one VPC reach each other over internal addresses by default, which is a real convenience of the global model.
- Allocate ranges centrally. Keep one address plan for every VPC, since overlapping ranges block VPC peering and VPN connections later.
- Stop the default network from returning. Set the
compute.skipDefaultNetworkCreationOrganization Policy constraint so new projects start without it. - Create subnets only for regions you use. Each extra subnet is more address space to track and review.
- Remember firewall defaults. A new custom-mode VPC has no allow rules, so add the ingress rules your workloads need.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
gcloud compute networks create --subnet-mode=custom |
Create a custom-mode VPC with no subnets |
gcloud compute networks subnets create |
Add a regional subnet to a VPC |
gcloud compute networks subnets list --network= |
List all subnets in a VPC |
gcloud compute networks subnets expand-ip-range |
Grow a subnet's address range |
gcloud compute networks update --switch-to-custom-subnet-mode |
Convert an auto-mode VPC to custom mode |
gcloud compute firewall-rules list --filter="network:vpc-prod" |
Review firewall rules on the VPC |