Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 45 ยท Networking

Hybrid Connectivity, VPN and Peering

Connect networks on Google Cloud: Cloud VPN, Interconnect, VPC peering, Shared VPC and Private Service Connect, with a route reachability checker.

Few organizations live entirely in one network. You may have an office or data center that must talk to your cloud servers, several projects that need to share services, or a partner's network you must reach privately. Google Cloud offers a small set of building blocks for these jobs, and each one answers a slightly different question.

This lesson sorts them out: Cloud VPN and Interconnect link Google Cloud to networks outside it, VPC peering and Shared VPC link networks inside it, and Private Service Connect exposes one service privately to another network. You should know how a VPC network works first, because every option here is about routes and address ranges.

Five ways to connect

Cloud VPN Encrypted tunnels over the public internet.
Interconnect A private physical or partner link.
VPC peering Two VPC networks exchange routes.
Shared VPC Many projects use one central network.

A fifth, Private Service Connect, publishes one service privately.

1 / 2

Cloud VPN

Cloud VPN connects your VPC network to another network through IPsec tunnels that travel over the public internet. The traffic is encrypted, so no one on the path can read it, and you set it up in hours rather than weeks. The type you should choose today is HA VPN ("high availability"): a gateway with two interfaces, each of which can build a tunnel to your side, which allows Google's highest availability commitment when you configure it as documented. Check the current service level agreement for the exact conditions.

A tunnel carries a limited amount of traffic (a few gigabits per second per tunnel), so VPN suits modest traffic, backups, and the first weeks of a migration. Routes across the tunnel are normally learned dynamically. A Cloud Router speaks BGP, the routing protocol of the internet, with your on-premises router: each side announces which address ranges it owns and routes appear on their own. The alternative is static routes you type by hand.

Terminal
# Read-only sketch: names and IP addresses are placeholders.
gcloud compute vpn-gateways create office-gw \
  --network=prod-vpc --region=europe-west1

gcloud compute routers create office-router \
  --network=prod-vpc --region=europe-west1 --asn=65001

You would then create the tunnels and BGP sessions, which need details from your own router (its address, the shared secret and its ASN). A tunnel that shows "established" but passes no traffic is usually a mismatch of address ranges or a firewall rule: check both ends.

Cloud Interconnect

When VPN is too slow or too unpredictable, Cloud Interconnect gives you a private connection that does not use the public internet. It comes in a few flavors:

  • Dedicated Interconnect: you run a physical circuit from your equipment to Google's at a colocation facility. It suits large, steady traffic and requires you to be present in such a facility.
  • Partner Interconnect: a service provider links you to Google. It starts at smaller capacities and suits sites that cannot reach a Google facility.
  • Cross-Cloud Interconnect: a private link between Google Cloud and another cloud provider.

Interconnect gives more bandwidth and steadier latency than VPN, but it takes longer to order and costs more. Note that a plain Interconnect link is not encrypted by itself: if you need encryption on top, you can run HA VPN over it or use the encryption options Google documents for it. A common pattern is Interconnect for the main path with a VPN as the backup.

VPC peering

VPC Network Peering lets two VPC networks exchange routes so that machines in each can reach the other using internal IP addresses. The traffic stays on Google's network and you pay no gateway to run. Both sides must create their half of the peering (it only becomes active when both exist), and each side keeps control of its own firewall rules.

Terminal
# Run in project A, then the mirror command in project B.
gcloud compute networks peerings create a-to-b \
  --network=vpc-a --peer-project=project-b --peer-network=vpc-b

Three rules cause most surprises:

  1. Address ranges cannot overlap. If both networks use 10.0.0.0/16, a route to 10.0.5.7 would be ambiguous, so the peering is refused or the conflicting ranges are not exchanged.
  2. Peering is not transitive. If A is peered with B and B is peered with C, A cannot reach C through B. You must peer A with C directly, or use another design such as a hub with VPN or a shared network.
  3. Each peering is a pair of one-way agreements. Both sides must exist and be active, or nothing flows.

