Quick Links

If you're hosting web services on a cloud server, such as GCP's Compute Engine, you probably want to use a static public IP address, as the default dynamic one is subject to change whenever the server is restarted.

What Is a Static IP Address?

Whenever you launch a server on any virtual cloud provider like AWS or Google Cloud Platform, it's assigned two IP addresses---a private address for communicating internally, and a public address that allows anyone on the web to access services running on the machine, provided the firewall is open.

However, because VPS providers like GCP allow you to launch and terminate cloud servers at will, your server's IP address may change if it is restarted, as the dynamic address you were using may have been given to someone else. If you need to configure another service using this IP address like your DNS, this is a problem.

The solution is static IP addresses, which will never change. You can provision these and attach them to your servers, and they will replace the dynamically assigned public address. If you restart the server, this address is guaranteed not to change.

Static IP addresses in GCP used to be free, but now they are billed for hourly usage. This is certainly worth it though if you're planning on using the same server long-term. If you're planning for high availability, and are launching two or more servers behind a load balancer, then external IP addresses are free.

You also must attach them to a running instance, or you'll be charged a small fee for leaving them unattached---$7.50 a month per IP, so make sure you're actually using them.

Related: How to Assign a Static IP Address in Windows 10 or Windows 11

Provisioning an Address in GCP

From the Google Cloud Platform Console, click Compute Engine > VM Instances:

Compute Engine > VM Instances.

Click on the settings dropdown for the instance you want to assign the address to, and select "View Network Details":

Click settings dropdown for instance you want to assign address to, select "View Network Details".

This will open up the network configuration for this GCP project, where you will be able to select "External IP Addresses" from the sidebar, and provision a new static one with "Reserve Static Address":

Network configuration for this GCP project.

Give it a name, and leave the defaults of Premium Network Service Tier and IPv4.

Name network configuration for this GCP project.

The next option is between regional and global addresses. If you're provisioning this address for a global load balancer, you must use the global option. But for an individual instance, select the region it is hosted in, and then select the instance under the "Attached to" dropdown.

Select regional address.

Click "Reserve" at the bottom, and within a minute or so you should see your instance moved over to the new static IP address.