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.
The hostname Command
You can use this command to see the current name of the system.
You can also use this command to change the name of the machine.
# hostname smallhat.putorius.net
Then issue the hostname command again to see the changes.
This only makes a temporary or non-persistent change. If you reboot the system the changes will revert.
The /etc/sysconfig/network configuration file
This is the 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 name.
After making changing to the configuration file you need to restart the network service in order to read that file.
NOTE: Do not do this remotely (via ssh) or you will lose your connection.
If you issue the hostname command now, you will see that it has changed.
The /proc/sys/kernel/hostname entry
Another simple way is to echo the new name 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 make permanent changes. 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 newer versions of Fedora please read our updated tutorial How to Change the System Hostname in Red Hat 7 or CentOS 7.
This site uses Akismet to reduce spam. Learn how your comment data is processed.