If you host web services on a cloud server, such as GCP’s Compute Engine, you probably want to use a static IP address, as the default dynamic may change when the server is restarted.
What is a static IP address?
When you start a server on a virtual cloud provider such as AWS or Google Cloud Platform, it is assigned two IP addresses ̵1; a private address for internal communication and a public address that allows anyone online to access services running on the machine, provided that firewall is open.
However, because VPS providers such as GCP allow you to start and stop cloud servers at any time, the server’s IP address may change if it is restarted, as the dynamic address you used may have been given to someone else. If you need to configure another service with this IP address as your DNS, this is a problem.
The solution is static IP addresses, which will never change. You can provide 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.
GCP static IPs are currently free, but starting June 30, 2020, they will cost $ 3 per month. This is really worth it if you plan to use the same server in the long run. If you plan for high availability and launch two or more servers behind a load balancer, external IP addresses are free.
You will also need to link them to an ongoing body, or you will be charged a small fee for leaving them offline – $ 7.50 per month per IP, so make sure you actually use them.
Provide an address in GCP
From the Google Cloud Platform Console, click Compute Engine> VM instances:
This opens the network configuration for this GCP project, where you can select “External IP addresses” from the sidebar and provide a new static with “Reserve static address”:
Give it a name and leave the default values for Premium Network Service Tier and IPv4.
The next option is between regional and global addresses. If you provide this address to a global load balancer, you must use the global option. But for an individual instance, select the hosted region and then select the instance under the “Attached To” drop-down menu.
Click “Reserve” at the bottom, and within a minute you should see your instance move over to the new static IP address.