无法编辑resolv.conf

iec*_*007 5 networking resolv.conf

我正在使用 Ubuntu 14.04,我必须编辑resolv.conf文件

所以这就是我想要做的

sudo su

vi /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)

但是当我尝试编辑它时说该文件是只读的

当我尝试这样做chmod +w /etc/resolv.conf时会出现错误Operation not permitted

如何编辑它。我必须编辑,因为这台笔记本电脑是公司给我的,他们配置了名称服务器,但是当我尝试在家里使用它时,我的 wifi 虽然已连接但我无法使用互联网。

如果我 ping 8.8.8.8 它正在工作

Gra*_*ett 8

在 CentOS8 上偶然发现这个问题。

该文件可能被标记为不可变:

# lsattr /etc/resolv.conf
----i--------------- /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)

删除不可变标志,如下所示:

# sudo chattr -i /etc/resolv.conf
# lsattr /etc/resolv.conf
-------------------- /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)

来源:https ://forums.centos.org/viewtopic.php?t=73182#p307891


Ser*_*nyy 4

如果要将行添加nameserver xxx.xx.xxx.xxx/etc/resolvconf/resolv.conf.d. 它们属于 root,但您可以使用 sudo 编辑它们(如果您喜欢图形文本编辑器,则可以使用 gksu )。

尽管您要求编辑resolv.conf,但在ubuntu中还有另一种不涉及resolv.conf的发送dns的方法。看看我的/etc/dhcp/dhclient.conf文件的第 18 行。第 19 行也是一种实用的方法。

1   # Configuration file for /sbin/dhclient, which is included in Debian's
     2  #   dhcp3-client package.
     3  #
     4  # This is a sample configuration file for dhclient. See dhclient.conf's
     5  #   man page for more information about the syntax of this file
     6  #   and a more comprehensive list of the parameters understood by
     7  #   dhclient.
     8  #
     9  # Normally, if the DHCP server provides reasonable information and does
    10  #   not leave anything out (like the domain name, for example), then
    11  #   few changes must be made to this file, if any.
    12  #

    13  option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

    14  #send host-name "andare.fugue.com";
    15  send host-name = gethostname();
    16  #send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
    17  #send dhcp-lease-time 3600;
    18  supersede domain-name-servers 208.67.222.222,208.67.220.220,8.8.8.8;
    19  # prepend domain-name-servers 208.67.222.222,208.67.220.220;
    20  request subnet-mask, broadcast-address, time-offset, routers,
    21      domain-name, domain-name-servers, domain-search, host-name,
    22      dhcp6.name-servers, dhcp6.domain-search,
    23      netbios-name-servers, netbios-scope, interface-mtu,
    24      rfc3442-classless-static-routes, ntp-servers,
Run Code Online (Sandbox Code Playgroud)

这会设置我的 dns 并让我浏览网页(并且 nnm-tool 命令确认所有三个 dns 均已使用),无论我在 resolv.conf 中写什么。所以试试这个


jdt*_*ood 1

如果您使用标准 Ubuntu,那么答案是:不要编辑 /etc/resolv.conf,而是使用 resolvconf 方法来配置写入 resolv.conf 的内容。AskUbuntu 中还有其他文档和其他答案,涵盖了如何做到这一点。

如果您使用的计算机是您公司以非标准 Ubuntu 方式配置的(例如,为了不使用 resolvconf 来管理 resolv.conf),那么您应该向您公司的 IT 支持部门寻求指示。假设这些说明确实涉及编辑 /etc/resolv.conf,您应该 (1) 确保 /etc/resolv.conf 不是符号链接,或者删除该符号链接(如果存在);然后执行(2)sudo vi /etc/resolv.conf并编辑文件。