I am new to ubuntu and I am trying to change hostname of my ubuntu server 18.04.2 LTS. I've already changed /etc/hostname and /etc/hosts and rebooted. But it didn't work.

My files: /etc/hostname:


/etc/hosts: localhost.localdomain ubuntu-s2

::1 localhost6.localdomain6 localhost6

::1 localhost ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters ff02::3 ip6-allhosts

Is the only way to do it to change preserve hostname to true in /etc/cloud/cloud.cfg?


You are missing one thing:

hostnamectl set-hostname ubuntu-s2

After that, reboot. Your hostname will then be ubuntu-s2

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.