
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create a VPC network and firewall rules
/ 5
Create the VM instance with no public IP address
/ 5
Create the Bastion host
/ 5
Create a Cloud Storage Bucket and Enable Private Google Access
/ 5
Configure a Cloud NAT gateway
/ 5
Google Cloud’s Network Address Translation (NAT) service enables you to provision your application instances without public IP addresses while also allowing them to access the internet for updates, patching, config management, and more in a controlled and efficient manner.
In this lab, you will configure Private Google Access and Cloud NAT for a VM instance that doesn't have an external IP address. Then, you will verify access to public IP addresses of Google APIs and services and other connections to the internet. Finally, you will use Cloud NAT logging to record connections made in your gateway.
In this lab, you will learn how to perform the following tasks:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
You will now create one VM instance that has no external IP address and another VM instance to serve as a bastion host.
First, create a VPC network for the VM instances and a firewall rule to allow SSH access.
In the Cloud Console, on the Navigation menu (), click VPC network > VPC networks.
Click Create VPC Network.
For Name, type privatenet.
For Subnet creation mode, click Custom.
Specify the following, and leave the remaining settings as their defaults:
Property | Value (type value or select option as specified) |
---|---|
Name | privatenet-us |
Region | |
IP address range | 10.130.0.0/20 |
Click Done.
Click Create and wait for the network to be created.
In the left pane, click Firewall.
Click Create Firewall Rule.
Specify the following, and leave the remaining settings as their defaults:
Property | Value (type value or select option as specified) |
---|---|
Name | privatenet-allow-ssh |
Network | privatenet |
Targets | All instances in the network |
Source filter | IPv4 ranges |
Source IPv4 ranges | 0.0.0.0/0 |
Protocols and ports | Specified protocols and ports |
For tcp, specify port 22.
Click Create.
Click Check my progress to verify the objective.
In the Cloud Console, on the Navigation menu (), click Compute Engine > VM instances.
Click Create Instance.
In the Machine configuration.
Select the following values:
Property | Value (type value or select option as specified) |
---|---|
Name | vm-internal |
Region | |
Zone | |
Series | E2 |
Machine type | e2-medium(2 vCPU, 1 core, 4 GB memory) |
Click Networking.
For Network interfaces, expand the default specify the following:
Property | Value (type value or select option as specified) |
---|---|
Network | privatenet |
Subnetwork | privatenet-us |
External IPv4 address | None |
Click Done.
Click Create.
On the VM instances page, verify that the External IP of vm-internal is None.
Click Check my progress to verify the objective.
Because vm-internal has no external IP address, it can only be reached by other instances on the network or via a managed VPN gateway. This includes SSH access to vm-internal, which is grayed out (unavailable) in the Cloud Console.
In order to connect via SSH to vm-internal, create a bastion host vm-bastion on the same VPC network as vm-internal.
In the Cloud Console, on the VM instances page, click Create Instance.
In the Machine configuration.
Select the following values:
Property | Value (type value or select option as specified) |
---|---|
Name | vm-bastion |
Region | |
Zone | |
Series | E2 |
Machine type | e2-micro (2vCPU) |
Click Networking.
For Network interfaces, expand default and specify the following:
Property | Value (type value or select option as specified) |
---|---|
Network | privatenet |
Subnetwork | privatenet-us |
External IPv4 address | Ephemeral |
Click Done.
Click Security.
Set access for each API
Read Write
Click Create.
Click Check my progress to verify the objective.
Verify that you can access vm-internal through vm-bastion.
2. From the vm-bastion SSH terminal, verify external connectivity by running the following command:
This should work!
Y
.This should not work because vm-internal has no external IP address!
ping
command to complete.VM instances that have no external IP addresses can use Private Google Access to reach external IP addresses of Google APIs and services. By default, Private Google Access is disabled on a VPC network.
Create a Cloud Storage bucket to test access to Google APIs and services.
In the Cloud Console, on the Navigation menu (), click Cloud Storage > Buckets.
Click Create.
Specify the following, and leave the remaining settings as their defaults:
Property | Value (type value or select option as specified) |
---|---|
Name | Enter a globally unique name |
Default storage class | Multi-Regional |
Click Create.
Note the name of your storage bucket for the next subtask. It will be referred to as [my_bucket]
.
Copy an image from a public Cloud Storage bucket to your own bucket.
[my_bucket]
with your bucket's name:You can click on the name of the image in the Cloud Console to view an example of how Private Google Access is implemented.
[my_bucket]
with your bucket's name:This should work because vm-bastion has an external IP address!
[my_bucket]
with your bucket's name:To terminate the request after the first attempt, press CTRL+C.
Close the SSH terminal.
Private Google access is enabled at the subnet level. When it is enabled, instances in the subnet that only have private IP addresses can send traffic to Google APIs and services through the default route (0.0.0.0/0) with a next hop to the default internet gateway.
This should work as vm-internal's subnet has Private Google Access enabled!
Click Check my progress to verify the objective.
Although vm-internal can now access certain Google APIs and services without an external IP address, the instance cannot access the internet for updates and patches. You will now configure a Cloud NAT gateway, which allows vm-internal to reach the internet.
The output should look like this:
This should work because vm-bastion has an external IP address!
This should only work for Google Cloud packages because vm-internal only has access to Google APIs and services!
Cloud NAT is a regional resource. You can configure it to allow traffic from all ranges of all subnets in a region, from specific subnets in the region only, or from specific primary and secondary CIDR ranges only.
In the Cloud Console, on the Navigation menu (), click Network services > Cloud NAT.
Click Get started to configure a NAT gateway.
Specify the following:
Property | Value (type value or select option as specified) |
---|---|
Gateway name | nat-config |
Network | privatenet |
Region |
For Cloud Router, select Create new router.
For Name, type nat-router.
Click Create.
It may take up to 3 minutes for the NAT configuration to propagate to the VM, so wait at least a minute before trying to access the internet again.
The output should look like this:
This should work because vm-internal is using the NAT gateway!
Click Check my progress to verify the objective.
Cloud NAT logging allows you to log NAT connections and errors. When Cloud NAT logging is enabled, one log entry can be generated for each of the following scenarios:
You can opt to log both kinds of events, or just one or the other. Created logs are sent to Cloud Logging.
If logging is enabled, all collected logs are sent to Stackdriver by default. You can filter these so that only certain logs are sent.
You can also specify these values when you create a NAT gateway or by editing one after it has been created. The following directions show how to enable logging for an existing NAT gateway.
In the Cloud Console, on the Navigation menu (), click Network services > Cloud NAT.
Click on the nat-config
gateway and then click Edit.
Click Advanced configurations.
Under logging, select Translation and errors and then click Save.
Now that you have set up Cloud NAT logging for the nat-config
gateway, let's find out where we can view our logs. You should have left off on the following page with your gateway updated:
Click on nat-config
to expose its details. Then click View in Logs Explorer link.
This will open a new tab with Logs Explorer—ensure that the top of your page resembles the following:
You will see that there aren't any logs yet—that's because we just enabled this feature for the gateway. Keep this tab open and return to your other Cloud Console tab.
As a reminder, Cloud NAT logs are generated for the following sequences:
Let's connect the bastion host to the internal VM again to see if any logs are generated.
The output should look like this:
Let's see if opening up this connection revealed anything new in our logs.
Return to your NAT Logging tab and click the Jump to now button.
You should see two new logs that were generated after connecting the bastion host to the internal VM.
As we see, the logs give us details on the VPC network we connected to and the connection method we used. Feel free to expand different labels and details.
This concludes this self-paced lab, Configuring Private Google Access and Cloud NAT.
You created vm-internal, an instance with no external IP address, and vm-bastion, a bastion host to securely connect to vm-internal. Then you enabled Private Google Access, configured a NAT gateway, and verified that vm-internal can access Google APIs and services and other public IP addresses. Finally, you learned how to configure NAT Logging and how to generate and view those logs in Stackdriver.
VM instances without external IP addresses are isolated from external networks. Using Cloud NAT, these instances can access the internet for updates and patches, and in some cases, for bootstrapping. As a managed service, Cloud NAT provides high availability without user management and intervention.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
Diese Inhalte sind derzeit nicht verfügbar
Bei Verfügbarkeit des Labs benachrichtigen wir Sie per E-Mail
Sehr gut!
Bei Verfügbarkeit kontaktieren wir Sie per E-Mail
One lab at a time
Confirm to end all existing labs and start this one