Perform the steps below as root or sudo
- Change the HOSTNAME in /etc/sysconfig/network to desired new hostname
- Change the hostname in /etc/hosts. (Add to the same line as localhost)
- Source /etc/sysconfig/network
- Type hostname $HOSTNAME
- logout and log back in.
TIP: If you would like to strip off the domain name portion, which is stored elsewhere anyway.
- sed -i.bak 's/\.[a-z].*//g' /etc/sysconfig/network
Reference
http://www.how2centos.com/centos-change-the-hostname/