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 - 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.


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?

migrated from serverfault.com May 5 '15 at 1:44

This question came from our site for system and network administrators.

  • Is the server using dhcp? – jordanm May 4 '15 at 13:24
  • Not enough rep to add a comment. Have you tried hostname.sh? – DCJeff May 4 '15 at 13:29
  • Not using dhcp. – dan983 May 4 '15 at 13:30
  • How are you checking what the hostname is? Are you just going off of what the prompt says? When you SSH into the server, do echo $PS1. I highly doubt someone has changed it, but you never know .... – Safado May 4 '15 at 14:58
  • I just issue 'hostname' after the reboot and it shows the old host name. It's a bit strange because it doesn't happen when I change the hostname on a VM. – dan983 May 4 '15 at 15:07
hostnamectl set-hostname servername.example.com

That's for RHEL 7 that is.

  • Same happened to my Debian setups. thx. – erm3nda Feb 25 at 12:40

/etc/hosts is meant as a first-step for DNS resolution. If you're trying to reach a host that's present there, it will use that record instead of querying DNS.

As you've discovered, /etc/hostname is one option for hostname changes in Debian. In RHEL6, it's /etc/sysconfig/network, and in RHEL7 it's either the hostnamectl command or /etc/hostname.

Changing hostnames on Linux hosts can vary by distribution and release, so it's best to Google the procedure for your particular platform.


Try setting runtime kernel parameter

sudo bash -c "echo 'kernel.hostname = YOUR_HOSTNAME' >> /etc/sysctl.conf"

Apply your changes with

sudo sysctl -p

Now simply, logout and log back in, your hostname should be the one you applied.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.