0

I recently tried changing an Ubuntu machine hostname. After a reboot, I found the name was reverted to it's previous one.

A quick search suggested this was happening because of cloud-init. If I change the setting preserve_hostname to true, the hostname will persist.

However I found that system updates can possible cause the setting to revert back to false resulting in the hostname reverting as well.

I would like to know if it is possible to change the hostname permanently without any change to cloud-init settings. In other words, where does cloud-init save the original hostname and how to change it?

vidarlo
  • 6,654
  • 2
  • 18
  • 31
GKman
  • 495
  • 3
  • 9
  • 16

1 Answers1

0

Write something like below, change the permission so content will be persistent.

write_files:
  - path: /<your path>/hostname.cfg
    permissions: '<your permission>'
    content: |
      preserve_hostname: true

Other way will be make your host file immutable after first time creation.

asktyagi
  • 2,860
  • 2
  • 8
  • 25