Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
What is the value in /etc/hostname? –  Peter Apr 13 at 14:12
    
@Peter - there is no /etc/hostname file –  Billy Moon Apr 13 at 14:35
    
@Peter /etc/hostname will be used in RHEL 7, but RHEL 6 uses /etc/sysconfig/network. –  Michael Hampton Apr 13 at 14:49
    

2 Answers 2

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.
share|improve this answer

Have you tried hostname(1) ?

Hostname is the program that is used to either set or display the current host, domain or node name of the system. These names are used by many of the networking programs to identify the machine.

hostname
xyzzy.example.com

hostname plugh.example.com

hostname
plugh.example.com
share|improve this answer
    
I did try that, and it works until the machine is rebooted :( –  Billy Moon Apr 13 at 14:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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