Prepare and test your skills

Prepare and test your skills

VPC and Subnet Configuration is the setup of private networks and regional address space for Google Cloud resources. A Virtual Private Cloud (VPC) (opens in a new tab) network is a private network that holds cloud resources and controls how they connect to each other and to other networks. A subnet is a section of a VPC network that lives in one region and provides IP addresses to resources in that region. Every workload that needs private connectivity, including Private Service Connect (opens in a new tab) endpoints, depends on a VPC network and a subnet for its IP address.
A VPC network is the top-level container for private connectivity, and each subnet inside the VPC network belongs to a single region. A service connection policy authorizes a managed service to create connections in a specific combination of service class, region, and VPC network, with a maximum of one policy for each combination. When a policy is configured, one or more subnets are selected, and IP addresses for the endpoints created through the policy are allocated from those subnets. The same subnet can be reused in multiple connection policies when the policies share the same region.
Subnets provide regional IP capacity, so connectivity that spans regions needs subnet capacity in each region. For example, to automate connectivity for two services in three different regions, six policies are needed, with a minimum of three subnets — one for each region. The stack type of a subnet affects the possible IP version of endpoints that can be deployed from it. A subnet with an internal IPv6 address range is required when an endpoint needs an IPv6 address.
After a service connection policy is created, only its subnets, connection limit, and service instance scope can be updated. If other fields need to change, the policy must be deleted and a new one created. This lifecycle keeps the link between a region, a VPC network, and its IP capacity clear and prevents accidental changes to the authorized service.
An endpoint connects to a subnet and receives an IP address from that subnet's range. For IPv4, reserving a static IP address is optional, and an address can be allocated automatically from the subnetwork if none is specified. For IPv6, reserving a static IP address is required, and the address uses a /96 IPv6 range from the subnet.
The endpoint must be created in the same region that contains the service producer's service attachment. By default the endpoint is available to resources in its own region, and the --enable-global-access flag makes the endpoint available to resources in other regions. This relationship means traffic flows from regional resources to the endpoint IP, and then to the target service.
Exam tip: A static IP reservation is optional for IPv4 endpoints but required for IPv6 endpoints.
Shared VPC separates network ownership from workload ownership by keeping the VPC network and subnets in a host project while workloads and endpoints live in service projects. An endpoint can be created in a service project that uses an IP address from a subnet in the host project, so the host project controls the network and IP ranges while the service project uses them. The endpoint configuration names both sides of this dependency: the VPC network in the host project and the subnet in the host project that supplies the address.
This setup depends on identity and access management (IAM) roles on both projects:
roles/compute.networkAdmin) on the service projectroles/compute.networkUser) on the host project, which provides compute.networks.use and compute.subnetworks.useroles/dns.admin) on the projectFirewall Rules and Traffic Management is the practice of controlling which packets can enter, leave, or move inside a Virtual Private Cloud (VPC) (opens in a new tab) network. Every VPC network acts as a distributed firewall, so rules are defined at the VPC level but enforced on each virtual machine (VM) instance. Traffic between two VMs in the same network is still checked, and communication succeeds only when firewall rules permit it.
Ingress and egress control in a VPC network starts with two implied rules that exist in every network. VPC firewall rules let you allow or deny connections to or from VMs, and Google Cloud always enforces enabled rules regardless of the VM configuration or operating system, even if the VM has not started. Routes govern traffic leaving an instance, while forwarding rules direct traffic to a resource based on IP address, protocol, and port.
| Direction | Implied behavior |
|---|---|
| Ingress | Block all incoming connections |
| Egress | Allow all outgoing connections |
A custom VPC network denies all ingress by default, so VMs in different subnets cannot communicate until you add an allow rule. The default network is an exception because it includes additional rules, including the default-allow-internal rule, which permits communication among instances in that network.
Exam tip: A custom network blocks ingress until you create a higher-priority ingress allow rule, while the default network already allows internal VM-to-VM traffic.
Network tags and service accounts are selectors that limit which VMs a firewall rule applies to. Firewall rules are defined at the VPC level and can be scoped in three ways:
This targeting creates granular security boundaries because a rule only opens traffic for its matched sources and destinations. You can think of VPC firewall rules as existing not only between your instances and other networks, but also between individual instances within the same VPC network.
Rule priority and consolidation determine which VMs can talk when many rules overlap and how efficiently those rules run. In a custom network you must explicitly create higher-priority ingress firewall rules to allow instance-to-instance communication, and a global network firewall policy can allow ingress from a specific subnet IP range. Only a certain number of rules can be programmed on any VM, so combining ports and addresses into fewer rules saves capacity.
For example, if all VMs need 10 ingress TCP ports open, one rule that includes all 10 ports is more efficient than 10 separate single-port rules. Limiting internet access to only the resources that need it also reduces the number of exceptions you must manage, since VMs with only private internal addresses can still reach many Google APIs through Private Service Connect or Private Google Access.
Cloud Next Generation Firewall (Cloud NGFW) (opens in a new tab) provides a stateful firewall that is horizontally scalable and applied to each VM in a distributed manner. A global network firewall policy attaches to the VPC network and can allow egress to any destination, allow ingress between subnets, and enable logging for visibility. Hierarchical firewall policies extend the same allow-or-deny model to an organization or folder, so administrators can enforce consistent rules in one place.
Higher-level hierarchical rules cannot be overridden by lower-level rules, but a higher-level rule can use a goto_next action to delegate evaluation to lower-level policies or VPC firewall rules. When native rules are not enough, traffic is typically routed to third-party appliance VMs by specifying routes with the same priority to distribute traffic using a 5-tuple hash, or with different priorities to create a redundant path. For high scale, push controls to endpoints by hardening VMs and using Google Cloud firewall rules, because inserting multi-interface appliance VMs can hit project-level quota limits and create a single chokepoint that works against the horizontal scalability of the VPC network.
IP Addressing and Name Resolution controls how resources find and reach each other inside and outside a network. A Virtual Private Cloud (VPC) (opens in a new tab) assigns IP addresses to resources such as virtual machines, containers, and load balancer forwarding rules, while Cloud DNS (opens in a new tab) translates human-readable domain names into those IP addresses. Together, reserved static addresses and DNS zones provide stable connectivity that survives restarts and recreations of resources.
Internal and external IP addresses in a VPC network define whether communication stays private or reaches the public internet. An internal IP address comes from the IP range of the subnet where the resource resides, and resources in the same VPC network can communicate through internal addresses when firewall rules permit. An external IP address is a public, internet-routable address assigned to a virtual machine interface, a forwarding rule for a load balancer, or a gateway.
Each Compute Engine virtual machine interface can have one primary internal IP address, one external IP address, and one or more secondary internal addresses called alias IP ranges. Alias IP ranges let multiple services on one virtual machine each use a different internal address, and the VPC network forwards packets destined for a service to the correct virtual machine. Resources with only an internal address remain isolated from the internet but can still reach many Google APIs through Private Google Access or Private Service Connect. Traffic leaving an instance follows VPC routes, while traffic arriving to a Google Cloud resource is directed by a forwarding rule based on IP address, protocol, and port.
Static and ephemeral addresses differ in whether the address persists after the resource stops or is deleted. A static internal IP address is reserved in advance and stays assigned to a project until it is explicitly released, so the same address can be reused even if the virtual machine is deleted and recreated. An ephemeral internal IP address is assigned automatically at creation time and is released back to the subnet pool when the resource is deleted. For reliable connectivity, reserve a static address for servers, databases, and DNS targets that other systems must always reach at the same address.
A static internal address is obtained in one of two ways: reserve the address first and then specify it when creating the instance, or create the instance with an ephemeral address and then promote that in-use address to static. The reservation depends on the subnet, because the address must come from that subnet's range and cannot overlap another assignment. Releasing an unused static address returns it to the pool for future use.
| Address type | Persistence | Choose when |
|---|---|---|
| Static internal | Reserved until explicitly released; survives VM delete and recreate | The workload needs a fixed private address for firewall rules, DNS records, or application configuration |
| Ephemeral internal | Assigned automatically; released when the resource is deleted | The workload needs temporary private connectivity and does not require a stable address |
| Static external | Reserved until explicitly released | An internet-facing service needs a stable public address for DNS or client allowlists |
Exam tip: A static internal address stays with your project after its VM is deleted, while an ephemeral address does not; public Cloud DNS zones must be authoritative and do not support DNS forwarding.
Cloud DNS zones for name resolution are containers that hold DNS records and control who can query them. When a virtual machine needs to reach another system by name, the DNS query flows from the virtual machine to the Cloud DNS resolver, which looks up the matching zone and returns the IP address. Private zones are visible only to authorized VPC networks, while public zones are visible on the internet. Using private zones for internal names keeps internal addresses hidden from the public while giving VPC resources consistent, reliable lookup.
Common Cloud DNS zone types serve different lookup needs:
DNS forwarding between a VPC network and an on-premises network lets each side resolve names hosted on the other side. Inbound forwarding lets on-premises hosts send queries through Cloud VPN or Cloud Interconnect to a Cloud DNS inbound forwarder to resolve records for Google Cloud resources. Outbound forwarding lets VMs in the VPC network send queries to chosen name servers or resolve records hosted on forwarding targets of a forwarding zone authorized for that VPC. You can configure inbound and outbound forwarding at the same time for bi-directional resolution, so VMs resolve on-premises names and on-premises hosts resolve Google Cloud names over the same hybrid connection.
An outbound server policy changes this flow by sending all DNS requests from a VPC network to an alternative name server. When an outbound server policy points to an alternative server, VMs in that VPC network can no longer resolve records in Cloud DNS private zones, forwarding zones, peering zones, or Compute Engine internal zones. Choose a forwarding zone when only specific names should go to another server, and choose an outbound server policy only when all lookups must leave the VPC.
A static internal IP address stays reserved for the project until it is explicitly released and survives deletion and recreation of its virtual machine, while an ephemeral internal IP address is assigned automatically and released back to the subnet pool when the resource is deleted. Reserve a static address for servers, databases, and DNS targets that other systems must always reach at the same address.
Use a Cloud DNS forwarding zone when only specific names should go to another server and use an outbound server policy only when all lookups must leave the Virtual Private Cloud network. When an outbound server policy points to an alternative server, virtual machines in that network can no longer resolve records in Cloud DNS private zones, forwarding zones, peering zones, or Compute Engine internal zones.
Virtual machine instances in different subnets of a custom Virtual Private Cloud network cannot communicate because a custom network denies all ingress by default and requires a higher-priority ingress allow rule for instance-to-instance communication. The default network is an exception because it includes the default-allow-internal rule which permits communication among instances in that network.
Shared VPC keeps the Virtual Private Cloud network and subnets in a host project while workloads and endpoints live in service projects. An endpoint can be created in a service project using an IP address from a subnet in the host project, so the host project controls the network and IP ranges while the service project uses them.
Your organization has deployed a multi-tier application across several Compute Engine virtual machines (VMs) in a single Virtual Private Cloud (VPC) network. You need to configure a firewall rule to allow inbound HTTPS traffic on TCP port 443 from the public internet exclusively to instances acting as web frontends. Database instances and internal worker VMs must not be accessible over this port from the internet.
You want to configure this security boundary using Google Cloud's recommended traffic management mechanism.
What should you do?
Last updated