linux centos 7 vps云服务器修改/etc/hosts文件不起效果,重启后自动恢复原状导致域名解析失效
linux centos 7 vps云服务器修改/etc/hosts文件不起效果,重启后自动恢复原状导致域名解析失效问题描述
实际上就是系统预装了cloud-init这个东西,开机后自动执行初始化导致
cloud-init --version
/usr/local/bin/cloud-init 22.1
查看hosts文件发现
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.redhat.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
# The following lines are desirable for IPv6 capable hosts
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
网上疯传错误的解决办法
打开编辑 vi /etc/cloud/cloud.cfg 文件
preserve_hostname,该选项改为true
正确的解决办法
找到 update_etc_hosts,该选项之前添加注释符号即可解决
一键修改
sed -i 's/ - update_etc_hosts/# - update_etc_hosts/g' /etc/cloud/cloud.cfg
学习了,感谢大佬!
页:
[1]