Can not edit resolv.conf

32,043

Solution 1

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

Solution 2

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

Solution 3

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.

Solution 4

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.

Share:
32,043

Related videos on Youtube

iec2011007
Author by

iec2011007

Updated on September 18, 2022

Comments

  • iec2011007
    iec2011007 over 1 year

    I am using Ubuntu 14.04 and I have to edit the resolv.conf file

    So this is what I am trying to do

    sudo su
    
    vi /etc/resolv.conf
    

    But when I try to edit it says the file is read only

    When I try to do chmod +w /etc/resolv.conf it gives the error Operation not permitted

    How to edit it. I have to edit as this laptop was given to me by company and they configured the nameserver but when I try to use it at home then my wifi though connected but I am not able to use Internet.

    If I ping 8.8.8.8 it is working

    • Admin
      Admin about 9 years
      By the way, there's never any reason to run sudo su. If you have activated the root account, use su alone and if not, use sudo -i to get a root shell. sudo su is pointless.
  • Mantra
    Mantra about 9 years
    The OP is already using sudo su, then vi to edit the file.
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy about 9 years
    He asked what is the proper way of editing /etc/resolv.conf, which is what I answered.
  • iec2011007
    iec2011007 about 9 years
    I already told that with using sudo also I am not able to change the content it says operation not permitted please help me to edit
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy about 9 years
    Well, in that case you have two separate questions there. Can you edit using sudo any other file ?
  • iec2011007
    iec2011007 about 9 years
    The nameserver which I want to add "127.0.0.1" is present in base but then also I am not able to access internet. Ping og 8.8.8.8 is successful
  • iec2011007
    iec2011007 about 9 years
    Which type of file like at what location
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy about 9 years
    Well, how about /etc/bash.bashrc ? What happens when you try to sudo su and then vi /etc/bash.bashrc ? by the way, what is the output of ls -l /etc/resolv.conf ? As for your "127.0.0.1" nameserver, you might want to read this question
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy about 9 years
    Um, what else you could try is reconfigure for dynamic updates
  • iec2011007
    iec2011007 about 9 years
    For ls it says -rw-r--r-- 1 and trying the above commands opened the file and it is editable while without sudo it is not
  • Dan M. CISSOKHO
    Dan M. CISSOKHO over 3 years
    thank you , you saved my day