Setting or Changing hostname of a CentOS host

How to set or change your host name in CentOS

Open the file /etc/sysconfig/network using your favorite editor,  I like nano.
[root@yourServer~]# sudo nano -w /etc/sysconfig/network

The file will look something like this:

To change the hostname, you need to edit the HOSTNAME value.
For an example if you wanted your hostname to be you would set it to:

Once you have set the desired hostname, save the changes and close the editor.
In nano this is done by pressing CTRL+x  then Y followed by  Enter to write the modified file. Your new hostname will not be applied until your next network restart.
[root@yourServer~]# sudo reboot

In order to verify the new hostname, simply issue the command on it’s own:
[root@yourServer~]# hostname

You should also update your /etc/hosts file to reflect the change. For an example: localhost localhost.localdomain

Loading Facebook Comments ...

Leave a Reply

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