
How to Find External IP of Google Cloud VM?


You are locating external IP addresses within GCP Server.
Are you working on a project where you need to retrieve external (Internet/Public) IP of respective VM instance for application?
Good news – you can quickly get them.
I am sure you would have tried running ifconfig
command. And, you could notice the results contain only internal IP.
GCP and AWS, both have a friendly web interface where you can see the public IP, but if you require to get them on a server directly, then the following commands will help you.
Getting External IP on GCP VM
There are two possible ways I am aware of. The first one is using a gcloud command.
gcloud compute addresses list
The above command will show you all your project IPs. Useful for troubleshooting or have a quick review while you are logged in on VM.
Ex:
[email protected]:~# gcloud compute addresses list
NAME ADDRESS/RANGE TYPE PURPOSE NETWORK REGION SUBNET STATUS
instance-1 xx.xx.xx.xx us-west1 IN_USE
geekflare-nexus xx.xx.xx.xx INTERNAL GCE_ENDPOINT us-west1 default IN_USE
geekflare xx.xx.xx.xx us-west1 IN_USE
geekflare-tools xx.xx.xx.xx us-west1 IN_USE
[email protected]:~#
and, the second one is by using curl command to metadata.
curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip
Note: if you have multiple network interface then you got to change 0 after network-interfaces to 1 or 2 accordingly.
Metadata is powerful; you can retrieve many metrics.
[email protected]:~# curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/
attributes/
cpu-platform
description
disks/
guest-attributes/
hostname
id
image
licenses/
machine-type
maintenance-event
name
network-interfaces/
preempted
remaining-cpu-time
scheduling/
service-accounts/
tags
virtual-clock/
zone
[email protected]:~#
You see, what I mean?
This can be handy for reporting and automation.
If you also need to get internal IP then use the below command.
curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/ip
Are you learning GCP administration? Check out this fantastic online course.
- Tagged in:
- GCP
More great readings on Cloud Computing
-
An Introduction Guide to AWS FargateNaman Yash on June 14, 2022
-
10 Cloud-Based Cross Browser Testing Tools [2022]Saptak Chaudhuri on June 13, 2022
-
8 Best Virtualization Monitoring Tools for Medium to Big BusinessSatish Shethi on June 10, 2022
-
12 Best Hosting Platforms for the Germany MarketAmrita Pathak on June 11, 2022
-
Infrastructure as a Service (IaaS): Everything You Need To KnowNaman Yash on June 7, 2022
-
Deliver Your Application Content Faster to the Users with G-Core Labs CDNAmrita Pathak on May 26, 2022
Join Geekflare Newsletter
Every week we share trending articles and tools in our newsletter. More than 10,000 people enjoy reading, and you will love it too.