Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On RHEL and similar distributions such as CentOS and OEL you can set the hostname by adding a hostname entry in /etc/sysconfig/network.


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. 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?

share|improve this question
up vote 2 down vote accepted

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 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.

share|improve this answer
I don't think it works that way. If the HOSTNAME= is set, that will be the FQDN regardless of what is in /etc/hosts. Your example will have hostname and hostname -f both return "mybox", at least on OEL5U4 where I just tested it. – Roy Dec 5 '09 at 11:35
You are quite right on the hostname being set to hydrogen.lan if that is the first none named in /etc/hosts. Going to try to reverse those and see what happens :) – Roy Dec 5 '09 at 11:41
Ok, reversing the order in /etc/hosts will give "hydrogen" as the hostname and FQDN. It also very much seems like the HOSTNAME= entry will override anything in /etc/hosts for both hostname and FQDN. – Roy Dec 5 '09 at 11:45
Note that having a fully qualified hostname does not seem to break anything. dhclient presents itself to the dhcp server with hostname only, as does the login prompt and the command prompt. – Roy Dec 5 '09 at 11:47

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.

share|improve this answer

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.)

share|improve this answer
Sure, but may I ask why you choose to set the hostname in /etc/sysconfig/network rather than let the system get it's hostname directly /etc/hosts? – Roy Dec 5 '09 at 18:16

the hostname command always worked for me just type man hostname

share|improve this answer
Simply using hostname(1) will not make the change persistent. – Roy Dec 5 '09 at 9:53
There was no mention of persistency being a requirement. And in any case, these days you have to switch to using hostnamed – dyasny Jul 17 '15 at 8:30
Nah, we'll be on Oracle Linux 6 for many years yet. Systemd 25 can go away and stay there, as far as I'm concerned. – Roy Jul 17 '15 at 14:10
Oracle Linux? Good luck with that – dyasny Jul 18 '15 at 11:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.