Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
  • in /etc/hosts set
  • 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 '14 at 14:12
@Peter - there is no /etc/hostname file – Billy Moon Apr 13 '14 at 14:35
@Peter /etc/hostname will be used in RHEL 7, but RHEL 6 uses /etc/sysconfig/network. – Michael Hampton Apr 13 '14 at 14:49

By default there is a start up script which sets the hostname according to the metadata of that instance.

Sets the hostname from the metadata server via DHCP exit hooks.
share|improve this answer
I'm getting 404 page. And is there a way to change that? I'd like that the hostname to be a FQDN hostname. – el.severo Jul 2 at 16:43

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.



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

Change hostname in Google Compute Engine (Cent OS)

Step 1

# nano /etc/sysconfig/network

Step 2: Create crontab auto set Hostname

# crontab -e
@reboot hostname=""; sed -i "s/.*Google.*//" /etc/hosts; hostname "$hostname"

Step 3

# reboot

Step 4: Add below

# nano /etc/hosts
share|improve this answer

Your Answer


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.