An external IP address is assigned to every Google Cloud Platform virtual machine (VM) instance that you create.
This IP address can be used in your DNS settings so that users can access the instance via a domain name. The problem, however, is that the IP address resets whenever the VM instance is restarted. This means that every time you restart your VM instance, you will need to update your various configurations (e.g. DNS, load balancing) to reference the new IP address.
You can bypass this issue by reserving and assigning a static IP address for an instance. An added bonus is that this is free! However, you will be charged USD$0.01/hour for unused IP addresses – i.e. reserved static IP addresses that are not attached to an instance or forwarding rule.
Concepts
Regional vs Global IP addresses
Regional IP addresses can be used by:
- VM instances
- Network load balancers
Global IP addresses are used for global load balancers.
How to reserve and assign a static IP address to a Google Cloud Platform VM instance
Navigate to the Google Cloud Platform Console page for your project.
Using the left-hand menu, navigate to Networking > VPC network > External IP addresses
Click on + Reserve Static Address
Edit the settings:
- Name: a name to describe this IP reservation (e.g. “webserver-primary-ip”)
- IP version: IPv4 or IPv6 depending on your needs
- Type: Regional if you want to use it for accessing a VM instance
- Region: Select the same region as where your VM instance lives
- *Attached to: Select the instance you wish to attach the static IP address to
- Click on Reserve to save your settings
You will be taken back to the External IP addresses list page. Here you can see the new IP address that has been assigned to your instance.
This IP address can now be used in your DNS settings.
Pingback: Setting up Google Cloud DNS for a GoDaddy domain - vinoaj.com
I reserved static address and released it by mistake. And I tried to reserve it again but external IP address appears same as original address. And it is not working properly. Can you please give me an advice?
Hi SooWhan,
What do you mean by it’s not working properly? Were you able to follow the steps in my post? At what point did you encounter any issues?
Cheers,
Vinny
hello i follow all the steps but still i am facing issue when i am type my domain name and press enter its take me to my external ip
Hi Hashir – if you follow the instructions, then that is what should happen: typing in your domain name will take you to the external IP of your instance. What behaviour are you seeking?
Hello
I have one public ip for my VM already to access it do I need to create once again.
If I will create it again can I access my VM with the external ip which I created.
my prob:
when I do nslookup my ip address is showing but I don’t want to show my ip address
Plz help me in this.
Yes, you can access the VM with the new IP. If your server is meant to be publicly accessible, then there is no way to hide it’s IP address from nslookup calls.
Hello Vinoaj,
excellent post, do you think that you can use the same method to reserve a static ip address for a storage bucket? i have been trying to connect a static website to my domain in godaddy and it seems impossible.
Hi Adonis – you can’t easily assign a static IP address to a bucket. The one way to do it is to set up a global HTTP(S) Load Balancer with an anycast IP address. However, this is a rather painful process. The alternative is to follow the guide here: https://cloud.google.com/storage/docs/hosting-static-website – this seems to be a much easier process!
Hello,
thank you for this great post!
I just assigned a static IP address to a LoadBalancer service and it works perfectly fine, but my other LoadBalancer(s) also “want” to have a static IP address now (I get the error “Error creating load balancer (will retry): failed to ensure load balancer for service default/example: failed to ensure a static IP for load balancer: Error 403: Quota ‘STATIC_ADDRESSES’ exceeded. Limit: 1.0 in region us-central1., quotaExceeded”, as I am limited to only 1 static IP address due to a Trial account), but I’d be fine with the other LoadBalancer having an ephemeral IP address.
Do you know if it is possible to force other LoadBalancer services having an ephemeral IP address?
Thank you in advance!
Laura
Hi Laura,
Thanks for your feedback! Regarding your problem, as far as I can tell you do need a reserved IP address if your load balancer is to be reached by external parties. If you use an internal load balancer, however, you have more flexibility with choice of IP address types: https://cloud.google.com/load-balancing/docs/internal/#load_balancing_ip_address
Pingback: Pulling The Plug, Part 12: The End – Glyffe News