Change Hostname CentOS

The Following is a Verified Turtorial on How to Change the Hostname on CentOS 5.2, CentOS 5.3, Centos 5.4, and CentOS 5.6  Last Used in 2011.

When you are changing the host name in CentOS you need to change it in several locations.  Please follow the instructions closely as not changing the host name correctly can stop certain web devices from working properly.

Step 1. Identify the Hostname

The first thing you need to do is to find the computers fully qualifier domain name (FQDN) and to see how the maching identifies itself.

# uname -n
Will show you what your current hostname is.

# dnsdomainname

Will show you what your current DNS name is (note for servers which are hosting multiple websites though virtual hosts this is often left blank)

Step 2. Change the Hostname

There are a couple of different ways to change the host name, some are redundant, which is ok with us as we have found that if you do not change the host name in all of the following locations that CentOS will some times not fully change it within its files.  It is recommended that you execute all of the following.

 

1. Edit the /etc/sysconfig/network and change the hostname

# vi /etc/sysconfig/network

NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=servername.yourdomain.com

Change the HOSTNAME= to your new desired host name

2. Run System Config

# system-config-network

The screen will show a navigational area.  Select Edit DNS configuration and edit the hostname and select OK and then Save&Quit.

âââââââ⤠Select Action âââââââ
â
â  Edit a device params
â  Edit DNS configuration
â
â
â
â  âââââââââââââ  ââââââââ
â  â Save&Quit â  â Quit
â  âââââââââââââ  ââââââââ
â
â
âââââââââââââââââââââââââââââââ

 

3. Change the hostname in your hosts file

# vi /etc/hosts

# Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 hostname.yourdomain.com hostname localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6

3. Reboot or Force the Computer to Update.

The following will force the computer to update, it is better to restart the computer but this will work in most situations.

# source /etc/sysconfig/network
# hostname $HOSTNAME

 

If you have any questions about his tutorial please comment below as we all get better if we combine our thoughts.  -mf

No comments yet.

Leave a Reply