大网数据广告活动
服务器运维问答

hostname doesn't persist after reboot in CentOS 7 instance

· 52CE 我爱测

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 so…

问题原文

原帖链接 · DiogoSaraiva · CC BY-SA 3.0

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 · CC BY-SA 3.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。