How GCP VPC peering builds its routing table
10.0.1.0/24 in us-central1, the spoke VPC automatically gets a route pointing to that CIDR through the peering connection. This happens without any extra configuration.
But subnet routes are not the only routes in a VPC's routing table. There are also custom routes, which fall into two categories:
- Static routes — routes you manually created, like a static route pointing
192.168.0.0/16to a next-hop VPN tunnel. - Dynamic routes — routes learned via Cloud Router's BGP sessions, typically from a Cloud VPN tunnel or a Dedicated/Partner Interconnect VLAN attachment. When your on-prem router advertises
172.16.0.0/12over BGP, Cloud Router installs that as a dynamic route in the hub VPC.
What happens to a packet when the route is missing
172.16.10.5.
- The VM in the spoke VPC constructs a packet with destination
172.16.10.5and hands it to the VPC networking stack. - GCP's software-defined networking layer looks up the effective routes for that VM's VPC network.
- It finds subnet routes for the spoke's own subnets, subnet routes imported from the hub via peering, and possibly a default internet gateway route (
0.0.0.0/0). But no route matching172.16.10.0/24or any parent prefix covering172.16.10.5. - Without a matching route, the packet either hits the default route (and gets sent toward the internet gateway, where it will be dropped because
172.16.10.5is an RFC 1918 address) or gets dropped outright if there is no default route.
Checking effective routes and peering settings
BASH
gcloud compute routes list --filter='network=spoke-vpc'172.16.0.0/12 or whatever your on-prem router advertises). If it is missing, the spoke VPC has no path to on-prem.
To check the peering configuration:
BASH
gcloud compute networks peerings list --network=hub-vpcTEXT
NAME NETWORK PEER_PROJECT PEER_NETWORK IMPORT_CUSTOM_ROUTES EXPORT_CUSTOM_ROUTES STATE STATE_DETAILS
hub-to-spoke hub-vpc spoke-proj spoke-vpc False False ACTIVE [2025-01-15T...]IMPORT_CUSTOM_ROUTES and EXPORT_CUSTOM_ROUTES tell the whole story. If EXPORT_CUSTOM_ROUTES is False on the hub side, the hub is not sharing its custom routes (including the on-prem dynamic routes) with the spoke. If IMPORT_CUSTOM_ROUTES is False on the spoke side, the spoke would not accept them even if offered.
Both sides need the correct setting. The hub must export custom routes, and the spoke must import them.
Enabling custom route exchange on the peering
BASH
gcloud compute networks peerings update hub-to-spoke \
--network=hub-vpc \
--export-custom-routesBASH
gcloud compute networks peerings update spoke-to-hub \
--network=spoke-vpc \
--import-custom-routesNEXT_HOP_VPN_TUNNEL or NEXT_HOP_INTERCONNECT_ATTACHMENT, routed through the peering.
Why GCP defaults to not sharing custom routes
0.0.0.0/0 default route pointing at an on-prem firewall, and the spoke also has its own 0.0.0.0/0 pointing at the internet gateway, importing that route creates ambiguity. GCP resolves this with route priority, but it can cause unexpected traffic paths if you are not paying attention. Keeping custom route exchange off by default forces you to opt in deliberately.
Firewall rules still apply after routes appear
- The hub VPC needs an ingress firewall rule allowing traffic from the spoke's subnet ranges, destined for the VPN tunnel or Interconnect next hop.
- The on-prem firewall needs to allow traffic from the spoke's IP ranges.
- Return traffic from on-prem must also have a route back. If the hub's Cloud Router advertises only the hub's subnets to on-prem, on-prem won't know how to reach the spoke's subnets. You need to configure Cloud Router to also advertise the spoke's subnet ranges to on-prem, either through custom route advertisements on the Cloud Router or by configuring the on-prem router with static routes.
Subnet routes that get exported automatically can also conflict
global dynamic routing mode, Cloud Router's learned routes apply to all regions. If set to regional, they apply only to the region where the Cloud Router sits. This regional scoping also affects what the spoke sees after import: if the spoke has VMs in a different region than the hub's Cloud Router, and the hub uses regional routing mode, those VMs may still not see the on-prem routes even after enabling custom route exchange.
Quick verification sequence
- Confirm the VPN tunnel or Interconnect attachment is up and Cloud Router has learned the on-prem prefixes. Check
gcloud compute routers get-status ROUTER_NAME --region=REGIONon the hub side. - Check the peering config on both sides for
EXPORT_CUSTOM_ROUTES(hub) andIMPORT_CUSTOM_ROUTES(spoke). - After enabling export/import, verify the on-prem route appears in the spoke's route list.
- Check firewall rules on the hub VPC allow transit from spoke CIDRs.
- Verify the on-prem router has return routes to the spoke's subnets, not just the hub's.
- If using regional dynamic routing mode on the hub, confirm the spoke VMs are in the same region as the Cloud Router, or switch to global mode.
