You can specify your own hostnames in your VM instances.
There are 2 easy ways.
- 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.
- 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.