Configuring Networks via gcloud
- In Cloud Shell, use the following
gcloud
command to create a custom mode network calledlabnet
:gcloud compute networks create labnet --subnet-mode=custom
With this command you’re doing the following:
gcloud
invokes the Cloud SDKgcloud
command line toolcompute
is a one of the groups available ingcloud
, part of a nested hierarchy of command groupsnetworks
is a subgroup ofcompute
with it’s own specialized commandscreate
is the action to be executed on this grouplabnet
is the name of the network you’re creating--subnet-mode=custom
you’re passing the subnet mode flag and the type of subnet you’re creating, “custom”.
- Now create sub-network labnet-sub:
gcloud compute networks subnets create labnet-sub \ --network labnet \ --region us-central1 \ --range 10.0.0.0/28
- Viewing & Describing networks
gcloud compute networks list gcloud compute networks describe NETWORK_NAME
- List subnets
gcloud compute networks subnets list
- Create the labnet-allow-internal firewall rule:
gcloud compute firewall-rules create labnet-allow-internal \ --network=labnet \ --action=ALLOW \ --rules=icmp,tcp:22 \ --source-ranges=0.0.0.0/0
- firewall-rules is a subcatagory of compute
- create is the action you are taking
- labnet-allow-internal is the name of the firewall rule
- –network=labnet puts the rule in the labnet network
- –action=ALLOW must be used with the –rules flag, and is either “ALLOW” or “DENY”
- –rules=icmp,tcp:22 specifies the icmp and tcp protocols and the ports that the rule applies to
- –source-ranges=0.0.0.0/0 specifies the ranges of source IP addresses in CIDR format.
- Run the following command to create the privatenet network:
gcloud compute networks create privatenet --subnet-mode=custom
- Create the private-sub subnet:
gcloud compute networks subnets create private-sub \ --network=privatenet \ --region=us-central1 \ --range 10.1.0.0/28
- Run the following command to create the privatenet-deny firewall rule:
gcloud compute firewall-rules create privatenet-deny \ --network=privatenet \ --action=DENY \ --rules=icmp,tcp:22 \ --source-ranges=0.0.0.0/0
- Run the following command to create the pnet-vm instance in the
private-sub
subnet:gcloud compute instances create pnet-vm \ --zone=us-central1-c \ --machine-type=n1-standard-1 \ --subnet=private-sub
- Run the following command to create the lnet-vm instance in the
labnet-sub
subnet:gcloud compute instances create lnet-vm \ --zone=us-central1-c \ --machine-type=n1-standard-1 \ --subnet=labnet-sub
- Ping the external IP addresses Ping the external IP addresses of the VM instances to determine if you can reach the instances from the public internet.
ping -c 3 <Enter lnet-vm's external IP here>
Tag:Google Cloud