Changing the hostname of your RHEL/CentOS server

So, after finding the hostname command doesn’t do the whole job, it was quite important that this setting would survive a reboot!

# hostname

Edit the /etc/sysconfig/network file so that the “HOSTNAME” variable is set to your new hostname:


It is a good idea to add an entry in /etc/hosts for this hostname (saves going out to the internet only to return back again): localhost.localdomain localhost localhost4.localdomain4 localhost4 testbox

Alternatively if you require to point outside for some reason then do something like the following and change your ip address to your public/network ip: testbox

I added two entries above, this allows you to either use or just testbox as a destination (i.e. ssh testbox).


Restart (r)syslog and crond. Check to see if it is now showing the correct hostname:

# service crond restart
# service *syslog restart
# tail /var/log/messages

/var/log/messages should now have changed the hostname to the new one.

If you are running an SMTP server on this host you could see what it returns:

# telnet localhost 25

It should say something like:

220 ESMTP Postfix