Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I've seen a few ways of changing hostnames of domain names. One way is to issue the hostname command followed by the name such as:

hostname localhost.localdomain

/etc/sysconfig/network also has a hostname field, but changing that does not affect the output of the hostname command.

My question is, where is each of these used, which do I care about and why? What's the proper way of setting the hostname?

share|improve this question
up vote 1 down vote accepted

If you set your hostname in /etc/sysconfig/network then the system will automatically set your hostname for you every time you boot.

This magic is done in /etc/rc.d/rc.sysinit. It does this using the hostname command in the third line below:-

# Set the hostname.
update_boot_stage RChostname
action $"Setting hostname ${HOSTNAME}: " hostname ${HOSTNAME}
[ -n "${NISDOMAIN}" ] && domainname ${NISDOMAIN}

The variable HOSTNAME is defined in /etc/sysconfig/network.

If you set it manually using the hostname command, then it will not be persistent over a re-boot.

share|improve this answer
I actually don't have the rep to upvote this.... It sounds legit, though I'd like to confirm/ look into the /etc/rc.d/rc.sysinit script. Thanks a lot! – user2555465 Jun 20 '14 at 14:59

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.