I have bought several Google Cloud Compute Engine instances.

I access each one through its public IP.

Is it possible to have hostnames in the Google Cloud service? Something like adolf.googlecloud.com, robert.googlecloud.com, etc.

When I search for «Google Cloud DNS», I only find information about having my own DNS server and zone. This is overkill for me. I just want a simple alias inside the Google Cloud domain, so that I don't have to memorize the IP. Is this possible?

3 Answers 3


AFAIK, GCP CE doesn't give such a facility.

If you want to access them from your local machine through a name / alias instead of IP, you can always bind the IP and the hostname you want into your hosts file. So, you will be able to connect to your instance by the name you bound to its public IP address. if your OS is a GNU/Linux or Unix-like,you can use the following command: echo " my.whateveriwant-hostname.tld" | sudo tee -a /etc/hosts ( Assuming that is your instance's public IP address )

If your need is to access them from one of the instance inside of their local network, you can simply use their hostname.

I hope this will help!

  • 1
    Thank you. I understand little of how DNS work. I was hoping there was a way to have something like hostname.googlecloud.com without changing anything in the client. May 25, 2018 at 11:54

You can specify your own hostnames in your VM instances.

There are 2 easy ways.

  1. Create a Custom Metadata entry hostname with value my.hostname.com

Then I call it on my centos servers like this :

hostname $(curl --silent "http://metadata.google.internal/computeMetadata/v1/instance/attributes/hostname" -H "Metadata-Flavor: Google")

Result is hostname set as per your meta data.

  1. Through the Google DHCP service that assigns your static internal IP's

I create a file "google_hostname.sh" in "/etc/dhcp/dhclient.d" (Using CentOS) Content of the file looks like this :

google_hostname_config() {
google_hostname_restore() {

The result is, upon Google assigning your ephemeral internal IP upon a reboot it will also do the hostname.

More info: The following article explains that the "hostname" is part of the default metadata entries and it is not possible to manually edit any of the default metadata pairs. As such, you would need to use a script or something else to change the hostname every time the system restarts, otherwise it will automatically get re-synced with the metadata server on every reboot.

You can find information on startup scripts for GCE in this article. You can visit this one for info on how to apply the script to an instance.


You can now create a GCE VM with a custom hostname. Please find this help center article for more details.

However, as mentioned in the limitations, you cannot change a custom hostname after you have created the VM


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.