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 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 :
127.0.0.1 localhost 192.168.1.21 node1.prajeeth.com
Here, the name of the machine is node1 and prajeeth.com is the domain name. Domain name is optional.
Edit /etc/sysconfig/network file as root user and set HOSTNAME parameter to appropriate name.
cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=node1.prajeeth.com GATEWAY=192.168.1.1
Use the hostname command to set the new name to the running instance. You do not require the server to be rebooted.
# hostname node1.prajeeth.com
Use hostname command to make sure that the hostname is set.
$ hostname node1.prajeeth.com