B4J Tutorial [GCE] For Noobs, Part 12 - Static vs Ephemeral IP Addresses

‘Static’? ‘Ephemeral’? What the heck am I talking about? It sounds like something from the Ghostbusters movie with references to the Key Master, Gate Keeper and my old pal Zuul!

Going back to Tutorial 9 I mentioned briefly that the external IP address that your VM is given is NOT static but, is in fact, ephemeral. What does that mean? In simple terms it means that the IP address that your VM is given could change. It may also stay the same. There’s just no guarantee that the IP address will stay the same for the life of the server.

Google’s documentation states (https://cloud.google.com/compute/docs/ip-addresses/)
I have highlighted the relevant part in 'orange'

Ephemeral internal IP addresses

Ephemeral internal IP addresses are available to VM instances and forwarding rules.

Ephemeral internal IP addresses remain attached to a VM instance only until the VM is stopped and restarted or the instance is terminated. If an instance is stopped, any ephemeral internal IP addresses assigned to the instance are released back into the network pool. When a stopped instance is started again, a new ephemeral internal IP address is assigned to the instance.

You can assign an ephemeral internal IP address when you create a resource by omitting an IP address specification in your request and letting Compute Engine randomly assign an address.

This should be taken to mean that the IP address will not change unless you stop and restart the VM. For long running processes/services/web apps you are probably going to want the IP address to stay the same - ie. Static

So how can we make sure that the IP address does not change for the life of the server? Well, to make it stay the same we need to change the IP address from being ‘ephemeral’ to ‘static’. Before we do this I feel that I should point out that you will get just one (1) static IP address with your free trial from Google. However, you can have more IP addresses but you will be billed for each additional one.

Note: the IP address that your VM has will not change after you have converted it to a Static IP. This is a good thing! :)

Follow these steps to convert your ephemeral IP address to a static IP address
  • Click on the ‘hamburger’ menu in the top-left of the console window (inside your browser)

  • Scroll down until you see the section labelled ‘NETWORKING’ and then the menu item ‘VPC network’ and finally, expand the sub-menu and click on ‘External IP addresses’ (image below)

  • You now see a window titled ‘External IP addresses’.
    If you only have one (1) VM instance then it will be the only VM listed and easily found. However, if you’re like me and, have already made several VM’s (...not greedy, just bent on world domination using my B4J console apps…) then you will need to carefully find the VM you want to change.

    In the image below I have shown, again, carefully circled and highlighted the server I need to change (which is also the same server name used in this tutorial series) as well as where to find the server name.

    (I should have become an artist!) ;)

  • Now you probably have already figured out the next step.
    Click on the arrow next to where is says ‘Ephemeral’ and select ‘Static’ from the pop-up menu (image shown below)

  • Next, in the pop-up form, fill in the name of the IP address. I usually prefix the name with ‘ip-’ (for IP address) and use the name of the VM. Click ‘RESERVE’ when you are done (image shown below)

  • After a short moment, your screen will refresh and the server will now show ‘Static’ instead of ‘Ephemeral’
Congratulations! You now have successfully assigned your VM with a Static IP address.