Shared VPC

Peering links separate networks. Shared VPC goes the other way: one host project owns a network, and other service projects attach to it and create their VMs and services inside its subnets. The network team controls subnets, routes and firewall rules in one place, while each application team keeps its own project, quota and billing. Shared VPC requires an organization, and the right to use a subnet is granted with IAM (the Compute Network User role on a subnet or on the host project), which follows the principle of least privilege.

Use Shared VPC when you want central control of networking inside one organization. Use peering when the networks are separate on purpose, for example two different companies or teams who must stay in charge of their own network.

Private Service Connect

Sometimes you do not want to connect whole networks, only to reach one service privately. Private Service Connect (PSC) creates an endpoint with an internal IP address in your network that forwards to a service: either a Google API (so traffic to Cloud Storage or BigQuery stays off the internet) or a service that another team or a vendor has published. The producer exposes a service attachment, and the consumer creates an endpoint to it. Because only the one service is reachable, the two networks can even use overlapping address ranges. This is often the cleanest answer when you offer a service to many customers and cannot coordinate address plans with each of them.

flowchart LR
  A["Office network<br/>192.168.0.0/16"] -- "HA VPN / Interconnect" --> V["prod-vpc<br/>10.0.0.0/16"]
  V -- "VPC peering" --> D["data-vpc<br/>10.1.0.0/16"]
  V -- "PSC endpoint" --> S["Published service"]

A typical hybrid design: external links into a hub VPC, with peering and a private endpoint on the other side.

Stand-in: the overlap rule

The real routing happens inside Google's network. The stand-in below is plain JavaScript that implements one rule you can verify yourself: whether two CIDR ranges overlap. It is the check that decides whether a peering or VPN design can work.

JS Stand-in: do these address ranges overlap?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The second pair overlaps because a /24 fits entirely inside a /16. Overlaps like this are the reason to plan address space for the whole company before you create the first network.

Stand-in: route reachability

This model keeps a list of links between networks, each marked as transitive or not, and answers "can A reach C?". It is not how Google's routing is implemented: real reachability also depends on routes and firewall rules. It does capture the key rule that peering does not chain.

JS Stand-in: peering is not transitive

Press Run (or Ctrl + Enter) to see the console output here.

No output.

vpc-a cannot reach vpc-c until you peer them directly, and the office link does not give the office a path to vpc-b either. In a real design you could advertise routes over a VPN with a Cloud Router, but peered routes are not re-exported by default, so you would need to configure that explicitly.

Choosing quickly

For a small company: start with HA VPN to the office, a single Shared VPC or one VPC, and Private Google Access for services. As traffic grows, add Interconnect. For a platform that serves other organizations, publish with Private Service Connect. Whatever you choose, give every network a distinct, documented address range.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which option encrypts traffic over the public internet between your office and a VPC network?

    Cloud VPN builds IPsec tunnels across the internet. Peering and Shared VPC join networks inside Google Cloud.
  2. 2. VPC A is peered with B, and B is peered with C. What is true?

    VPC peering is not transitive. Traffic does not pass through B to the next network.
  3. 3. What stops two VPC networks from being peered?

    Overlapping address ranges make routes ambiguous. Different projects and regions are fine.
  4. 4. Which feature lets many projects create resources inside one centrally managed network?

    A host project owns the network and service projects attach to it.
  5. 5. You want customers to reach one service privately without coordinating address plans. What fits best?

    PSC exposes one service through an endpoint, so address ranges may even overlap.

Summary

  • Cloud VPN (use HA VPN) and Interconnect link Google Cloud to outside networks; Interconnect is faster and steadier but slower to order, and not encrypted by default.
  • A Cloud Router uses BGP to exchange routes dynamically.
  • VPC peering joins two VPC networks over internal IPs; ranges must not overlap and it is not transitive.
  • Shared VPC puts many projects on one central network inside an organization.
  • Private Service Connect publishes a single service through a private endpoint.

Next: BigQuery Basics