错误写入 /etc/resolv.conf 操作不允许

错误写入 /etc/resolv.conf 操作不允许

我写入 sudo nano /etc/resolv.conf 终端并添加名称服务器 8.8.8.8 名称服务器 8.8.4.4 但它给出错误操作不允许所以我无法访问网站如何修复错误

答案1

根本原因:

  • /etc/resolv.conf 文件具有不可变标志

解决方案:

  • 使用以下命令删除不可变标志:
sudo chattr -i /etc/resolv.conf

来源: https://support.tools/post/fix-stuck-resolv-conf/

答案2

就我而言,我正在使用自动化来修改此配置文件,并在服务器设置期间看到类似的错误。

对我来说,问题在于文件属性。不知何故,文件/etc/resolv.conf获得了i属性,这意味着文件无法被修改。

来自 chattr 文档(https://man7.org/linux/man-pages/man1/chattr.1.html):

i      A file with the 'i' attribute cannot be modified: it
       cannot be deleted or renamed, no link can be created to
       this file, most of the file's metadata can not be
       modified, and the file can not be opened in write mode.
       Only the superuser or a process possessing the
       CAP_LINUX_IMMUTABLE capability can set or clear this
       attribute.

对我来说,修复方法是以 root 用户身份运行此程序:

chattr -i /etc/resolv.conf

您可以使用以下lsattr命令检查它是否已经起作用:

[root@hostname ~]# lsattr /etc/resolv.conf
----i--------e-- /etc/resolv.conf
[root@hostname ~]# chattr -i /etc/resolv.conf
[root@hostname ~]# lsattr /etc/resolv.conf
-------------e-- /etc/resolv.conf

这只是对我有用的解决方案。发布只是为了以防其他人也遇到此问题。我建议运行该lsattr命令以查看这是否适用于您。

答案3

resolve.conf 是包自动生成的文件resolvconf

cd /etc/resolvconf/resolv.conf.d

有一个head文件。首先创建 head 文件的备份。然后编辑 head 文件以添加名称服务器。

sudo nano head

不要更改其余部分并忽略警告。转到文件末尾,添加所需的名称服务器。nameserver ip_here然后生成 conf 文件

sudo resolvconf -u

检查名称服务器是否已添加到/etc/resolve.conf,然后重新启动。即使重新启动后,名称服务器仍会存在。

resolve.conf 是静态页面,可以使用 resolvconf 包添加名称服务器

这是手册页解析配置

看看是否有帮助。

相关内容