5

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.

  • 1
    Have you tried to provide the --static flag to hostnamectl command? – Valentin Bajrami Sep 8 '16 at 14:50
  • Changed answer to comment: Did you update the /etc/hostname file? – colbyt Sep 8 '16 at 15:19
  • @val0x00ff yes but reverts too – DiogoSaraiva Sep 8 '16 at 16:05
  • Does sp-30.localdomain mean anything to you? Any idea where that hostname may have come from? Understanding why that specific wrong hostname is being set may be essential to fixing this issue. – Charley Sep 9 '16 at 3:52
  • @Charley that was the name i gave to the public cloud OVH instance. – DiogoSaraiva Sep 12 '16 at 15:58
3

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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.