How to Change Hostname on CentOS 5.8

In this post, i will show you the basic guides on how to change the hostname on linux CentOS 5.8 server. Assumed that you have root account access on this CentOS server and this steps may working on RHEL 6, RHEl 5, CentOS 5.5, CentOS 5.6, CentOS 5.7, CentOS 6.0, CentOS 6.1 and CentOS 6.2.

1. Check current hostname :

[root@localhost ~]# hostname
localhost.localdomain

2. Modify “/etc/sysconfig/network” to change hostname :

[root@localhost ~]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain

Change the hostname to the following :

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=centos58.ehowtuff.local

Alternatively, you can execute the following command :

[root@localhost ~]# hostname centos58.ehowtuff.local

3. Change host file :

[root@localhost ~]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6

127.0.0.1 centos58.ehowstuff.local centos58

4. Reboot the server.

[root@localhost ~]# reboot

How to Change the Hostname on Linux CentOS 6.2 Server

In this post, i will show you on how to change the Hostname on linux CentOS 6.2. I have tested this on RHEL 6, CentOS 5.5 and CentOS 6.2. Reboot is required for both options (A) and (B) for the changes to take effect.

Check current hostname with this command :

[root@centos62 ~]# hostname --fqd
centos62.ehowstuff.local

Option A:
1. Modify /etc/sysconfig/network

[root@centos62 ~]# vi /etc/sysconfig/network

2. Edit to your preferred hostname :

NETWORKING=yes
HOSTNAME=NewHostname.ehowstuff.local

3. Modify /etc/hosts file as below :

[root@centos62 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.44 NewHostname.ehowstuff.local NewHostname

4. Save and reboot your server.

Option B:
1. Type the following command to enter GUI mode.

[root@centos62 ~]# system-config-network

2. Go to “DNS Configuration”.
Hostname

3. Modify your preferred hostname and click OK.
Hostname

4. Click ” Save & Quit”.
Hostname

5. Modify /etc/hosts file as below :

[root@centos62 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.44 NewHostname.ehowstuff.local NewHostname

6.Reboot your server.