Can not edit resolv.conf

The proper way to edit resolv.conf if to add nameserver xxx.xx.xxx.xxx lines to either base, head, or tail files in /etc/resolvconf/resolv.conf.d . They belong to root, but you can edit them with sudo ( or gksu if you prefer graphical text editors ).

Although you ask for editing resolv.conf, there's another way to sent dns in ubuntu that doesn't involve resolv.conf. Look at the line 18 of my /etc/dhcp/dhclient.conf file. Line 19 is also a practical way to do it.

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,

This sets my dns and lets me browse webs (and nnm-tool command confirms all three dns are used) no matter what i write in my resolv.conf. So try this


Stumbled on this problem on CentOS8.

The file may be marked immutable:

# lsattr /etc/resolv.conf
----i--------------- /etc/resolv.conf

Remove the immutable flag as follows:

# sudo chattr -i /etc/resolv.conf
# lsattr /etc/resolv.conf
-------------------- /etc/resolv.conf

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


If you are using standard Ubuntu then the answer is: Don't edit /etc/resolv.conf but use resolvconf methods to configure what gets written to resolv.conf. There is other documentation and there are other answers in AskUbuntu which cover how to do that.

If you are using a machine that your company has configured other than in standard Ubuntu ways (e.g., so as not to use resolvconf to manage resolv.conf) then you should ask your company IT support department for instructions. Assuming that these instructions really do involve editing /etc/resolv.conf, you should (1) make sure that /etc/resolv.conf is not a symbolic link or remove the symbolic link if it's there; then do (2) sudo vi /etc/resolv.conf and edit the file.


I guess you are having a red color resolv.conf in /etc/

  • Add these commands:

    sudo nano resolv1.conf nameserver 8.8.8.8

  • Save it.

    sudo rm resolv.conf sudo mv resolv1.conf resolv.conf

  • Reboot.

That should be Ok.