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.

READ  How to Listen Radio Online Free

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.

4 comments
  1. James
    James
    May 17, 2013 at 3:39 am

    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.

    Reply
    • James
      James
      May 17, 2013 at 3:57 am

      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.

      Reply
Leave a Reply

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

SiteGround.com

A world leading hosting company that provides fully-managed innovative and secure solutions, suitable for hosting small to medium-sized websites

Built on the best available technologies combined with Google Cloud for strong redundancy and application availability. Backed by skilled experts to address web security threats, a devops team to create advanced custom security solutions, and 24/7 sysadmins to watch over the platform. This powerful, hands-on approach makes your sites faster, safer, and easier to manage. Starting from only $3.95/mo.

TRY FREE

* up to 30 days money back guarantee