Chapters

Hybrid: VPN and Interconnect

Kadé's office has its own network: staff laptops, warehouse scanners, a file server and a DNS server. This chapter joins that network to kade-vpc privately, so office devices reach GCP on internal IPs and GCP reaches the office back. It covers Cloud VPN in depth, because that is what a business Kadé's size uses, and Interconnect briefly, for when traffic grows.

Growing out · chapter 21 of 26 · 9 min read

Three ways to reach GCP from an office

Builds on6. Kadé's office network29. Tunnels

1 · PER PERSON, OVER THE INTERNETKadé office172.16.0.0/16kade-vpc10.10.0.0/16IAP / Access sign-ineach person signs in; one tool at a time; devices without accounts are left out2 · SITE-TO-SITE VPN, OVER THE INTERNETKadé office172.16.0.0/16kade-vpc10.10.0.0/16IPsec tunnels · whole networks · private IPs both waysencrypted, over the public internet; about 3 Gbps per tunnel3 · INTERCONNECT, A PRIVATE LINKKadé office172.16.0.0/16kade-vpc10.10.0.0/16colocation / partnerphysical fibre into Google; many Gbps; steady latency; not encrypted by default
#OptionHowFitsKadé
1Per person, over the internetIAP for SSH and admin tools (chapter 6), IAP for HTTPS or Cloudflare Access for web apps (chapter 13)People with Google identities, occasional admin workKept for admin access
2Site-to-site VPNAn encrypted tunnel between the office router and GCP, over the internet. Whole networks talk on private IPsDevices that cannot sign in, steady office-to-cloud traffic, modest bandwidthKadé's choice
3InterconnectA private physical link, or a link through a provider, into Google's networkMany gigabits, predictable latency, large data volumesNot needed (section 08)

The hybrid family

#ProductPathBandwidthAvailability SLAEncrypted
1HA VPNIPsec over the internetAbout 3 Gbps per tunnel; add tunnels for more99.99% with two tunnels, one from each gateway interfaceYes (IPsec)
2Classic VPNIPsec over the internet, one interfaceSame per tunnel99.9%Yes
3Dedicated InterconnectYour own 10 or 100 Gbps fibre to a Google colocation facility10-200+ Gbps99.9% or 99.99% with redundant linksNo by default; MACsec or HA VPN over it
4Partner InterconnectThrough a service provider already connected to Google50 Mbps to 50 Gbps99.9% or 99.99%No by default
5Cross-Cloud InterconnectGoogle-managed link to another cloud (AWS, Azure…)10 or 100 Gbps99.9% or 99.99%No by default
Classic VPN is the older product: use HA VPN for anything new. All of them use the same Cloud Router and BGP setup (section 04), so what you learn with HA VPN carries over to Interconnect.

HA VPN: the parts

An HA VPN connection is five GCP resources plus the office router. Click each part to see what it holds and Kadé's value:

GCP · kade-vpc · asia-southeast1HA VPN gatewaykade-havpnif0 · if1Cloud Routerkade-vpn-router · 64512BGP over the tunnelsPeer VPN gateway · kade-office-gwGCP resource: describes 198.51.100.20Kadé office · 172.16.0.0/16Office router198.51.100.20 · ASN 65010IPsec + BGP + MSS clamptunnel 0 · 169.254.0.1 ↔ .0.2tunnel 1 · 169.254.1.1 ↔ .1.2both tunnels: IPsec over the public internet

HA VPN gateway · kade-havpn

Kadé's value
asia-southeast1 · interface 0: 34.124.x.1 · interface 1: 34.124.x.2 (Google-assigned)

Holds: A regional GCP resource with two interfaces, each with its own public IP that Google assigns. It is the GCP end of every tunnel.

Cloud Router and BGP: who learns which routes

Builds on12. Routing and BGP

HA VPN uses dynamic routing: the Cloud Router and the office router run BGP over each tunnel, and each tells the other which ranges it can reach (chapter 4: dynamic routes). Nothing is typed in by hand, and when a tunnel fails its routes disappear by themselves. The important question is what each side advertises, because a range that is not advertised simply has no path.

What if
kade-vpn-router advertises →✓ 10.10.1.0/24 sn-app✓ 10.10.2.0/24 sn-data✓ 10.10.3.0/24 sn-run✓ 10.10.32.0/20 Cloud SQL range✓ 35.199.192.0/19 DNS forwarding← office router advertises✓ 172.16.0.0/16 whole officeinstalled in kade-vpc as dynamicroutes (chapter 4), next hop: thetunnels, priority from BGPtunnel 0 · BGPtunnel 1 · BGP

