My first frustration with Ubuntu 18.04 came yesterday. I created a template VM with my basic toolkit that any machine in my network should have. I then deployed the VM and asked vSphere to set the hostname to the value of the VM name. Strangely, this didn’t happen: The new machine booted up alright, but its name remained that of the template.
Remember the old way to manually change the name of a machine in Linux? It went something like this:
- Add the new hostname to your
/etc/hosts
so sudo doesn’t get confused. - Replace the old hostname in
/etc/hostname
with the new one. - Reboot the computer or restart all affected services.
The new way goes like this:
- Add the new hostname to your
/etc/hosts
so sudo doesn’t get confused. - Replace the old hostname in
/etc/hostname
with the new one. - Reboot the computer.
- Notice that the hostname is the same as it was before you attempted to change it.
- Web search “change hostname ubuntu 18.04”.
- Discover that there’s a new utility,
hostnamectl
, which has a command,change-hostname
, that takes the new hostname as an argument. - Run
hostnamectl change-hostname [newname]
- Run
hostnamectl
without any arguments to confirm that “Static hostname” has the correct value. - Log off and back on again and be happy that everything seems to be working.
- Reboot the computer after doing some changes.
- Notice that the hostname is back to what it was.
- Run
hostnamectl change-hostname [newname]
again, and check in/etc/hostname
just to see that it actually did change the file to contain the new hostname. - Check in
/etc/hosts
and see that the new name appears there too. - Scour the web some more for additional information.
- Find some mention of
cloud-init
. - Read up on it and see the point of it – but also that it doesn’t apply to my current environment.
- Run
sudo apt remove cloud-init
- Reboot the server and see that it works as expected again.
- (In the future: Learn more about cloud-init and re-evaluate whether it should be implemented in my environment as a complement to Ansible).