To change host name in CentOS use following steps:
Open /etc/sysconfig/network file
$ vim /etc/sysconfig/network
Now modifiy HOSTNAME= value
my.domain.com is desired host for my machine, similarly we can use other valid domain names.
Next edit /etc/hosts file, here we need to change the host that is associated to your main IPaddress for your server.
192.168.1.10 my.domain.com my
After completing above two changes restart network by using following command:
$ service network restart
Now run hostname command:
Above procedure will work both in CentOS 5 and 6 versions.