Centos – Google Compute Engine Cent OS change hostname

centosgoogle-cloud-platformgoogle-compute-engine

Title says it all really – I want to change the hostname of a Google Compute Engine Cent OS instance.

I have tried the normal method…

  • in /etc/sysconfig/network set HOSTNAME=my.new.hostname
  • in /etc/hosts set 127.0.1.1 my.new.hostname
  • reboot

I have tried setting a hostname key/value pair in the Custom metadata of the Compute Engine VM Instance admin page.

Nothing sticks. Seems to use the instance name as hostname.

Best Answer

By default there is a start up script which sets the hostname according to the metadata of that instance.
See: https://github.com/GoogleCloudPlatform/compute-image-packages/tree/master/google-startup-scripts

Sets the hostname from the metadata server via DHCP exit hooks.
Related Topic