Centos – How to change hostname on CentOS 6.5

centoshostname

I can't seem to change the hostname on my CentOS 6.5 host.
I am following the instructions I found here: http://www.rackspace.com/knowledge_center/article/centos-hostname-change

I set my /etc/hosts like so …

    [root@mig-dev-006 ~]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain 
    192.168.32.128  ost-dev-00.domain.com ost-dev-00
    192.168.32.129  ost-dev-01.domain.com ost-dev-01

… then I make my /etc/sysconfig/network file like so …

    [root@mig-dev-006 ~]# cat /etc/sysconfig/network
    NETWORKING=yes
    HOSTNAME=ost-dev-00.domain.com
    NTPSERVERARGS=iburst

… then I run hostname like so …

    [root@mig-dev-006 ~]# hostname ost-dev-00.domain.com

… and then I run bash and all seems well …

    [root@mig-dev-006 ~]# bash

… but when I restart my network the old hostname comes back:

    [root@ost-dev-00 ~]# /etc/init.d/network restart
    Shutting down interface eth0:  Device state: 3 (disconnected)
                                                               [  OK  ]
    Shutting down loopback interface:                          [  OK  ]
    Bringing up loopback interface:                            [  OK  ]
    Bringing up interface eth0:  Active connection state: activating
    Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/6
    state: activated
    Connection activated
                                                               [  OK  ]
    [root@ost-dev-00 ~]# bash
    [root@mig-dev-006 ~]# 

… I can't figure it out. What am I doing wrong here.

Best Answer

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