7

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

terdon
  • 98,183
  • 15
  • 197
  • 293
iec2011007
  • 518
  • 2
  • 6
  • 12
  • 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. – terdon Apr 03 '15 at 13:42

6 Answers6

8

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

storm
  • 4,943
  • 6
  • 35
  • 48
Graham Leggett
  • 361
  • 1
  • 3
  • 6
4

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

Sergiy Kolodyazhnyy
  • 103,293
  • 19
  • 273
  • 492
  • The OP is already using `sudo su`, then `vi` to edit the file. – slhck Apr 03 '15 at 08:09
  • He asked what is the proper way of editing `/etc/resolv.conf`, which is what I answered. – Sergiy Kolodyazhnyy Apr 03 '15 at 08:12
  • 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 – iec2011007 Apr 03 '15 at 08:14
  • Well, in that case you have two separate questions there. Can you edit using sudo any other file ? – Sergiy Kolodyazhnyy Apr 03 '15 at 08:16
  • 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 Apr 03 '15 at 08:17
  • Which type of file like at what location – iec2011007 Apr 03 '15 at 08:18
  • 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](http://askubuntu.com/q/327532/295286) – Sergiy Kolodyazhnyy Apr 03 '15 at 08:23
  • Um, what else you could try is [reconfigure for dynamic updates](http://askubuntu.com/a/172517/295286) – Sergiy Kolodyazhnyy Apr 03 '15 at 08:27
  • 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 – iec2011007 Apr 03 '15 at 08:34
  • Very well. If you opened a file owned by root and it is editable , then that means there's no problem with sudo. Weird that your resolv.conf is set to rw permission for the owner. Can you `sudo chmod +x /etc/resolv.conf` ? Go ahead and try adding `nameserver 8.8.8.8` to tail or head file, save and reboot. That should let you get you use internets. Among other things, look here : http://askubuntu.com/a/90263/295286 – Sergiy Kolodyazhnyy Apr 03 '15 at 08:56
1

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

  • Follow these commands:

    $sudo nano /etc/resolv1.conf
    

    Add following:

    nameserver 8.8.8.8
    nameserver 8.8.4.4
    
  • Save it and then hit following commands:

    $sudo rm /etc/resolv.conf
    $sudo mv /etc/resolv1.conf /etc/resolv.conf
    
  • No need of Reboot. Now refresh your webpage. It will work now.

Artur Meinild
  • 21,605
  • 21
  • 56
  • 89
1

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.

jdthood
  • 12,287
  • 2
  • 48
  • 66
0
sudo apt-get purge resolvconf

then reboot, then you need to install it again

sudo apt-get install resolvconf

This worked for me

0

I had this exact same problem, and finally resolved it by allowing the ICMP protocol at our Cisco ASA-5540 edge router.

Turns out that if the protocol is not allowed, pings in AND out, are both blocked. It caused a great deal of trouble for us when using CPAN, as some fetches would fail.

Kevin Bowen
  • 19,395
  • 55
  • 76
  • 81