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.

See also  How to Allow and Deny Access for Remote SSH to CentOS 6.2

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.

Comments

2 Comments

  • Avatar James says:

    Good stuff. Thanks.
    One problem I encountered though: I followed the Option A instructions on my CentOS 6.4 server which resides in a VMWare 5 environment. Afterward, I could no longer copy and paste to or from the guest virtual machine to the host. I’m just now going to start figuring out the work around and will report back if I find something.

    • Avatar James says:

      Never mind; just needed Microsoft Repair Procedure #1: REBOOT. Once I completely shutdown and restarted my VMWare (as opposed to the ‘shutdown -r now’ command I used to activate the changes), the copy-paste problem went away but the changes remained intact.
      Thanks again for the straight forward and accurate instructions.

Leave a Reply

Your email address will not be published. Required fields are marked *