I want to change the hostname of a Ubuntu 18.04 server.

I did:

hostnamectl --set-hostname newname --static
changed /etc/hostname file to newname
cahnged /etc/hosts file to newname
rm -f /etc/machine-id
dbus-uuidgen --ensure=/etc/machine-id
dbus-uuidgen --ensure
dpkg-reconfigure openssh-server

Finally I did a reboot. But after reboot there is still the old hostname. The file /etc/hostname has been changed to the old hostname.

How to permanently change the hostname?

  • hi. did you try "hostname newname" as root?
    – jpbrain
    Sep 15 at 1:36
  • yes, of course all commands as root Sep 15 at 1:47

Additionally I had to change the file /etc/cloud/cloud.cfg

There is a setting preserve_hostname: false

I had to change that from false to true. After rebbot hostname had changed.

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.