resolv.conf会在重新启动时重新写入



我正在配置一台fedora 21服务器,我已经基于以下链接设置了静态ip和dns

我正在使用编辑文件

vi /etc/resolv.conf

然后像上面提到的那样放我的dns。一切都很好。但在我重新启动后,文件被其原始内容改写了:

# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com

发生了什么,如何阻止这种情况的发生?

NetworkManager正在覆盖它。您可以关闭它并进入"手动"模式,那里有一些教程:http://xmodulo.com/disable-network-manager-linux.html

在fedora 26下,man NetworkManager.conf,上面写着:

rc-manager
           Set the resolv.conf management mode. The default value depends on NetworkManager build options, and this version of NetworkManager was build with a default of "symlink". Regardless of this
           setting, NetworkManager will always write resolv.conf to its runtime state directory /var/run/NetworkManager/resolv.conf.
           symlink: If /etc/resolv.conf is a regular file, NetworkManager will replace the file on update. If /etc/resolv.conf is instead a symlink, NetworkManager will leave it alone. Unless the symlink
           points to the internal file /var/run/NetworkManager/resolv.conf, in which case the symlink will be updated to emit an inotify notification. This allows the user to conveniently instruct
           NetworkManager not to manage /etc/resolv.conf by replacing it with a symlink.
           file: NetworkManager will write /etc/resolv.conf as file. If it finds a symlink, it will follow the symlink and update the target instead.
           resolvconf: NetworkManager will run resolvconf to update the DNS configuration.
           netconfig: NetworkManager will run netconfig to update the DNS configuration.
           unmanaged: don't touch /etc/resolv.conf.
           none: deprecated alias for symlink.

似乎没有必要更改任何配置文件。

我只是在那里放了一个符号链接,它就起作用了。

使用以下命令防止resolv.conf或任何文件在重新启动后被覆盖

chattr -V +i filename

例如:chattr -V +i /etc/resolv.conf

要恢复更改,请使用以下命令:

chattr -i filename-重新启用插入文件

chattr(更改属性)是一个命令行Linux实用程序,用于在Linux系统中设置/取消设置文件的某些属性,以确保意外删除或修改重要文件和文件夹,即使您是以root用户身份登录。

相关内容

  • 没有找到相关文章

最新更新