How to Setup an static ip address to a Google Compute Engine Instance

1 minute read

By default Google Compute Engine instances are created with ephimeral IP address. What if you want to set to them an static IP that doesnt change? For instance, the most common scenario would be to link to that IP a catchy DNS for your web application or API.

I found a solution in 2 steps:

Delete the current possible ephimeral ip configuration:

gcloud compute instances delete-access-config <instance> --access-config-name "External NAT"

Where <instance> is the name of the instance you want to update, and External NAT is the name of the configuration, which probably has that value because of its the default one. And you can check it running this:

gcloud compute instances describe <instance> --zone=us-west1-a

And add the static one

If you want to bind an static address, probably to bind it to a DNS address, execute something like this

gcloud compute instances add-access-config <instance> --access-config-name="External NAT" --address=xxx.xxx.xxx.xxx

Remember to always append the --zone to any gcloud command to avoid any ambiguity. You can get the address from the valid addresses configuration you have in your project, which you can be gotten like this:

gcloud compute addresses list

Dont use the NAME but the ADDRESS. You should pick an address in the same zone of your instance. When the address be attached you will see that in the STATUS field of the last query it will say IN USE.

Et voila!

Leave a Comment