Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP: assign/remove ephemeral IP to an existing instance

I have few instances in GCP and for administrative purposes I need to briefly connect in SSH and launch few commands. These instances do not have external IP in "normal" mode but for these brief maintenance I would like to assign ephemeral IP, do the maintenance and then remove them.

One can do this easily on the web interface (edit the instance change the NIC config to add ephemeral NAT IP) but I would like to avoid this since I have several instances... Am I missing something in gcloud documentation?

like image 320
gdupont Avatar asked Nov 28 '17 16:11

gdupont


People also ask

What is ephemeral IP address in GCP?

An ephemeral IP address is an IP address that doesn't persist beyond the life of the resource. For example, when you create an instance or forwarding rule without specifying an IP address, Google Cloud automatically assigns the resource an ephemeral IP address.

Can an instance be provisioned without external IP?

If no external address is configured on the instance, Cloud NAT can be used for IPv4 traffic. For information about identifying the internal and external IP address for your instances, see Locating the external and internal IP address for an instance.


1 Answers

Found it after some (too long) time exploring the deep part of gcloud documentation.

In the section dedicated to assign static external IP address to an instance (yes in the static part) it says in a small note:

"If you intend to use an ephemeral external IP address, you can skip this step, and Compute Engine will randomly assign an ephemeral external IP address."

https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address#ipassign

So the "key" word is to add an accessConfig to your instance like:

gcloud compute instances add-access-config [INSTANCE_NAME] \
--access-config-name "[ACCESS_CONFIG_NAME]" 

In the example, there is a --address [IP_ADDRESS] option to assign the static external IP but, as the note said, it is optional. Frankly, not easy to find!

like image 194
gdupont Avatar answered Oct 05 '22 04:10

gdupont