VPC Networks, Firewall Rules, and Load Balancing on Google Cloud
A VPC network on Google Cloud is a global, software-defined network whose subnets are regional, whose traffic is filtered by VPC firewall rules and Cloud NGFW policies, and whose applications are exposed through Cloud Load Balancing. In this lesson you will plan and create a custom mode VPC with primary and secondary subnet ranges, share a network across projects with Shared VPC, and connect networks with VPC Network Peering, including how routes cross a peering. You will write ingress and egress rules using actions, priorities, sources, destinations, targets, protocols, and ports, and see how hierarchical and network firewall policies, secure Tags, and service accounts change the picture. You will then connect to on-premises and other clouds with Cloud VPN or Cloud Interconnect, choose and deploy the right load balancer along the global-versus-regional, external-versus-internal, and Application-versus-Network axes, and decide between Premium and Standard Network Service Tiers.
On this page9 sections
- How VPC networks and subnets work
- Shared VPC and VPC Network Peering
- VPC firewall rules: ingress and egress attributes
- Firewall rules for common access paths: IAP, Private Google Access, and health checks
- Cloud NGFW policies, secure Tags, and service accounts
- Establishing connectivity: Cloud VPN, peering, and Cloud Interconnect
- Choosing and deploying load balancers
- Network Service Tiers: Premium vs Standard
- Scenario: networking for a global retail platform
- Create a custom mode VPC with regional subnets, expand a subnet's primary range, and plan secondary ranges for GKE
- Decide between Shared VPC and VPC Network Peering, grant Shared VPC access with least privilege, and route peered traffic to on-premises
- Predict the outcome of VPC firewall rules from priority, tie-breaking, implied rules, and the default network's rules
- Configure firewall rules for IAP TCP forwarding, Private Google Access, and load balancer health checks
- Explain Cloud NGFW policy scope and evaluation order, including goto_next, and target rules with secure Tags and service accounts
- Choose between HA VPN, Classic VPN, Dedicated, Partner, and Cross-Cloud Interconnect, and design HA VPN for the 99.99% SLA
- Select and deploy the right Cloud Load Balancing product and Network Service Tier for a workload
How VPC networks and subnets work
A VPC network is a global resource, while each of its subnets is a regional resource — this inversion of most on-premises models is the single most tested VPC fact. One VPC can contain subnets in every Google Cloud region, and instances in different regions on the same VPC communicate over internal IPs across Google's private backbone without any gateways or extra configuration. Because a subnet spans its whole region, VMs in every zone of that region can use the same subnet: you add a subnet only when you need a new region (or a separate range), never per zone.
VPCs come in two subnet modes. An auto mode VPC automatically creates one subnet per region from the fixed block 10.128.0.0/9, and new subnets appear as Google opens new regions. A custom mode VPC starts with no subnets; you create each one deliberately, choosing its region and its primary IPv4 range. Production guidance is clear: use custom mode. Every auto mode network uses the same ranges, so two auto mode networks can never be peered with each other, and the block can collide with on-premises addressing; you also cannot control where subnets exist. You can convert an auto mode VPC to custom mode (its existing subnets keep their ranges), but never the reverse — and conversion does not fix an overlap, so resolving one means rebuilding a network in custom mode with unique ranges.
Creating a custom mode network and a subnet looks like this:
gcloud compute networks create prod-vpc --subnet-mode=custom
gcloud compute networks subnets create web-subnet \
--network=prod-vpc --region=us-central1 \
--range=10.10.0.0/24Primary ranges, expansion, and secondary ranges
A VM's primary internal IP address always comes from its subnet's primary range. When a subnet runs out of addresses you can expand the primary range in place, for example from /24 to /23:
gcloud compute networks subnets expand-ip-range web-subnet \
--region=us-central1 --prefix-length=23Expansion is non-disruptive — existing VMs keep their addresses and are not recreated — but it is one-way: you can never shrink a range afterwards, and the larger range must not overlap any other subnet in the network (or in peered networks). Leave growth room without being wasteful.
Subnets can also carry secondary IPv4 ranges. These supply alias IP addresses for things running on a VM, such as containers; they do not provide VMs' primary addresses, so adding a secondary range does not help a subnet that has run out of room for new VMs. Their best-known consumer is a VPC-native GKE cluster: nodes take their addresses from the subnet's primary range, Pods from one secondary range and Services from another secondary range of the same subnet (newer GKE versions can instead allocate Service addresses from a Google-managed range if you do not name one). If GKE is in your design, plan those ranges up front so they do not overlap anything you will connect later.
VPC firewall rules: ingress and egress attributes
VPC firewall rules filter connections to and from workloads, and every rule is defined by the same set of attributes: a direction (ingress or egress), an action (allow or deny), a priority (0 to 65535, where a lower number wins), a source (for ingress) or destination (for egress), a set of targets the rule applies to, and the protocols and ports it matches. Rules are stateful: once a connection is allowed in one direction, its return traffic is automatically allowed — so an egress deny-all does not break responses to inbound connections an ingress rule already allowed.
How rules are evaluated
For each connection, the matching rule with the lowest priority number decides the outcome. If an allow rule and a deny rule both match at the same priority, the deny wins. Nothing else breaks ties: how specific a rule's source, ports, or targets are, and the order in which rules were created, have no effect. So a broad deny at priority 1000 blocks traffic that a narrow allow at priority 1000 also matches; to let the allow win, give it a lower number.
Implied rules and the default network
Every VPC has two implied rules you cannot delete: allow all egress and deny all ingress, both at the lowest priority (65535). Instances can reach out by default, but nothing can reach in until you write an allow rule. A new custom mode network has only these. The default network, created with every new project unless an organization policy prevents it, also gets prepopulated ingress rules at priority 65534:
| Rule | Allows | From |
|---|---|---|
default-allow-internal | All protocols and ports | 10.128.0.0/9 (the auto mode block) |
default-allow-ssh | tcp:22 | 0.0.0.0/0 |
default-allow-rdp | tcp:3389 | 0.0.0.0/0 |
default-allow-icmp | ICMP | 0.0.0.0/0 |
These apply to every instance in the network. HTTP and HTTPS are not open by default: ticking the Allow HTTP or HTTPS traffic boxes when creating a VM in the console adds the http-server or https-server network tag and creates a matching rule that targets only VMs with that tag. Internet-wide SSH and RDP are one more reason production uses custom mode networks where you author every rule.
Sources and targets
Ingress sources can be IP ranges, source network tags, or source service accounts; targets can be all instances in the network, instances with a target tag, or instances running as a target service account. A network tag is a plain string that anyone allowed to edit an instance can add, so a tag-targeted rule can be extended to an unrelated VM by whoever edits it. A service account target is harder to subvert: changing a VM's service account requires stopping the VM and holding IAM permission to use that account. VPC firewall rules support network tags and service accounts but not secure Tags — those belong to Cloud NGFW policies (next sections). A classic pattern:
gcloud compute firewall-rules create allow-web-ingress \
--network=prod-vpc --direction=INGRESS --action=ALLOW \
--rules=tcp:443 --source-ranges=0.0.0.0/0 \
--target-tags=web-serverTo troubleshoot or audit, enable Firewall Rules Logging on a rule and inspect matches in Cloud Logging. When traffic is unexpectedly blocked or allowed, list every rule that matches it and compare priorities — and remember that hierarchical firewall policies can decide traffic before any VPC rule is consulted.
Firewall rules for common access paths: IAP, Private Google Access, and health checks
Three access paths come up constantly, and each needs specific rules or settings beyond the implied ones.
SSH through Identity-Aware Proxy
IAP TCP forwarding lets administrators SSH or RDP to VMs that have no external IP address, without opening those ports to the internet. Two things are required: an ingress firewall rule allowing the port (for example tcp:22) from IAP's forwarding range 35.235.240.0/20 to the target VMs, and the IAP-secured Tunnel User role (roles/iap.tunnelResourceAccessor) for the administrators on the project or the specific VMs. Users still need the usual permission to log in to the VM, such as an OS Login role. Connect with gcloud compute ssh VM_NAME --tunnel-through-iap. No external IP, Cloud NAT, or bastion host is involved.
Private Google Access and egress rules
Private Google Access lets VMs that have only internal IP addresses reach Google APIs and services such as Cloud Storage. It is a per-subnet setting, so two subnets of the same network can behave differently; VMs with external IPs do not need it.
gcloud compute networks subnets update batch-subnet \
--region=us-central1 --enable-private-ip-google-accessTwo conditions often trip people up. First, the network needs a route to the Google API destinations whose next hop is the default internet gateway; the default 0.0.0.0/0 route provides this, so if you delete it you must add custom routes (next hop default internet gateway) for the destinations your VMs actually use. With the default domain names, *.googleapis.com resolves to Google's public API addresses, so those ranges need the route. To use the smaller private.googleapis.com (199.36.153.8/30) or restricted.googleapis.com (199.36.153.4/30) ranges instead, you also configure DNS, typically a Cloud DNS private zone, so that *.googleapis.com resolves to that range; a route alone does nothing if names still resolve to the public addresses. The traffic still stays on Google's network. Second, API traffic is ordinary egress and still obeys egress firewall rules. To block the internet but keep Google APIs, allow egress to the Google API ranges at a lower priority number than an egress rule that denies 0.0.0.0/0. The reverse order denies everything.
Load balancer health checks and proxies
Google Cloud health check probes come from 35.191.0.0/16 and 130.211.0.0/22, so backends behind most load balancers need an ingress rule allowing those ranges on the serving port. Proxy-based regional load balancers also need a rule allowing their proxy-only subnet (see Choosing and deploying load balancers).
Establishing connectivity: Cloud VPN, peering, and Cloud Interconnect
Choosing a connectivity product comes down to what you are connecting and how much private, reliable bandwidth you need. Cloud VPN sends IPsec-encrypted traffic over the public internet. It is quick to set up and cheap, but throughput is bounded per tunnel and latency depends on the internet.
HA VPN and the 99.99% SLA
HA VPN is a regional gateway with two interfaces, each with its own external IP address. It uses dynamic routing only: a Cloud Router runs BGP sessions over the tunnels to exchange routes. HA VPN carries a 99.99% availability SLA on the Google Cloud side when both interfaces have a tunnel to the peer. The peer can be two devices, one device with two IP addresses, or even a single device with a single public IP address — in that last topology each HA VPN interface runs a tunnel to the same peer IP, and the Google Cloud side still qualifies for 99.99% (the peer device itself remains a single point of failure on your side). A gateway with only one interface's tunnel configured gets no 99.99% SLA. Classic VPN, the older single-interface gateway, has a 99.9% SLA.
Cloud Interconnect
Cloud Interconnect provides private connectivity that does not traverse the public internet, with availability SLAs when built with redundant connections. There are three options:
- Dedicated Interconnect: your own physical circuits between your router and Google's network in a colocation facility where Google has a presence. Circuits are 10, 100, or 400 Gbps, and you can bundle several for more capacity.
- Partner Interconnect: reach Google through a supported service provider, with capacities from 50 Mbps to 50 Gbps per attachment. Choose it when you cannot meet Google in a colocation facility or need less than a full circuit.
- Cross-Cloud Interconnect: dedicated physical links between Google Cloud and another cloud provider (such as AWS, Microsoft Azure, or Oracle Cloud Infrastructure), for private multicloud traffic.
Traffic on Interconnect is not encrypted by default. Questions sometimes test this.
VPC Network Peering is different in kind: it connects two VPC networks inside Google Cloud, not a VPC to an on-premises site. A peered spoke can still reach on-premises through a hub's VPN or Interconnect by exchanging custom routes (see Shared VPC and VPC Network Peering).
| Option | Connects | Path | Capacity | Best for |
|---|---|---|---|---|
| Cloud VPN (HA VPN) | On-premises or other cloud to VPC | Encrypted IPsec over the internet | Per-tunnel limits; add tunnels to scale | Fast setup, lower cost, moderate bandwidth, 99.99% SLA |
| Dedicated Interconnect | On-premises to VPC | Private circuits at a colocation facility | 10, 100, or 400 Gbps per circuit | High, consistent bandwidth and low latency |
| Partner Interconnect | On-premises to VPC via provider | Private connection through a partner | 50 Mbps to 50 Gbps | Private connectivity without colocation presence |
| Cross-Cloud Interconnect | Another cloud provider to VPC | Dedicated physical links | Dedicated circuits | Private, high-bandwidth multicloud |
| VPC Network Peering | VPC to VPC | Google internal network | No tunnel bottleneck | Private internal traffic between two VPCs |
A common pattern: start with HA VPN for speed of delivery, then add Interconnect as bandwidth needs grow. The two can run side by side, with VPN as an encrypted backup path.
Choosing and deploying load balancers
Pick a Cloud Load Balancing product by answering three questions in order: what layer is the traffic (HTTP and HTTPS mean an Application Load Balancer; TCP, UDP, or other IP protocols mean a Network Load Balancer), who are the clients (internet-facing means external; clients inside your VPC or connected networks mean internal), and what scope do you need (one anycast IP serving backends in many regions means global; a single region means regional).
Application Load Balancers are proxy-based Layer 7 balancers: they terminate TLS and route requests with a URL map by host name and path to different backend services. The global external Application Load Balancer serves worldwide users from a single anycast IP that sends each client to the nearest Google edge with healthy backend capacity, and integrates with Google Cloud Armor and Cloud CDN. Cloud CDN works only with the global external Application Load Balancer and the classic Application Load Balancer. Regional external and internal variants cover single-region and private HTTP(S) services.
Network Load Balancers come in two families. Proxy Network Load Balancers terminate TCP (optionally with TLS) at the proxy and open a new connection to backends. The global external proxy Network Load Balancer gives a non-HTTP TCP service one anycast IP and terminates connections at the edge closest to each client. Passthrough Network Load Balancers forward packets without terminating the connection, preserving the client source IP, and support protocols beyond TCP such as UDP. Passthrough balancers are regional.
Which load balancers show the client's IP?
Proxy-based load balancers (all Application Load Balancers and proxy Network Load Balancers) open their own connection to the backend, so the backend sees the proxy's address as the packet source. The client IP is passed along in the X-Forwarded-For HTTP header (Application Load Balancers) or in an optional PROXY protocol header (proxy Network Load Balancers). Only passthrough Network Load Balancers deliver packets whose source address is the original client.
| Requirement | Choose |
|---|---|
| HTTPS app, users worldwide, one IP, CDN and WAF | Global external Application Load Balancer |
| HTTPS app for one region or jurisdiction | Regional external Application Load Balancer |
| Internal microservice traffic over HTTP, path-based routing | Internal Application Load Balancer |
| Global TCP or TLS service, non-HTTP | Global external proxy Network Load Balancer |
| UDP traffic, or client IP must appear as the packet source | External passthrough Network Load Balancer |
| Internal TCP or UDP within the VPC | Internal passthrough Network Load Balancer |
Deploying one
Deployment uses the same skeleton for every type: create a health check, a backend service pointing at instance groups or network endpoint groups, any Layer 7 routing configuration (URL map and target proxy), and a forwarding rule that holds the IP address. Backends need an ingress firewall rule for the health-check ranges 35.191.0.0/16 and 130.211.0.0/22.
Regional proxy-based load balancers, including the regional internal Application Load Balancer, also need a proxy-only subnet. This is a dedicated subnet in the same region and VPC network, created with purpose REGIONAL_MANAGED_PROXY, and the load balancer's proxies draw their addresses from it. Two consequences follow. Backends see connections from the proxy-only range, so they need an ingress allow rule from that range on the serving port, in addition to the health-check rule. And the load balancer's own forwarding-rule IP comes from a regular subnet, never the proxy-only subnet.
gcloud compute networks subnets create proxy-only-us-east1 \
--purpose=REGIONAL_MANAGED_PROXY --role=ACTIVE \
--network=prod-vpc --region=us-east1 --range=10.129.0.0/23Scenario: networking for a global retail platform
Put the pieces together. A retailer runs its storefront on Google Cloud: web and API tiers on managed instance groups in us-central1 and europe-west1, a payments service that must stay private, an on-premises warehouse system that needs steady private connectivity today and roughly 5 Gbps within a year, and three application teams in separate projects under one organization.
The network team creates a custom mode VPC in a host project with non-overlapping subnets in both regions, plus GKE secondary ranges reserved for a future cluster, and enables Shared VPC. Each team gets Compute Network User only on the subnets it should use. Traffic policy lives in a global network firewall policy: an ingress rule allows tcp:443 from the internet to workloads bound to the secure Tag role=web, a second rule allows the web tier to reach the payments backends only via their service account identity, and an organization-level hierarchical policy denies all RDP from the internet everywhere. Administrators reach VMs through IAP TCP forwarding instead of public SSH.
Users worldwide hit a global external Application Load Balancer on Premium Tier — one anycast IP, Cloud CDN for product images, Cloud Armor in front. The payments service sits behind an internal Application Load Balancer with its proxy-only subnet, unreachable from outside the VPC. For the warehouse, the team ships HA VPN with BGP over Cloud Router this quarter for the 99.99% SLA, and orders Partner Interconnect at 5 Gbps for the bandwidth milestone, keeping the VPN as an encrypted failover path. Every choice here maps to a decision rule from this lesson.
Tip. Expect scenario questions that make you choose between custom and auto mode, Shared VPC and VPC Network Peering, and Cloud VPN, Partner, Dedicated and Cross-Cloud Interconnect from bandwidth, SLA, colocation and organizational clues. Questions also test subnet expansion, secondary ranges for GKE, least-privilege Network User grants, and how routes cross a peering. Firewall questions hinge on priority and deny-wins ties, implied and default-network rules, stateful return traffic, tag versus service-account targets, and the access paths for IAP SSH, Private Google Access and health checks. NGFW questions test policy scope, evaluation order and goto_next, and secure Tags. Load balancing questions give you the traffic type, client location, scope and client-IP needs and expect the matching product and its prerequisites, with Premium versus Standard Tier as a frequent twist.
- VPC networks are global and subnets are regional; custom mode is the production choice because every auto mode network uses the same 10.128.0.0/9 ranges and cannot be peered with another.
- A subnet's primary range can be expanded in place without disruption but never shrunk; secondary ranges supply alias IPs, such as GKE Pod and Service ranges, not VM primary addresses.
- Shared VPC shares one network across projects in one organization, with Compute Network User granted in the host project on the project or on individual subnets; VPC Network Peering is non-transitive, forbids overlapping ranges, and exchanges custom routes only when exported and imported.
- VPC firewall rules are stateful; the lowest priority number wins, a deny wins an equal-priority tie, and implied rules deny all ingress and allow all egress.
- IAP SSH needs ingress from 35.235.240.0/20 plus the IAP-secured Tunnel User role; Private Google Access is per subnet and still obeys egress firewall rules.
- Hierarchical firewall policies attach to the organization or folders and are evaluated first; an allow or deny ends evaluation, while goto_next passes the decision down. Secure Tags work in NGFW policies, not VPC firewall rules.
- HA VPN gives a 99.99% SLA when both interfaces have tunnels, even to one peer IP; Classic VPN gives 99.9%. Dedicated Interconnect offers 10, 100, or 400 Gbps circuits, Partner Interconnect 50 Mbps to 50 Gbps, and Cross-Cloud Interconnect links to other clouds.
- Choose load balancers by layer, client location, and scope; only passthrough Network Load Balancers show the client IP as the packet source, and regional proxy load balancers need a proxy-only subnet. Global load balancing requires Premium Tier.
Frequently asked questions
When should I use a custom mode VPC instead of auto mode?
Use custom mode for anything beyond experimentation. An auto mode network creates a subnet in every region from the fixed 10.128.0.0/9 block, which is identical in every auto mode network, so two auto mode networks cannot be peered and the block may clash with on-premises addresses. Custom mode gives you full control over subnet regions and IP ranges. You can convert auto mode to custom mode, but never back, and conversion keeps the existing ranges.
Is VPC Network Peering transitive?
No. If network A peers with B and B peers with C, A cannot reach C through B, because routes learned from one peering are not re-exported to another. Each pair of networks that needs to communicate must have its own peering, and their subnet ranges must not overlap. To reach on-premises through a peered hub, the hub must export custom routes, the spoke must import them, and the hub's Cloud Router must advertise the spoke's ranges.
How are firewall rules evaluated when several rules or policies match?
Within a network's VPC firewall rules, the matching rule with the lowest priority number wins; if an allow and a deny share a priority, the deny wins, and neither specificity nor creation order breaks the tie. Across Cloud NGFW levels, hierarchical firewall policies go first (the organization's, then each folder's from the top down); by default (AFTER_CLASSIC_FIREWALL) the VPC firewall rules come next, then the global and regional network firewall policies, while BEFORE_CLASSIC_FIREWALL moves the network policies ahead of the VPC rules. At any level a matching allow or deny is final; a goto_next rule, or no match, passes the decision to the next level, and the implied rules apply last. Return traffic for an allowed connection is always permitted because rules are stateful.
What is the difference between secure Tags and network tags in firewall rules?
Network tags are plain strings anyone with permission to edit an instance can attach, so they carry no access control, and they are what VPC firewall rules use. Secure Tags are Resource Manager resources governed by IAM: creating a tag and binding it to a VM each require explicit permissions. Hierarchical, global, and regional network firewall policies support secure Tags, which stops an instance owner from quietly moving a workload into a permissive firewall scope.
Why can't my internal-only VMs reach Cloud Storage?
VMs without external IP addresses reach Google APIs only through Private Google Access, which is enabled per subnet, so check the subnet the VMs use. The network also needs a route to the Google API ranges through the default internet gateway; the default route provides this, so deleting it requires a custom route. Finally, egress firewall rules apply to this traffic, so an egress deny-all must be outranked by an allow rule for the Google API ranges.
How do I choose between Cloud VPN and Cloud Interconnect?
Choose HA VPN when you need connectivity quickly, traffic must be encrypted over the internet, and per-tunnel bandwidth is acceptable; it carries a 99.99% SLA when both gateway interfaces have tunnels and routes are exchanged over BGP by Cloud Router. Choose Dedicated Interconnect for 10, 100, or 400 Gbps private circuits if you can meet Google in a colocation facility, Partner Interconnect for 50 Mbps to 50 Gbps through a service provider, or Cross-Cloud Interconnect to link to another cloud provider.
Which load balancer should I pick for a global HTTPS application?
The global external Application Load Balancer. It gives you a single anycast IP address, sends each user to the nearest Google edge with healthy backend capacity, terminates TLS, routes by host and path with URL maps, and integrates with Cloud CDN and Google Cloud Armor. It requires Premium Network Service Tier; on Standard Tier you are limited to regional load balancers.
When does Standard Network Service Tier make sense?
Standard Tier makes sense when cost matters more than latency consistency and the workload is regional: bulk data egress, batch jobs, or a service whose users sit close to its region. Standard Tier hands traffic to the public internet near the hosting region and prices egress lower, but it cannot serve global anycast IP addresses or global external load balancers; Premium Tier is the default and is required for those.
Source
This lesson covers the "Planning and implementing a cloud solution" domain of the official ACE exam guide. Vendors revise their guides — check the source for the current version.
- Google Cloud Associate Cloud Engineer exam guide — Google Cloud
Sign up free to mark lessons complete, bookmark topics and track your exam readiness.