I have a redhat (EL5) server that I need to change the hostname on. I'm trying to put it back into a known state to help with server provisioning activities.

As part of changing the hostname, I'm updating /etc/sysconfig/network and /etc/hosts. I also have an explicit call to hostname. My desired state is that the server thinks its hostname is "localhost". And a call to "hostname" returns "localhost".

The problem I'm having is that when I reboot, the hostname is reverted to "localhost.companyname.com" which is not what I want. How do I ensure that the hostname is set up as just "localhost" when I reboot?

If you have set a static IP make sure that IP is set in /etc/hosts along with your desired hostname.

After setting the desired hostname in /etc/sysconfig/network, it would not save or persist after reboot until the IP I had set for the machine in /etc/sysconfig/network-scripts/ifcfg-eth0 or /etc/sysconfig/network-scripts/ifcfg-eno1 on CentOS 7 and my desired hostname were on the same line in /etc/hosts.

Something else to consider, some VPS providers use virtualization technologies that take control of the networking and hostname, so you will need to use their control panel in order to change the hostname.