1. 程式人生 > >騰訊雲centos服務器修改/etc/hosts,使其重啟不失效

騰訊雲centos服務器修改/etc/hosts,使其重啟不失效

添加 發現 with zed 還原 -h centos服務 lac local

騰訊雲centos服務器修改/etc/hosts,使其重啟不失效
  • 使用騰訊雲的服務器,我修改了/etc/hosts文件,然後操作了一下重啟操作後,一打開/etc/hosts文件便如以下:
## template:jinja
{#
This file (/etc/cloud/templates/hosts.tmpl) is only utilized
if enabled in cloud-config.  Specifically, in order to enable it
you need to add the following to config:
   manage_etc_hosts: True
-#}
# 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.tmpl
# b.) change or remove the value of ‘manage_etc_hosts‘ in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
#
{# The value ‘{{hostname}}‘ will be replaced with the local-hostname -#}
127.0.1.1 {{fqdn}} {{hostname}}
127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
  • 然後發現之前配置的本地hosts消失了,後面認真看了下修改方式和常規的直接修改方式的不一樣,直接只對/etc/hosts文件進行修改後,重啟系統後添加的記錄就還原了。
  • 文件註釋大致說法,我的系統配置了manage_etc_hosts為True,如果要修改hosts的話
a. 需要先對/etc/cloud/templates/hosts.redhat.tmpl進行修改(可以將需要修改的hosts替換掉);
b. 然後修改/etc/cloud/templates/hosts.redhat.tmpl文件中的manage_etc_hosts的值或刪除manage_etc_hosts的值在/etc/cloud/cloud.cfg文件中;
  • 最後測試了下,重啟主機已經不會重置hosts了

騰訊雲centos服務器修改/etc/hosts,使其重啟不失效