
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 the VM instance
/ 30
Create a Cloud Storage bucket and Enable Private Google Access
/ 40
Configure a Cloud NAT gateway
/ 30
In this lab, you implement Private Google Access and Cloud NAT for a VM instance that doesn't have an external IP address. Then, you verify access to public IP addresses of Google APIs and services and other connections to the internet.
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.
In this lab, you learn how to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel 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 panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Create a VPC network with some firewall rules and a VM instance that has no external IP address, and connect to the instance using an IAP tunnel.
First, create a VPC network for the VM instance and a firewall rule to allow SSH access.
In the Google Cloud console, in the Navigation menu (), click VPC network > VPC networks.
Click Create VPC Network.
For Name, type privatenet.
For Subnet creation mode, click Custom.
In New Subnet specify the following, and leave the remaining settings as their defaults:
Property | Value (type value or select option as specified) |
---|---|
Name | privatenet-us |
Region | |
IPv4 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 | 35.235.240.0/20 |
Protocols and ports | Specified protocols and ports |
For tcp, click the checkbox and specify port 22.
Click Create.
In the Google Cloud console, in the Navigation menu (), click Compute Engine > VM instances.
Click Create Instance.
On the Machine configuration page, specify the following, and leave the remaining settings as their defaults:
Property | Value (type value or select option as specified) |
---|---|
Name | vm-internal |
Region | |
Zone | |
Series | E2 |
Machine type | e2-medium (2vCPU, 1 core, 4 GB memory) |
Click OS and storage.
If the Image shown is not Debian GNU/Linux 12 (bookworm), click Change and select Debian GNU/Linux 12 (bookworm), and then click Select.
Click Networking.
In Network interfaces, edit the network interface by specifying the following:
Property | Value (type value or select option as specified) |
---|---|
Network | privatenet |
Subnetwork | privatenet-us |
External IPv4 address | None |
Click Check my progress to verify the objective.
In the Cloud console, click Activate Cloud Shell ().
If prompted, click Continue.
Run the following command in Cloud Shell to setup auth without opening up a browser.
If prompted [Y/n], press Y and then ENTER.
This will give you a link to open in your browser. Open the link in the same browser where you are logged in to the qwiklabs account. Once you login you will get a verification code to copy. Paste that code in the cloud shell.
To connect to vm-internal, run the following command:
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 Google Cloud console, in 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 |
Location type | Multi-region |
Click Create. If prompted to enable public access prevention, ensure it is checked and cick Confirm. Note the name of your storage bucket.
Store the name of your bucket in an environment variable:
Copy an image from a public Cloud Storage bucket to your own bucket.
You can click on the name of the image in the Cloud console to view an example of how Private Google Access is implemented.
This should work because Cloud Shell has an external IP address!
If prompted, type Y to continue.
Store the name of your bucket in an environment variable:
This should not work: vm-internal can only send traffic within the VPC network because Private Google Access is disabled (by default).
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.
Click Check my progress to verify the objective.
This should work because vm-internal's subnet has Private Google Access enabled!
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. Configure a Cloud NAT gateway, which allows vm-internal to reach the internet.
The output should finish like this (example output):
This should work because Cloud Shell 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.
On the Google Cloud console title bar, type Network services in the Search field, then click Network services in the Products & Page section.
On the Network service page, click Pin next to Network services.
Click 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.
Click Check my progress to verify the objective.
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 finish like this (example output):
This should work because vm-internal is using the NAT gateway!
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 Cloud Logging 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 Google Cloud console, in the Navigation menu (), click Network services > Cloud NAT.
Click on the nat-config
gateway and then click Edit.
Click the Advanced configurations dropdown to open that section.
For 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.
Click on nat-config
to expose its details. Then click on the View in Logs Explorer.
This will open a new tab with Logs Explorer.
You will see that there aren't any logs yet—that's because we just enabled this feature for the gateway.
As a reminder, Cloud NAT logs are generated for the following sequences:
Let's connect the host to the internal VM again to see if any logs are generated.
The output should look like this (example output):
Let's see if opening up this connection revealed anything new in our logs.
You should see two new logs that were generated after connecting 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.
You created vm-internal, an instance with no external IP address, and connected to it securely using an IAP tunnel. 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.
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.
IAP uses your existing project roles and permissions when you connect to VM instances. By default, instance owners are the only users that have the IAP Secured Tunnel User role.
For how to allow other users to access your VMs using IAP tunneling, see, in the Cloud Architecture Center, Grant access to additional users Guide.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 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.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one