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

In order to have an alias for my server, which can be seen in a "hostname -a" command, I edited the /etc/hosts file to add the alias at the end of the entry containing the hostname.

For example, my hostname is host1 and I want to have alias hostalias, I have below entry in /etc/hosts: host1 hostalias

With this change I am able to use "hostname -a" to see hostalias.

However, I can change it only once! If I edit the file /etc/hosts again to something like this: host1 hostalias2

the output of "hostname -a" is still hostalias.

Even after I remove the hostalias2 and reboot the server, it's still saying hostalias.

BUT, if I change the alias the first time after reboot, it takes effect.

So in fact I have two questions:

  1. Where is the hostname alias persistent, if not /etc/hosts (so it can survive a reboot).

  2. Why can it only be changed once per boot?

More information: It is a RHEL 6.2 server.

share|improve this question
Which operating system? – Ignacio Vazquez-Abrams Jun 25 '13 at 10:05
Possibly you have a name service cache daemon. Try after sudo nscd -i hosts (to invalidate the host cache). – Stéphane Chazelas Jun 25 '13 at 13:11
@StephaneChazelas Thanks Stephane, it is indeed caused by name service cache. – cutemic Oct 10 '13 at 4:32

If you are on Fedora / RHEL / CentOS, the hostname is set by the rc.sysinit script after retrieving the desired value from the /etc/sysconfig/network file.

As to why it can only be changed once per boot - it can be changed anytime. You have to provide a new hostname to the hostname command to change it, just editing a file won't do so. Keep in mind though that if you change it this way, any programs that were running before you changed it may still have the old value cached.

share|improve this answer
yes, it is RHEL. But it is not about changing hostname, but adding hostname alias via the /ect/hosts file. – cutemic Oct 8 '13 at 10:40
up vote 2 down vote accepted

@StephaneChazelas is right in the comment.

Possibly you have a name service cache daemon. Try after sudo nscd -i hosts (to invalidate the host cache). I can't make a comment the answer of a question so I answer this question myself.

share|improve this answer

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.