Assigning Hostname to Linux System
This article provides the steps required to give a name to your linux installation. By default the hostname  is localhost, you can follow these steps to change it to some other name.
There are two ways to change the hostname of the machine
Temporary Hostname Change
- Issuing command hostname
Changing the hostname of the linux/CENTOS machine, issue the following command
hostname master.cluster.com
Doing this will change the hostname to master.cluster.com but this change will be effective until the end of current session and would be lost once the machine is rebooted.Â
Permanent Hostname Change
- Adding an entry for hostname in /etc/hosts file
You can add an entry for hostname in the /etc/hosts file using the editor by issuingÂ
vi /etc/hosts
Contents of host file looks like below
127.0.0.1Â Â localhost localhost.localdomain localhost4 localhost4.localdomain4
::1Â Â Â Â Â Â Â Â localhost localhost.localdomain localhost6 localhost6.localdomain6
You can add a line to the bottom to include the ip address and the hostname as shown by highlighted text
127.0.0.1Â Â localhost localhost.localdomain localhost4 localhost4.localdomain4
::1Â Â Â Â Â Â Â Â localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.21 master.node.com                         Â
- Changing the Hostname in /etc/sysconfig/network file
You should change the value of Hostname variable in /etc/sysconfig/network by editing the file usingÂ
vi /etc/sysconfig/network
Open your /etc/sysconfig/network file, locate the HOSTNAME line and change the hostname to your preferred node name.
NETWORKING=yes           Â
HOSTNAME=master.node.com      Â
.Now when you restart the machine it will have the hostname setup in the host file.