2

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?

1

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 "111.111.111.111 my.whateveriwant-hostname.tld" | sudo tee -a /etc/hosts ( Assuming that 111.111.111.111 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!

  • 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. – Ricardo Cruz May 25 '18 at 11:54
2

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 :

#!/bin/bash
google_hostname_config() {
  google_set_hostname
}
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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