Are you working on a project where you need to retrieve the external (Internet/Public) IP of the respective VM instance for the 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. 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: and, the second one is by using the curl command to metadata. 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. 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. Are you learning GCP administration? Check out this fantastic online course.

How to Find External IP of Google Cloud VM  - 69How to Find External IP of Google Cloud VM  - 72How to Find External IP of Google Cloud VM  - 13How to Find External IP of Google Cloud VM  - 42How to Find External IP of Google Cloud VM  - 48How to Find External IP of Google Cloud VM  - 98