Open the file
/etc/sysconfig/networkusing your favorite editor, auted as root or using sudo. We'll use nano for this example.
nano -w /etc/sysconfig/network
The file will contain something along the lines of this:
In order to change the hostname, you need to edit the
HOSTNAMEvalue. For an example if you wanted your hostname to be
server1.example.comyou would set it to:
Once you have set the desired hostname, save the changes and close the editor. If you used nano, this is done by pressing CTRL+x and then Enter to write/save the modified file. The new hostname will not be applied until your next reboot.
If you would like to temporarily apply the new hostname (until the next reboot), you can use the hostname command:
In order to verify the new hostname, simply issue the command on it's own:
In order for your new hostname to resolve properly, you should also update your
/etc/hostsfile to reflect the change. For an example:
127.0.0.1 server1.example.com localhost localhost.localdomain
source : centosforge.com