
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
Update the firewall
/ 100
In this hands-on lab, you learn how to connect to computing resources hosted on Google Cloud via gcloud
, Google Cloud's CLI tool.
You are encouraged to type the commands themselves, which reinforces the core concepts. This lab uses code blocks that contain the required commands. You can easily copy and paste the commands from the code block into the appropriate places during the lab.
gcloud
commands.Pre-configured resource:
You have a pre-configured VM instance named gcelab2 in the default network for this lab.
Throughout the lab, you will use the zone:
Create an environment variable to store your zone:
gcloud compute
makes connecting to your instances easy.
The gcloud compute ssh
command provides a wrapper around SSH, which takes care of authentication and the mapping of instance names to IP addresses.
SSH stands for Secure Shell. It is a network protocol that allows you to securely access and manage a virtual machine (VM).
To connect to your VM with SSH in a specific zone, run the following command:
Output:
In a production environment you should set a passphrase, but for this lab it is not required. Leave the passphrase empty by pressing Enter twice.
You have connected to the virtual machine pre-created for the lab.
Did you notice how the command prompt changed?
The prompt now says something similar to sa_xxxxxxxxxxxxxxxxxxxx@gcelab2
Install nginx
web server on to the virtual machine:
You don't need to do anything here. To disconnect from SSH and exit the remote shell, run the following command:
You should be back at your project's command prompt.
When using compute resources such as virtual machines, its important to understand the associated firewall rules.
List the firewall rules for the project:
Output:
From the above you can see the default
networks available, where the virtual machine gcelab2
is located.
Try to access the nginx service running on the gcelab2
virtual machine.
Send HTTP request using cURL
to the nginx web server and see if the server responds:
The nginx server will not respond and you will see a frozen remote shell. Press Ctrl-c to stop cURL.
Communication with the virtual machine will fail as it does not have an appropriate firewall rule. Nginx uses port 80 for HTTP traffic by default. The nginx web server is expecting to communicate on tcp:80.
To get communication working you need to updated a firewall rule which allows incoming traffic on TCP port 80 from any source targeting gcelab2
virtual machine.
Update the firewall rule to allow:
Notice --target-tags=http-server
in the above command. This firewall rule applies only to instances that have the http-server network tag, which means that incoming traffic on port 80 would be allowed to those instances.
Add the http-server
network tag to the gcelab2
virtual machine:
List the firewall rules for the project:
Output:
List instances that are tagged with the http-server
network tag:
You can see the 'gcelab2' virtual machine listed.
Verify communication is possible for http to the virtual machine:
You can see the default nginx
output.
Click Check my progress to verify the objective.
Viewing logs is essential to understanding how your project works.
Use gcloud
to access the different logs available on Google Cloud.
View the available logs on the system:
Output:
View the logs that relate to compute resources:
Output:
Read the logs related to the resource type of gce_instance
:
Read the logs for a specific virtual machine:
You learned how to launch cloud terminal and run some sample gcloud
commands.
gcloud
, refer to the gcloud documentation
...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.
Manual Last Updated January 9, 2024
Lab Last Tested November 12, 2024
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.
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