To change the hostname in CentOS, you will first need to update the hostname line in the /etc/sysconfig/network file.
Once that is changed, you will want to add the IP address for the hostname to /etc/hosts.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
Then, you need to restart network for the changes to take affect.
service networking restart
Once that is done, you should be able to use the hostname command and it should show the new hostname that you set. On my test box I did have to restart the box for it to take affect, so if you don’t see the changes, you may need to reboot.
[[email protected] ~]# hostname