GCP VPC and Networking
Global VPCs, firewalls and hybrid connectivity
GCP VPCs are global: one network with regional subnets, global routing, firewall rules, Cloud NAT and VPC peering. Interconnect/Cloud VPN link on-prem; private service connect keeps PaaS private.
What you will learn
- Design a global VPC with regional subnets
- Apply firewall rules and Cloud NAT
- Connect VPCs and on-prem with peering/Cloud VPN/Interconnect
GCP VPC is a global virtual network: subnets live in regions, routing is global, firewall rules attach to networks/tags, Cloud NAT gives ephemeral egress, and peering/Cloud VPN/Interconnect stitch networks together.
What is this?
A GCP VPC is a software-defined global network spanning regions: custom subnets per region, global route propagation, and firewall rules (allow/deny by IP, tags, service accounts). Cloud NAT provides managed outbound NAT for private instances. VPC peering connects VPCs transitively as hub-spoke with no route complexity; Cloud VPN (IPsec) and Dedicated/Partner Interconnect connect on-prem data centers. Private Service Connect (and the older network peering) reach Google-managed services privately.
Why do you need it?
- Global routing means two regions share one route graph — simpler than per-region VPCs.
- Tagged firewall rules express 'web tier can talk to app tier' in one rule.
- Cloud NAT removes public-IP-everywhere for egress-heavy workloads.
- Peering avoids gateways; Interconnect provides SLA-bound dedicated bandwidth.
Mental model
A national highway authority
Global VPC
One authority (VPC) manages roads (subnets) across regions with one rulebook (firewall rules). Tolls for private roads (Cloud NAT) let citizens leave the county; agreements with neighboring countries (peering/interconnect) connect the whole map.
How it works
- Create a VPC with regional subnets (auto or custom mode); routes are global.
- Firewall rules: allow/deny by source/target (IP ranges, tags, service accounts), default deny inbound except allow listed.
- Cloud NAT: a static set of egress IPs; instances with no public IP can still reach the internet.
- VPC peering: direct private connectivity between two networks, no gateway, DNS config needed.
- Hybrid: Cloud VPN over the internet, or Interconnect with dedicated circuits; BGP advertisements on both.
A global VPC with hybrid connectivity.
In production
- A multi-region SaaS uses one global VPC: eu and us subnets, each app tier behind a global LB, egress via Cloud NAT.
- An enterprise connects on-prem via two Cloud VPN tunnels + BGP for redundancy.
- A platform team peering hub VPC to each team's VPC for shared services (monitoring, bastion).
Best practices
- Use custom-mode VPCs and plan CIDRs; overlap breaks peering/interconnect.
- Default-denied firewall: open only required ports via tags, not whole subnets.
- Centralize egress with a single Cloud NAT per region and route default via it.
- Prefer peering + Private Service Connect over creating VMs as proxies for PaaS access.
Common mistakes
- Overlapping CIDRs across peered networks — silent route failures.
- Firewall everything-open 'for dev', promoting to prod.
- Tunneling one Cloud VPN tunnel with no failover/BGP redundancy.
- Using public IPs on instances when Cloud NAT would do egress cleanly.
Common issues
Instance with no public IP can't reach the internetNo default route via Cloud NAT in the subnet
Add a 0.0.0.0/0 route with next-hop Cloud NAT and create the NAT gateway.
Peered VPC can't reach the other's servicesOverlapping prefixes or firewall rules missing
Ensure disjoint prefixes and allow the required ports between the two networks' tags.
On-prem to GCP drops periodicallySingle VPN tunnel without BGP redundancy
Add a second tunnel/path and enable BGP failover routing.
Debugging tips
- Traffic blocked? Read effective firewall rules for the instance (gcloud compute firewall-rules list).
- Ping/port fails across peering? Check both sides' prefixes and rules; same-VPC wins over peering.
- NAT issues: check Cloud NAT's SNAT IPs and whether the route to 0.0.0.0/0 exists in the subnet.
- VPN flaps: review tunnel status and BGP session state (established) rather than pinging blindly.
Interview checkpoint
Hands-on lab
- Create a custom VPC with a regional subnet
- Attach firewall rules scoped by tags
- Validate the topology with gcloud or a IaC plan
Build a VPC with Instance Templates and a Firewall (Plan)
30 min · intermediate
Quick quiz
What provides outbound internet access to instances without public IPs on GCP?