Office reaches subnets, Cloud SQL, and DNS replies come back

Kadé advertises its subnets plus two ranges that are not subnets: Cloud SQL's 10.10.32.0/20 and Cloud DNS's 35.199.192.0/19. The office advertises its whole 172.16.0.0/16. Each side installs the other's list as routes through the tunnels.

Show as config
kade-vpn-router: advertisement-mode CUSTOM
  groups: ALL_SUBNETS
  ranges: 10.10.32.0/20, 35.199.192.0/19
office router: advertises 172.16.0.0/16
#Kadé advertisesWhyLearned from
1All subnets of kade-vpc (default)Office reaches kade-worker and anything else in a subnetAutomatic
210.10.32.0/20Cloud SQL's private services range is not a subnet of kade-vpc, so it is not advertised by defaultChapter 9
335.199.192.0/19Replies to Cloud DNS forwarding queries (chapter 8) must find their way back over the VPNChapter 8
Adding 2 and 3 means switching the Cloud Router to custom advertisement: "all subnets" plus listed ranges (command 6).

Two tunnels: sharing load and failing over

With two tunnels, there are two ways to use them. BGP decides, through the priority Cloud Router attaches to the routes it advertises and the priority the office router uses:

What if
kade-worker→ 172.16.2.0/24officescanners, file servertunnel 0 · priority 100 · carrying traffictunnel 1 · priority 100 · carrying traffic

kade-vpc's routes to 172.16.0.0/16

  • 172.16.0.0/16 via tunnel 0priority 100ECMP
  • 172.16.0.0/16 via tunnel 1priority 100ECMP

Both tunnels advertise the office route with the same priority, so kade-vpc has two equal routes and shares connections across them (ECMP, chapter 4 example D). Uses both tunnels' bandwidth.

Show as config
office-0: advertised-route-priority 100
office-1: advertised-route-priority 100
→ two equal routes to 172.16.0.0/16 (ECMP)
#SettingDefaultEffect
1BGP keepalive and hold time20 s keepaliveWithout BFD, a silent tunnel failure is noticed after up to about a minute
2BFD (Bidirectional Forwarding Detection)offDetects a dead path in about a second, if the office router supports it
3Advertised route priority (base priority)100Lower wins, the same idea as route priority in chapter 4. Give one tunnel a higher number to make it the backup

MTU over the tunnel

Builds on18. MTU, MSS and fragmentation

IPsec wraps each packet in extra headers before it crosses the internet. The inside packet must therefore be smaller than the outside path allows. Chapter 1.2 promised this would come back:

ONE FULL-SIZE PACKET FROM kade-worker TO THE OFFICEinner packet: TCP data + headers1460 byteswhat the VM sends (VPC MTU)the same inner packet≈ 1534 bytesafter IPsec wraps ithighlighted = IPsec additions: new IP header (20) + ESP header and IV (24) + padding, trailer and auth tag (≈30)1500: typical internet MTU

Cloud VPN handles the outer packet size on Google's side. On the office side, MSS clamping keeps TCP from filling the tunnel with packets that will not fit once wrapped. Header sizes vary with the cipher; these are typical.

