Skip to main content

Assign External IP to VM Instance using gcloud (Solution)

Updated 1 min readMarkdown
Part of seriesTip & Tricks
Assign External IP to VM Instance using gcloud (Solution)

Overview

  • Labs are timed and cannot be paused. The timer starts when you click Start Lab.

  • The included cloud terminal is preconfigured with the gcloud SDK.

  • Use the terminal to execute commands and then click Check my progress to verify your work.

Challenge scenario

You are a system administrator for a company that uses Google Cloud to host its applications. You have an existing compute instance without an external IP in the default VPC network.

Your task is to assign static external IP address to your virtual machine (VM) instances.

Click Check my progress to verify the objective.

Create a static external IP address


Solution of Lab

curl -LO raw.githubusercontent.com/ePlus-DEV/storage/refs/heads/main/labs/assign-external-ip-to-vm-instance-using-gcloud-solution/lab.sh
source lab.sh

Script Alternative

export VM_NAME=$(gcloud compute instances list --format='value(name)' --limit=1) && export ZONE=$(gcloud compute instances list --format='value(zone)' --limit=1) && export REGION=${ZONE%-*}
gcloud compute addresses create lab-static-ip --region=$REGION
export IP_ADDRESS=$(gcloud compute addresses describe lab-static-ip --region=$REGION --format='get(address)') && gcloud compute instances add-access-config $VM_NAME --zone=$ZONE --address=$IP_ADDRESS

About the author

No comments yet. Be the first to comment.

Tip & Tricks

Part 1 of 50

Quick and practical tips to help users optimize tasks, improve skills, and solve common problems effectively across various areas like tech, lifestyle, productivity, and more.

More from this blog