Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have a redhat (EL5) server that I need to change the hostname on. I'm trying to put it back into a known state to help with server provisioning activities.

As part of changing the hostname, I'm updating /etc/sysconfig/network and /etc/hosts. I also have an explicit call to hostname. My desired state is that the server thinks its hostname is "localhost". And a call to "hostname" returns "localhost".

The problem I'm having is that when I reboot, the hostname is reverted to "" which is not what I want. How do I ensure that the hostname is set up as just "localhost" when I reboot?

My /etc/sysconfig/network file contains:

GATEWAY= #I do have a proper IP address here

My /etc/hosts file contains:       localhost.localdomain   localhost     localhost
share|improve this question
Can't say that naming your server localhost is the wisest course of action. – Tux May 7 '10 at 20:26
  1. Change the ^HOSTNAME line in /etc/sysconfig/network
  2. Change the hostname (FQDN and alias) in /etc/hosts
  3. Run /bin/hostname new_hostname for the hostname change to take effect immediately.
  4. Run /sbin/service syslog restart for syslog to log using the new hostname.

A reboot is not required to change the system hostname, of course you should reboot in order to verify your issue is solved :)

More information at

Your error is in the second line of /etc/hosts! just remove it.

share|improve this answer
And some apps pull the host name at startup and not again. Rebooting is a good way to restart everything at once. – McJeff May 7 '10 at 20:41
service --full-restart will accomplish that without a reboot, although at that point you might as well. – Rodger May 7 '10 at 21:50

If you have set a static IP make sure that IP is set in /etc/hosts along with your desired hostname.

After setting the desired hostname in /etc/sysconfig/network, it would not save or persist after reboot until the IP I had set for the machine in /etc/sysconfig/network-scripts/ifcfg-eth0 or /etc/sysconfig/network-scripts/ifcfg-eno1 on CentOS 7 and my desired hostname were on the same line in /etc/hosts.

Just as this answer suggests:

Edit: I read the proper way to set the hostname in Centos7 / RedHat 7

hostnamectl set-hostname
share|improve this answer

Something else to consider, some VPS providers use virtualization technologies that take control of the networking and hostname, so you will need to use their control panel in order to change the hostname.

share|improve this answer

Your Answer


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