Renaming hostname in Ubuntu Server 18.04

  • For those who installed Ubuntu Server 18.04 using the new installer from (ubuntu-18.04-live-server-amd64.iso), you will notice that renaming the hostname is not preserved after a reboot.

    You'll find that you will need to change preserve_hostname: from false to true in /etc/cloud/cloud.cfg.

    Now you can change your hostname using sudo hostnamectl set-hostname <new-hostname> and will stay put after a reboot.

    Here's a one-liner command to change the preserve_hostname setting to true and to set a new hostname

    sudo sed -i '/preserve_hostname: false/c\preserve_hostname: true' /etc/cloud/cloud.cfg; sudo hostnamectl set-hostname YourNewHostname

  • That sounds just stupid.

  • @jaredbusch said in Renaming hostname in Ubuntu 18.04:

    That sounds just stupid.

    It was pissing me off trying to figure out why it didn't keep the new name.

  • Looks like I will not be using any Ubuntu based systems if I can help it... I'm liking Debian 9 rather well right now.

Log in to reply