Force the hostname on Cloud-init

Use hostnamectl

$ sudo hostnamectl set-hostname [hostname]

Check for the existence of /etc/cloud/cloud.cfg configuration. If it exists edit the file and change the settings within:

FROM:

  • preserve_hostname: false

TO:

  • preserve_hostname: true

The output should be:

$ hostnamectl
       Static hostname: [hostname]
            Icon name: computer-vm
            Chassis: vm
            Machine ID: ceb8b579410b472899a95049f8a61e05
            Boot ID: 3f73eea15fb34a38937488149143d9d3
            Virtualization: (Something, like Proxmox)
      Operating System: Ubuntu Bionic Beaver
            Kernel: Linux 4.13.0-32-generic
            Architecture: x86-64

After that, edit /etc/hosts just like usually