How to change hostname on CentOS 6.5?

to change the hostname permanently, you need to change it in two places:

vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=newHostName

and: a good idea if you have any applications that need to resolve the IP of the hostname)

vi /etc/hosts 
127.0.0.1 newHostName
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

and then

 rebooting the system

A solution for CentOS 7 can be found here:

hostnamectl set-hostname <new hostname>

You can change your hostname with a single command.

  • Command: hostname - this displays old hostname
  • Command: hostname <new name> -this sets new hostname

Example

$ hostname mynewhost

For persisting the new hostname across reboot

edit /etc/sysconfig/network file to look like below

NETWORKING=yes
HOSTNAME=myhostanme

For video help

  • https://www.youtube.com/watch?v=0qdoj9r-8to