How to set hostname in Red Hat Linux
Set hostname

In order to set hostname on Red Hat Linux system, you should set the new name in two files :

Both the files are ASCII text files and can be edited by vi.

Edit /etc/hosts

Edit /etc/hosts file as root user to change old hostname or add new hostname. IP address should also be added in the same line where you have added/changed the hostname. ping uses local /etc/hosts for name resolution if DNS is not used and may not work if hostname is not correctly set here. A sample /etc/hosts file is below :     localhost

Here, the name of the machine is node1 and is the domain name. Domain name is optional.

Edit /etc/sysconfig/network

Edit /etc/sysconfig/network file as root user and set HOSTNAME parameter to appropriate name.

cat /etc/sysconfig/network

Use the hostname command to set the new name to the running instance. You do not require the server to be rebooted.

# hostname

Use hostname command to make sure that the hostname is set.

$ hostname