Linux – Changing hostname reboot reverts back to original

hostnamelinux

So, What I'm trying to do is simply change the hostname permanently. I can update the hostname but when a reboot is issued the original hostname is used!

I'm aware there is a file hostname located at: /etc/hostname. I update this file and issue a reboot, however the hostname is back to the previous setting!

What I've tried:

  1. Updating /etc/hosts file newhostname
  2. Updating hosts file – 127.0.0.1 newhostname
  3. reboot

I've also tried with sudo user and root!

Why is this happening?!

Thanks for any advice or suggestions, I feel like I've tried every other solution with no avail.

EDIT:

I've just updated the /etc/hostname file on a VM running debian 7 locally and it works as expected. Why doesn't this work when connected to a remote server with SSH?

Best Answer

hostnamectl set-hostname servername.example.com

That's for RHEL 7 that is.

Related Question