VPC_Lab
VPC_Lab
In this lab, you explore the VPC and default networks, firewalls, Subnets,
Connectivity and Secuirty.
Next you create a new auto mode VPC network with subnets, routes, firewall rules,
and two VM instances and tested the connectivity for the VM instances. Because
auto mode networks aren't recommended for production, you convert the auto mode
network to a custom mode network.
Next, you create two more custom mode VPC networks with firewall rules and VM
instances using the Cloud Console and the gcloud command line.
Then you test the connectivity across VPC networks and VMs, which work when
pinging external IP addresses but not when pinging internal IP addresses they do not
ping.
Overview
Google Cloud Virtual Private Cloud (VPC) provides networking functionality to
Compute Engine virtual machine (VM) instances, Kubernetes Engine containers, and
the App Engine flexible environment. In other words, without a VPC network, you
cannot create VM instances, containers, or App Engine applications. Therefore, each
Google Cloud project has a default network to get you started.
You can think of a VPC network as similar to a physical network, except that it is
virtualized within Google Cloud. A VPC network is a global resource that consists of
a list of regional virtual subnetworks (subnets) in data centers, all connected by a
global wide area network (WAN). VPC networks are logically isolated from each
other in Google Cloud.
In this lab we create VPC networks, subnets and VM’s as per the diagram given
below:
Page 1 of 17
Objectives
Each Google Cloud project has a default network with subnets, routes, and firewall
rules.
To create GCP project first time you have to enable the “Compute Engine api”
Before you create a VM you create a project. When you create a Project the VPC is
created for you. If delete the VPC then, you cannot create a VM instance without a
VPC network!
Page 2 of 17
View the subnets
The default network has a subnet in each Google Cloud region.
• In the Cloud Console, on the Navigation menu (), click VPC network > VPC
networks. Notice the default network with its subnets. Each subnet is
associated with a Google Cloud region and a private RFC 1918 CIDR block
for its internal IP addresses range and a gateway.
(24 Subnets + gateway , the Default route to the Internet. 0.0.0.0/0)
• In the left pane, click Routes. Notice that there is a route for each subnet and
one for the Default internet gateway (0.0.0.0/0).
• These routes are managed for you, but you can create custom static routes
to direct some packets to specific destinations.
For example, you can create a route that sends all outbound traffic to an
instance configured as a NAT gateway.
• In the left pane, click Firewall. Notice that there are 4 Ingress firewall rules
for the default network:
o default-allow-icmp
o default-allow-rdp
o default-allow-ssh
o default-allow-internal
These firewall rules allow ICMP, RDP, and SSH ingress traffic from anywhere
(0.0.0.0/0) and all TCP, UDP, and ICMP traffic within the network
(10.128.0.0/9). The Targets, Filters, Protocols/ports, and Action columns
explain these rules.
Page 3 of 17
2. Select all default network firewall rules.
3. Click Delete.
Page 4 of 17
These are the same standard firewall rules that the default network had. The deny-
all-ingress and allow-all-egress rules are also displayed, but you cannot select or
disable them because they are implied. These two rules have a
lower Priority (higher integers indicate lower priorities) so that the allow ICMP,
internal, RDP, and SSH rules are considered first.
6. Click Create. When the new network is ready, notice that a subnet was
created for each region.
7. Record the IP address range for the subnets in us-central1 and europe-
west1. These will be referred to in the next steps.
Tip: If you ever delete the default network, you can quickly re-create it by creating an
auto mode network as you just did.
2. Click Create.
3. Specify the following, and leave the remaining settings as their defaults:
Name mynet-us-vm
Region us-central1
Zone us-central1-c
Series N1
4. Click Create.
5. Verify that the Internal IP for the new instance was assigned from the IP
address range for the subnet in us-central1 (10.128.0.0/20).
Page 5 of 17
The Internal IP should be 10.128.0.2 because 10.128.0.1 is reserved for the
gateway, and you have not configured any other instances in that subnet.
2. Specify the following, and leave the remaining settings as their defaults:
Name mynet-eu-vm
Region europe-west1
Zone europe-west1-c
Series N1
3. Click Create.
4. Verify that the Internal IP for the new instance was assigned from the IP
address range for the subnet in europe-west1 (10.132.0.0/20).
Page 6 of 17
1. On the Navigation menu ( ), click Compute Engine > VM instances. Note
the external and internal IP addresses for mynet-eu-vm.
2. For mynet-us-vm, click SSH to launch a terminal and connect.
You can SSH because of the allow-ssh firewall rule, which allows incoming traffic
from anywhere (0.0.0.0/0) for tcp:22. The SSH connection works seamlessly
because Compute Engine generates an SSH key for you and stores it in one of the
following locations:
You can ping mynet-eu-vm's internal IP because of the allow-internal firewall rule.
You can SSH to mynet-us-vm and ping mynet-eu-vm's internal and external IP
addresses as expected. Alternatively, you can SSH to mynet-eu-vm and
ping mynet-us-vm's internal and external IP addresses, which also works.
Page 7 of 17
Converting an auto mode network to a custom mode network is an easy task, and it
provides you with more flexibility. We recommend that you use custom mode
networks in production.
Note that the IP CIDR ranges of these networks do not overlap. This allows you to
set up mechanisms such as VPC peering between the networks.
Page 8 of 17
5. Specify the following, and leave the remaining settings as their defaults:
Name managementsubnet-us
Region us-central1
IP address
10.130.0.0/20
range
6. Click Done.
These commands illustrate that networks and subnets can be created using
the gcloud command line. You will create the privatenet network using these
commands with similar parameters.
8. Click Close.
9. Click Create.
Page 9 of 17
gcloud compute networks subnets create privatesubnet-eu --network=privatenet --region=europe-west1 --
range=172.20.0.0/20
The output should look like this (do not copy; this is example output):
7. To list the available VPC subnets (sorted by VPC network), run the following
command:
The output should look like this (do not copy; this is example output):
*Read the notes below:
Page 10 of 17
mynetwork us-east1 mynetwork 10.142.0.0/20
The managementnet and privatenet networks only have the subnets that you
created because they are custom mode networks.
mynetwork is also a custom mode network, but it started out as an auto mode
network, resulting in subnets in each region.
3. Specify the following, and leave the remaining settings as their defaults:
managementnet-allow-
Name
icmp-ssh-rdp
Network Managementnet
Source IP
0.0.0.0/0
ranges
Protocols and
Specified protocols and ports
ports
Make sure to include the /0 in the Source IP ranges to specify all networks.
Page 11 of 17
4. Select tcp and specify ports 22 and 3389.
These commands illustrate that firewall rules can also be created using
the gcloud command line. You will create the privatenet's firewall rules using
these commands with similar parameters.
7. Click Close.
8. Click Create.
The output should look like this (do not copy; this is example output):
3. To list all the firewall rules (sorted by VPC network), run the following
command:
The output should look like this (do not copy; this is example output):
Page 12 of 17
mynetwork-allow-ssh mynetwork INGRESS 1000 tcp:22
The firewall rules for mynetwork network have been created for you.
You can define multiple protocols and ports in one firewall rule
(privatenet and managementnet) or spread them across multiple rules
(default and mynetwork).
• managementnet-us-vm in managementsubnet-us
• privatenet-us-vm in privatesubnet-us
3. Specify the following, and leave the remaining settings as their defaults:
Name managementnet-us-vm
Region us-central1
Zone us-central1-c
Series N1
Machine
f1-micro (1 vCPU, 614 MB memory)
type
Page 13 of 17
5. Click Networking.
7. Specify the following, and leave the remaining settings as their defaults:
Network Managementnet
Subnetwork managementsubnet-us
The subnets available for selection are restricted to those in the selected region (us-
central1).
8. Click Done.
The output should look like this (do not copy; this is example output):
Page 14 of 17
3. To list all the VM instances (sorted by zone), run the following command:
The output should look like this (do not copy; this is example output):
1. In the Cloud Console, on the Navigation menu, click Compute Engine > VM
instances. Note the external IP addresses for mynet-eu-
vm, managementnet-us-vm, and privatenet-us-vm.
Page 15 of 17
2. For mynet-us-vm, click SSH to launch a terminal and connect.
You can ping the external IP address of all VM instances, even though they are in
either a different zone or VPC network. This confirms that public access to those
instances is only controlled by the ICMP firewall rules that you established earlier.
Which instances should you be able to ping from mynet-us-vm using internal IP addresses?
managementnet-us-vm
privatenet-us-vm
mynet-eu-vm
Submit
1. In the Cloud Console, on the Navigation menu, click Compute Engine > VM
instances. Note the internal IP addresses for mynet-eu-
vm, managementnet-us-vm, and privatenet-us-vm.
Page 16 of 17
ping -c 3 <Enter mynet-eu-vm's internal IP here>
You can ping the internal IP address of mynet-eu-vm because it is on the same
VPC network as the source of the ping (mynet-us-vm), even though both VM
instances are in separate zones, regions, and continents!
This should not work either, as indicated by a 100% packet loss! You cannot ping the
internal IP address of managementnet-us-vm and privatenet-us-vm because they
are in separate VPC networks from the source of the ping (mynet-us-vm), even
though they are all in the same zone, us-central1-c.
Page 17 of 17