resolv.conf 每次都会被覆盖

resolv.conf 每次都会被覆盖

我懂了

drwxrwxr-x 3 root tunnel 100 date and time .
drwxr-xr-x 33 root root 860 date and time …
-rwxrwxr-x 1 root tunnel 0 date and time enable-updates
drwxrwxr-x 2 root tunnel 40 date and time interface
-rwxrwxr-x 1 root tunnel 151 date and time resolv.conf

然后我跑

sudo chown --recursive root:tunnel run/resolvconf
sudo chmod --recursive 775 /run/resolvconf

然后我明白了

drwxrwxr-x 3 root tunnel 100 date and time .
drwxr-xr-x 33 root root 860 date and time …
-rwxrwxr-x 1 root tunnel 0 date and time enable-updates
drwxrwxr-x 2 root tunnel 40 date and time interface
-rwxrwxr-x 1 root tunnel 151 date and time resolv.conf

但几秒钟或重新启动后,所有标志和文件 resolv.conf 都被覆盖,我再次得到这个

ls -al /run/resolvconf
total 4
drwxrwxr-x  3 root tunnel 100 date and time .
drwxr-xr-x 33 root root   860 date and time ..
-rw-r--r--  1 root root     0 date and time enable-updates
drwxrwxr-x  2 root tunnel  40 date and time interface
-rw-r--r--  1 root root   151 date and time resolv.conf

我不能聊天

chattr: Operation not supported while reading flags on /etc/resolv.conf

这是 resolv.conf 的 cat

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND – YOUR CHANGES WILL BE OVERWRITTEN

答案1

正如它所写的,每次启动或重新启动网络管理器恶魔时,resolv.conf 文件都会被覆盖

如果你想保留静态 DNS,你必须在 /etc/network/interfaces 文件中添加以下行:

dns-nameservers xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx

在我的示例中,您必须替换xxxx.xxxx.xxxx.xxxx为所需 DNS 的 IP 地址。您可以以8.8.8.8Google8.8.4.4的 DNS 为例。

问候,

答案2

/etc/resolv.conf只是一个符号链接,因为您resolvconf的系统上默认安装了软件包ls -al /etc/resolv.conf

/etc/resolv.conf -> /etc/resolvconf/run/resolv.conf

这就是你收到chattr: Operation not supported while reading flags on /etc/resolv.conf错误的原因。

删除/etc/resolv.conf然后重新创建。

rm /etc/resolv.conf # or use unlink command
nano /etc/resolv.conf # etdit your file
chattr +i /etc/resolv.conf

答案3

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

chattr -V +i filename e.g chattr -V +i /etc/resolv.conf

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

chattr -i filename - to re-enable insert to the file

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

相关内容