On RHEL and similar distributions such as CentOS and OEL you can set the hostname by adding a hostname entry in /etc/sysconfig/network.
HOSTNAME=hydrogen.lan
If you don't have such an entry, the system will fall back to the default behaviour - referencing the hostname configured on the first matching entry in /etc/hosts.
192.168.92.101 hydrogen.lan hydrogen
Now, my question is. Are there any good reasons to use the direct hostname configuration in /etc/sysconfig/network or is it simply redundant in most scenarios?
The box in your example will have hydrogen.lan as its hostname, not hydrogen.
The only way I know of to have
hostname
return the short hostname and to havehostname -f
return the FQDN, is to use both the mentioned options.So add
HOSTNAME=mybox
to /etc/sysconfig/network and addto /etc/hosts. I like having
hostname
andhostname -f
return different things. By default, Anaconda sets it up like you have it set up now.It will stop the hostname mysteriously changing when someone adds another entry (for a new web site, perhaps) to /etc/hosts (or eighteen months later when the machine is rebooted).
If the hostname is changed accidentally (by someone typing hostname then fat-fingering the return key) you can see what to change it back to.
Running "hostname myhost" from the command line immediately changes the hostname.
I define the short or full hostname by editing /etc/sysconfig/network in order to make the name persistent across reboots.
Adding an entry in /etc/hosts with the system's IP address and FQDN and short name makes the hostname consistent for services that rely on it (apache, lpd, sendmail, etc.)
the hostname command always worked for me just type
man hostname