Leaderboard ad


How to change a machines hostname in Red Hat 6

There are several ways to change the hostname of a machine running Redhat 6.  These also works on CentOS, Fedora and older/other Redhat variants.

First: The "hostname" command.

You can use the hostname command to see the current host name of the system.

# hostname

You can also use the hostname command to change the host name of the machine.

# hostname smallhat.putorius.net

Then issue the hostname command again to see the changes.
# hostname

This only makes a temporary or non-persistent change of hostname.

Second: The /etc/sysconfig/network configuration file. (preferred method)

In order for the change to survive a reboot, or to make it persistent, you must change it in the /etc/sysconfig/network file.

Open the file in your favorite editor and change the following line to reflect your desired hostname.


After making changing to the configuration file you need to restart the network service in order to read that file.

/etc/init.d/network restart
NOTE: Do not do this remotely (via ssh) or you will lose your connection.

If you issue the hostname command now, you will see the hostname has changed. 

Third: The /proc/sys/kernel/hostname entry.

Another simple way to change the hostname is to echo the hostname into the /proc/sys/kernel/hostname file.

echo "bighat.putorius.net" > /proc/sys/kernel/hostname

NOTE: Using the /etc/sysconfig/network file is the preferred method to set the permanent hostname of a system.  Anything in the /proc/sys/kernel/hostname file will be overridden by the /etc/sysconfig/network file during a reboot. 

If you are using Red Hat 7 (RHEL7), CentOS 7 or newed versions of Fedora click below of instructions on changing your hostname.


  1. This doesn't work.

    1. It sure does, maybe we can help if you would be more specific.

    2. it still shows the old name until logout, even after restart network on rhel6.8

    3. you have to restart bash itself to make the changes visible there (exec bash)

  2. Yeah, this definitely works. Thanks for the info! Was so sick of the stupid default hostname given by my company.

  3. try restarting your machine

  4. Please, perform all steps (including the last one)..... It really works !

  5. Thanks, quick and easy!

  6. its not working for me do all the baove steps and after reseting service it comes up with old name.

    1. Which service are you restarting? Did you try to log out and log back in? Did you try to reboot?

    2. try editing /etc/hosts file along with the one mentioned above and then start network service

  7. It work for me after reboot the machine

  8. hostname changed ,but /var/log/messages still showing old hostname

    any idea without system restart solve this issue ???