Topic 9 of 11
Section 2.3 of the exam guide starts with creating a VPC with subnets (custom mode, Shared VPC, VPC Network Peering) and continues with VPC firewall rules and Cloud Next Generation Firewall (Cloud NGFW) policies: action, source, destination, targets, protocols and ports, and the use of secure tags and service accounts.
Contents
A virtual version of a physical network, implemented inside Google's production network with Andromeda. VPC networks, along with their routes and firewall rules, are global resources; subnets are regional.
compute.skipDefaultNetworkCreation constraint prevents it.Auto mode
10.128.0.0/9.Custom mode (recommended for production)
You can switch from auto mode to custom mode, but not back.
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/24
PRIVATE, the default) or reserved for Private NAT (PRIVATE_NAT). It generally can't be changed later.| Unusable address | Example in 10.1.2.0/24 |
|---|---|
| Network address (first) | 10.1.2.0 |
| Default gateway (second) | 10.1.2.1 |
| Second-to-last, reserved by Google | 10.1.2.254 |
| Broadcast (last) | 10.1.2.255 |
Google uses the first two and last two addresses of the primary range. All addresses in secondary ranges are usable. The gateway doesn't respond to ping. Expanding a subnet is covered in domain D3.
It connects two VPC networks so their resources communicate over internal IPs, with the same latency and bandwidth as within one network. They can be in the same project, different projects, or different organizations.
Cloud Next Generation Firewall is a distributed firewall with stateful inspection and Layer 7 control, for north-south traffic (entering or leaving the VPC) and east-west traffic (within the VPC). It applies rules to VMs and to certain Envoy-based load balancers.
| Tier | What it includes |
|---|---|
| Essentials | Rules by IP, ports, and protocols. No cost |
| Standard | FQDN objects and threat intelligence |
| Enterprise | Layer 7: intrusion detection and prevention, URL filtering, malware sandbox (preview) |
They belong to a VPC network. Each rule has these components:
| Component | Values |
|---|---|
| Direction | Ingress or egress, from the target's point of view |
| Priority | 0 to 65,535, default 1000. The highest-priority (lowest number) matching rule applies |
| Action | Allow or deny |
| Target | All instances in the network (default), those with a network tag, or those using a service account |
| Source or destination | IP ranges, network tags, or service accounts (source for ingress); IP ranges (destination for egress) |
| Protocols and ports | e.g. tcp:22, tcp:80,443, icmp |
| Logs | Log matching connections (has a cost) |
default-allow-internal (from 10.128.0.0/9), default-allow-ssh (tcp:22), default-allow-rdp (tcp:3389), and default-allow-icmp, all with priority 65534 and editable.gcloud compute firewall-rules create allow-web --network=prod-vpc \ --direction=INGRESS --action=ALLOW --rules=tcp:80,tcp:443 \ --source-ranges=0.0.0.0/0 --target-tags=web --priority=1000
A policy groups several rules so you can update them at once and control who manages them with IAM.
| Type | Scope |
|---|---|
| Hierarchical | Associated with the organization or folders, affecting many VPCs across projects |
| Global network | Every region of one or more VPCs |
| Regional network | One region of a VPC |
| Regional system | Managed by Google when a service needs it; you can only toggle its logging. No cost |
goto_next (continue evaluating at the next level), and apply_security_profile_group (send to Layer 7 inspection).With the default order (AFTER_CLASSIC_FIREWALL):
Hierarchical policies: First the organization's, then the folders', top down. Allow or deny stops evaluation; goto_next moves to the next level.
Regional system policies: Google's own.
VPC firewall rules: The "classic" ones.
Global network policies
Regional network policies
Implied actions: Deny ingress to VMs and allow egress.
With BEFORE_CLASSIC_FIREWALL, global and regional network policies are evaluated before VPC rules. You change it with gcloud compute networks update --network-firewall-policy-enforcement-order. Hierarchical and system policies always come first.
| Situation | Answer | Why |
|---|---|---|
| A production network that will connect to on-premises over VPN | Custom mode VPC | Full control of ranges and no overlap with 10.128.0.0/9. |
| Several teams must use a network managed by the networking team | Shared VPC | Host project and service projects. |
| Connect two VPCs in different organizations with internal IPs | VPC Network Peering | Works across projects and organizations. |
| A peers with B and B with C; A must reach C | Create an A-C peering | Peering isn't transitive. |
| Block SSH from the internet across the whole organization | Hierarchical firewall policy on the organization | Evaluated before everything else. |
| Apply rules to VMs without depending on IPs and without an instance admin changing them | Secure tags in a firewall policy | Governed by IAM. |
| A rule must apply only to the VMs of a specific backend | Target by service account or tag | Instead of every instance in the network. |
| Intrusion inspection and URL filtering | Cloud NGFW Enterprise | Layer 7 capabilities. |
❓ Are subnets global resources?
No. VPC networks are global; subnets are regional.
❓ Can you switch a VPC from custom mode to auto mode?
No. Only from auto mode to custom mode.
❓ What happens to ingress traffic if no rule matches?
It is denied by the implied action. Egress traffic is allowed.
❓ Does a rule with priority 100 beat one with priority 1000?
Yes. The lowest number is the highest priority.
❓ Does peering share firewall rules between networks?
No. It only exchanges routes; each network keeps its own firewall.
❓ Can network tags be used in hierarchical firewall policies?
No. Policies use secure tags; network tags only work in VPC rules.
❓ How many IPs in a primary range are unusable?
Four: the first two and the last two.
Did you get this topic?
Test what you just learned
The security team wants to block SSH from the internet to every VM in the organization, and no project administrator should be able to bypass it with their own rules. What should it configure?
Original questions, each with a full explanation.
Start a mock exam