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:
192.168.0.1 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:
192.168.0.1 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:
Where is the hostname alias persistent, if not /etc/hosts (so it can survive a reboot).
Why can it only be changed once per boot?
More information: It is a RHEL 6.2 server.