Google Cloud Network Engineering: Configuring NAT Gateway for Compute Engine Instances

How to Use a NAT Gateway to Enable Internet Access for Existing Instances

Question

You have configured a Compute Engine virtual machine instance as a NAT gateway.

You execute the following command: gcloud compute routes create no-ip-internet-route \ --network custom-network1 \ --destination-range 0.0.0.0/0 \ --next-hop instance nat-gateway \ --next-hop instance-zone us-central1-a \ --tags no-ip --priority 800 You want existing instances to use the new NAT gateway.

Which command should you execute?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

D.

https://cloud.google.com/vpc/docs/special-configurations

The correct command to execute in order to direct existing instances to use the new NAT gateway is:

B. gcloud compute instances add-tags [existing-instance] --tags no-ip

Explanation:

The gcloud compute routes create command creates a route in a VPC network. In this case, the route created is named no-ip-internet-route and it directs traffic with the destination IP range of 0.0.0.0/0 to the nat-gateway instance in the us-central1-a zone of custom-network1. The --tags no-ip option adds the no-ip tag to the route, which means that any instance with the no-ip tag will use this route to access the internet.

To direct existing instances to use the new NAT gateway, we need to add the no-ip tag to them. This can be done with the gcloud compute instances add-tags command. The [existing-instance] parameter should be replaced with the name of the existing instance that you want to add the no-ip tag to.

Option A (sudo sysctl -w net.ipv4.ip_forward=1) is not relevant to this scenario. This command enables IP forwarding on a Linux-based NAT gateway, but it is not necessary in this case because the Compute Engine instance has already been configured as a NAT gateway.

Option C (gcloud builds submit --config=cloudbuild.waml --substitutions=TAG_NAME=no-ip) is also not relevant to this scenario. This command submits a build to Cloud Build, which is a service for building and deploying applications. It has no relevance to configuring a NAT gateway or adding tags to instances.

Option D (gcloud compute instances create example-instance --network custom-network1 --subnet subnet-us-central --no-address --zone us-central1-a --image-family debian-9 --image-project debian-cloud --tags no-ip) creates a new instance with the no-ip tag. However, this is not what the question is asking for. The question is asking how to direct existing instances to use the new NAT gateway, not how to create a new instance with the no-ip tag.