Centos – Configuring the hostname on Red Hat Enterprise Linux

centosnetworkingredhat

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?

Best Answer

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 have hostname -f return the FQDN, is to use both the mentioned options.

So add HOSTNAME=mybox to /etc/sysconfig/network and add

10.10.10.10 mybox.example.com mybox 

to /etc/hosts. I like having hostname and hostname -f return different things. By default, Anaconda sets it up like you have it set up now.