Overview and What You Will Learn
Use Cloud VPN when the other end of the connection is an on-premises or non-Google network, and use VPC Network Peering when the other end is another VPC. VPN gives you an encrypted tunnel over the internet, while peering gives you private, low-latency routing on Google's backbone.
In this lab, you will:
- Peer two custom VPCs and confirm private connectivity with a real ping
- Add a third VPC and prove that peering is non-transitive
- Review the building blocks of an HA VPN connection to an on-premises network
Why This Matters in Production
Choosing the wrong connectivity model shows up as an outage or an audit finding. A platform team at a company like Grab might peer a shared-services VPC with a prod VPC, then peer prod with an analytics VPC, and expect shared-services to reach analytics. It cannot, because VPC Network Peering is non-transitive, and the team loses hours debugging routes that were never going to exist.
Core Principles
Cloud VPN and VPC Network Peering solve different problems, and the deciding question is what sits on the other side of the link.
over the internet]) P --> P1([Private routing on
Google backbone]) classDef decision fill:#F59E0B,color:#111827 classDef tool fill:#326CE5,color:#FFFFFF classDef result fill:#D1FAE5,color:#1E293B class Q decision class V,P tool class V1,P1 result
A short comparison of the two options:
| Aspect | Cloud VPN | VPC Network Peering |
|---|---|---|
| Connects | On-premises or other cloud to a VPC | Two VPCs (any project or org) |
| Path | Encrypted tunnels over the internet | Google's internal network |
| Transitive | Routes follow your Cloud Router config | No, never |
Detailed Step-by-Step Practical Lab
Use a sandbox project with billing enabled. Replace mumbai-prod-network-lab with your own project ID.
- Set the project and enable the Compute API:
gcloud config set project mumbai-prod-network-labgcloud services enable compute.googleapis.com- Create three custom-mode VPCs with non-overlapping ranges:
for NAME in prod analytics reporting; do gcloud compute networks create vpc-$NAME --subnet-mode=customdone gcloud compute networks subnets create subnet-prod \ --network=vpc-prod --region=asia-south1 --range=10.0.1.0/24gcloud compute networks subnets create subnet-analytics \ --network=vpc-analytics --region=asia-south1 --range=10.1.1.0/24gcloud compute networks subnets create subnet-reporting \ --network=vpc-reporting --region=asia-south1 --range=10.2.1.0/24- Allow ICMP between the lab ranges and SSH through Identity-Aware Proxy. Custom VPCs deny all ingress by default:
for NAME in prod analytics reporting; do gcloud compute firewall-rules create allow-icmp-$NAME \ --network=vpc-$NAME --allow=icmp --source-ranges=10.0.0.0/8 gcloud compute firewall-rules create allow-iap-ssh-$NAME \ --network=vpc-$NAME --allow=tcp:22 --source-ranges=35.235.240.0/20done- Create one small VM in each VPC, without external IPs:
for NAME in prod analytics reporting; do gcloud compute instances create vm-$NAME \ --zone=asia-south1-a --machine-type=e2-micro \ --subnet=subnet-$NAME --no-address \ --image-family=debian-12 --image-project=debian-clouddone- Peer
vpc-prodwithvpc-analytics. Peering must be created from both sides before it becomes active:
gcloud compute networks peerings create peer-prod-to-analytics \ --network=vpc-prod --peer-network=vpc-analyticsgcloud compute networks peerings create peer-analytics-to-prod \ --network=vpc-analytics --peer-network=vpc-prod gcloud compute networks peerings list --network=vpc-prodThe STATE column should read ACTIVE. If it reads INACTIVE, the other side is missing.
- Peer
vpc-analyticswithvpc-reporting, again from both sides:
gcloud compute networks peerings create peer-analytics-to-reporting \ --network=vpc-analytics --peer-network=vpc-reportinggcloud compute networks peerings create peer-reporting-to-analytics \ --network=vpc-reporting --peer-network=vpc-analytics- Collect the internal IPs, then test from
vm-prod:
ANALYTICS_IP=$(gcloud compute instances describe vm-analytics \ --zone=asia-south1-a --format="get(networkInterfaces[0].networkIP)")REPORTING_IP=$(gcloud compute instances describe vm-reporting \ --zone=asia-south1-a --format="get(networkInterfaces[0].networkIP)") gcloud compute ssh vm-prod --zone=asia-south1-a --tunnel-through-iap \ --command="ping -c 3 $ANALYTICS_IP" # Unreachable: prod and reporting are only connected through analyticsgcloud compute ssh vm-prod --zone=asia-south1-a --tunnel-through-iap \ --command="ping -c 3 -W 2 $REPORTING_IP"The first ping succeeds and the second reports 100% packet loss. That is the non-transitive rule in action. Fixing it needs a direct vpc-prod to vpc-reporting peering.
- Review what an on-premises link would need. This block is for reference only and is not run in the lab:
# Reference only: HA VPN to an on-premises router at 203.0.113.10gcloud compute routers create router-mumbai --network=vpc-prod \ --region=asia-south1 --asn=65001gcloud compute vpn-gateways create ha-vpn-mumbai --network=vpc-prod \ --region=asia-south1gcloud compute external-vpn-gateways create onprem-gw \ --interfaces=0=203.0.113.10# Then: create vpn-tunnels (with a shared secret) and BGP sessions on the router- Clean up in dependency order:
gcloud compute instances delete vm-prod vm-analytics vm-reporting \ --zone=asia-south1-a --quiet for NAME in prod analytics reporting; do gcloud compute firewall-rules delete allow-icmp-$NAME allow-iap-ssh-$NAME --quietdone gcloud compute networks peerings delete peer-prod-to-analytics --network=vpc-prod --quietgcloud compute networks peerings delete peer-analytics-to-prod --network=vpc-analytics --quietgcloud compute networks peerings delete peer-analytics-to-reporting --network=vpc-analytics --quietgcloud compute networks peerings delete peer-reporting-to-analytics --network=vpc-reporting --quiet for NAME in prod analytics reporting; do gcloud compute networks subnets delete subnet-$NAME --region=asia-south1 --quiet gcloud compute networks delete vpc-$NAME --quietdoneProduction Best Practices & Common Pitfalls
Common MistakeAssuming peering is transitive. If A peers with B and B peers with C, A still cannot reach C. Create a direct A to C peering, or move to a hub design such as Network Connectivity Center.
TipWhen you need many VPCs or sites talking to each other, use Network Connectivity Center instead of building a growing mesh of individual peerings.
- Plan CIDR ranges before you peer. Peered VPCs cannot have overlapping subnet ranges, and renumbering a live subnet is painful.
- Create peering on both sides. One-sided peering stays
INACTIVEindefinitely and fails silently. - Use HA VPN, not Classic VPN, for production. HA VPN with two tunnels and BGP gives a 99.99% availability SLA when configured correctly.
- Pair VPN with Cloud Interconnect when bandwidth matters. VPN tunnels have per-tunnel throughput limits, and traffic still crosses the public internet.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
gcloud compute networks peerings create |
Create one side of a peering |
gcloud compute networks peerings list --network=NAME |
Check peering state (ACTIVE or INACTIVE) |
gcloud compute routes list --filter="network:vpc-prod" |
Inspect routes imported from peers |
gcloud compute vpn-tunnels list |
Check tunnel status for HA VPN |
gcloud compute routers get-status router-mumbai --region=asia-south1 |
Check BGP session health |