6

I'm trying to set a hostname with hostnamectl set-hostname server.domain.tld in CentOS 7 but when I reboot it returns to sp-30.localdomain

Always i used that command to change hostname but now is not working, so or i'm missing somethinh or is some bug?

However, how can i change permanently my hostname?

Before rebooting I check /etc/hostname file and its correct but when I reboot it reverts

"SP-30" was the name I gave to the instance in OVH public cloud.

DiogoSaraiva
  • 409
  • 4
  • 16

2 Answers2

4

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

DiogoSaraiva
  • 409
  • 4
  • 16
  • This worked for me too, but the changes weren permanent after i uncommented those two lines in the cloud.cfg. There has got to be an official puppet way for this, but im not finding it. – Brian Thomas Aug 17 '18 at 21:52
0

Not sure about CentOS, but I also ran into this problem on Ubuntu Server. Resolved with:

sudo apt-get remove cloud-init
Sharky
  • 1