#RuleWhy
1Cloud VPN carries inner packets up to 1460 bytesThe same as kade-vpc's default MTU (chapter 1.2), so VMs and the tunnel agree
2Set the office side of the tunnel to the same size, and clamp TCP MSS on the office routerOffice PCs think in 1500-byte packets. Clamping MSS (Google's peer guides suggest values around 1360 to 1420) makes TCP pick smaller segments from the start
3If kade-vpc's MTU is ever raised to 1500 or 8896, the VPN does not followLarge packets to the office would no longer fit through the tunnel
4The symptom of getting it wrongSmall things work (ping, DNS, logins); large transfers or big pages hang. The fundamentals course' "black hole" again

Everything the VPN touches

A tunnel that is up only means packets can travel. Each real flow also needs a route on both sides, a firewall rule, and often DNS. These are Kadé's three flows; switch one piece off to see which flow breaks:

What if
Warehouse scanner172.16.2.31office sidekade-worker10.10.1.20:8443kade-vpcHA VPN tunnels: up

What this flow needs

  • route office → 10.10.1.0/24Cloud Router advertises all subnets
  • route kade-vpc → 172.16.0.0/16learned over BGP
  • firewall on kade-workerkade-warehouse-to-inventory · tcp:8443 from 172.16.2.0/24

Works

Route out: the office learned 10.10.1.0/24 over BGP. Route back: kade-vpc learned 172.16.0.0/16. Firewall: kade-warehouse-to-inventory allows tcp:8443 from 172.16.2.0/24 to sa-kade-worker. All three are needed.

Interconnect, briefly

Interconnect replaces "over the internet" with a private physical path into Google's network. The Cloud Router and BGP part stays exactly as above; the tunnel is replaced by a VLAN attachment on the physical link.

#Consider Interconnect whenDetail
1You need more than a few Gbps steadilyEach VPN tunnel tops out around 3 Gbps
2Latency must be steadyThe internet path a VPN uses changes from hour to hour
3You move a lot of data out of GCPEgress over Interconnect is cheaper per GB than internet egress, which can pay for the port
4Your site is near a Google colocation facility, or a partner serves itDedicated needs your equipment in the facility; Partner works through a provider that is already there
Interconnect traffic is not encrypted by default. Add MACsec on the link, or run HA VPN over the Interconnect, when encryption is required.

Back to Kadé

Commands in this chapter

Commands 1 to 4 are read-only. Commands 5 to 7 change the project; the office router is configured separately, with the same secret, addresses and ASNs.

Are the tunnels up?

  • What it shows: Each tunnel's status and the reason if it is not established.
  • What to look for: ESTABLISHED on both. Other values usually mean a mismatched shared secret or IKE settings.
gcloud compute vpn-tunnels list --filter="region:asia-southeast1" \  --format="table(name,status,detailedStatus,peerIp)"

Are the BGP sessions up, and what was learned?

  • What it shows: Each BGP peer's state, and the routes learned from the office.
  • What to look for: Both peers Established, and 172.16.0.0/16 in the best routes.
gcloud compute routers get-status kade-vpn-router --region=asia-southeast1 \  --format="yaml(result.bgpPeerStatus,result.bestRoutes)"

What does Kadé advertise to the office?

  • What it shows: The Cloud Router's advertisement mode, groups and extra ranges.
  • What to look for: CUSTOM, ALL_SUBNETS, and both extra ranges.
gcloud compute routers describe kade-vpn-router --region=asia-southeast1 \  --format="yaml(bgp)"

Test a full-size packet to the office

  • What it shows: From kade-worker, whether 1460-byte packets cross the tunnel without fragmenting.
  • What to look for: Replies at 1432 bytes of data. If small pings work and this one fails, it is MTU.
ping -c 3 -M do -s 1432 172.16.1.40

Create the gateways (changes the project)

  • What it shows: The HA VPN gateway, and a resource describing the office router.
  • What to look for: The two public IPs GCP assigns to kade-havpn, which go into the office router's config.
gcloud compute vpn-gateways create kade-havpn --network=kade-vpc --region=asia-southeast1gcloud compute external-vpn-gateways create kade-office-gw --interfaces=0=198.51.100.20

Create the router and one tunnel with its BGP session (changes the project)

  • What it shows: The Cloud Router, tunnel 0, and its BGP session. Repeat the last three commands for interface 1 and 169.254.1.0/30.
  • What to look for: Commands 1 and 2 report the tunnel and session up once the office side is configured.
gcloud compute routers create kade-vpn-router --network=kade-vpc \  --region=asia-southeast1 --asn=64512gcloud compute vpn-tunnels create kade-tunnel-0 --region=asia-southeast1 \  --vpn-gateway=kade-havpn --interface=0 \  --peer-external-gateway=kade-office-gw --peer-external-gateway-interface=0 \  --ike-version=2 --shared-secret=REPLACE-WITH-A-LONG-SECRET --router=kade-vpn-routergcloud compute routers add-interface kade-vpn-router --region=asia-southeast1 \  --interface-name=if-tunnel-0 --vpn-tunnel=kade-tunnel-0 --ip-address=169.254.0.1 --mask-length=30gcloud compute routers add-bgp-peer kade-vpn-router --region=asia-southeast1 \  --peer-name=office-0 --interface=if-tunnel-0 \  --peer-ip-address=169.254.0.2 --peer-asn=65010

Advertise the extra ranges (changes the project)

  • What it shows: Switches to custom advertisement: all subnets, plus Cloud SQL's range and Cloud DNS's forwarding range.
  • What to look for: The office router's BGP table now lists both ranges via the tunnels.
gcloud compute routers update kade-vpn-router --region=asia-southeast1 \  --advertisement-mode=CUSTOM --set-advertisement-groups=ALL_SUBNETS \  --set-advertisement-ranges=10.10.32.0/20,35.199.192.0/19

Spotted a mistake, or something unclear? Suggest an edit on GitHub