debian 中的 /etc/hosts 在重启时会自行重置

debian 中的 /etc/hosts 在重启时会自行重置

我一直遇到一个问题,当我们的 vps 提供商决定重新启动服务器(运行 Debian 5.0.8)时,服务器无法记住对/etc/hosts.我所需要的只是一个用于服务器上的 Web 应用程序的数据库别名,该别名指向127.0.0.1( localhost)。

我希望它看起来像这样:

# The following lines are desirable for IPv6 capable hosts
# (added automatically by netbase upgrade)

::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


127.0.0.1 localhost.localdomain localhost webservice database
# Auto-generated hostname. Please do not remove this comment.
XXX.XX.XXX.XX xxxxxx.net.au  xxxxxx www.xxxxxxx.net.au xxxxxxx

但是,每当重新启动时,它都会将自身重置为:

# The following lines are desirable for IPv6 capable hosts
# (added automatically by netbase upgrade)

::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


127.0.0.1 localhost.localdomain localhost webservice
# Auto-generated hostname. Please do not remove this comment.
XXX.XX.XXX.XX xxxxxx.net.au  xxxxxx www.xxxxxxx.net.au xxxxxxx

没有数据库,我必须手动更改文件才能正常工作。这种情况已经发生了一段时间并且已经变得很麻烦,但我似乎找不到一种方法来让更改坚持下去。有人知道该怎么办吗?

答案1

删除 #Auto-generate hostname 行然后进行更改会导致生成主机名的任何内容现在都记住它。对我有用,但可能并不适合所有人。

答案2

这可能是因为您的系统使用 Cloud-init (https://cloudinit.readthedocs.io/en/latest/)。要重新获得对主机文件的控制,您必须编辑/etc/cloud/cloud.cfg 并将manage_etc_hosts 从“true”更改为“false”。

相关内容