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
For an example if you wanted your hostname to be
yourserver01.example.com 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:
You should also update your
/etc/hosts file to reflect the change. For an example:
127.0.0.1 yourserver01.example.com localhost localhost.localdomain