Unable to change hostname in Ubuntu 18.04 server on Virtualbox
What I’ve tried:
sudo hostnamectl set-hostname ubuntu-1
echo ‘ubuntu-1’ > /etc/hostname
Sadly, whenever I reboot
the hostname changes back to what it was originally.
This can be solved by changing preserve_hostname to true in /etc/cloud/cloud.cfg
To reiterate:
- Set preserve_hostname true in /etc/cloud/cloud.cfg
- Update hostname
sudo hostnamectl set-hostname ubuntu-1
reboot