https://blog.csdn.net/valark/article/details/118708929
修改了 /etc/host 文件,然而重启电脑就发现里面的内容还原了。
一直百思不得其解,仔细一看,发现/ etc/hosts 最上方的注释写着:
原来是wsl会自动生成这一文件,而它也给出了停止自动生成的方法:
sudo vi /etc/wsl.conf
添加如下代码:
[network]
generateHosts = false
保存退出,然后重启电脑发现,/etc/hosts 中修改的内容并没有被重置。
遇到这样的情况,仔细看一下/etc/hosts的注释文件,可以找到一些线索解决问题
比如下面这份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 C20240928134767.local C20240928134767
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
# The following lines are desirable for IPv6 capable hosts
::1 C20240928134767.local C20240928134767
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
按照这个说明,只要修改/etc/cloud/templates/hosts.redhat.tmpl,以后即便自动还原也还原成了模板,就不会发生改变了