hostname doesn't persist after reboot in CentOS 7 instance

Solution 1:

I found that my CentOS 7 Instance uses Cloud-Init every reboot and it sets to originally given hostname every time I reboot the instance.

I found a solution here:

https://www.ovh.pt/g1928.hostname

Which tells that and to get around must have to deactivate an cloud-init module with: manage_etc_hosts: false in /etc/cloud/cloud.cfg file, and then hostname to whatever you want.

But since my /etc/cloud/cloud.cfg file was different I just deleted:

- set_hostname
- update_hostname

under cloud_init_modules and it worked for me