1

I write sudo nano /etc/resolv.conf terminal and add nameserver 8.8.8.8 nameserver 8.8.4.4 but it gives error operation not permitted so I could not reach websites how to fix the error

imren
  • 29
  • What OS & release are you using? – guiverc Oct 02 '20 at 23:36
  • You should ask about the actual problem that you have instead of your attempted solution. You're more likely to recieve an answer if you are detailed and specific when explaining how to reproduce your problem and describing exactly what happens on your device: https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/66378#66378 – Nmath Oct 02 '20 at 23:45
  • With supported Ubuntu, /etc/resolv.conf is a managed configuration file. Simply editing it fails. Read man -a resolvconf;man -a resolv.conf;man dnsmasq. – waltinator Oct 02 '20 at 23:56
  • ubuntu 18.04.04 also I am trying to solve my problem for a long time.My computer connected to wifi but I am not reach web site because resolv.conf file is empty so ı want to add nameserver to reach networking but it gives operation not permitted – imren Oct 03 '20 at 00:15
  • I wrongly deleted nameserver from resolv.conf. After I delete, my Internet has gone.It is connecting Wi-Fi network but I couldn't reach any website.

    When I write the terminal sudo nano /etc/resolv.conv the file is empty.

    I want to add nameserver 8.8.8.8 and nameserver 8.8.4.4 in resolv.conf file but I am getting the error:

    /etc/resolv.conf: Operation not permitted

    – imren Oct 03 '20 at 00:18
  • finally Can anybody give me real solution please ? – imren Oct 03 '20 at 00:19
  • Read the first line of /etc/resolv.conf - it says This file is managed by man:systemd-resolved(8). Do not edit.. All you need to do to restore it to normal is to reboot. As mentioned, you can't edit this file. Please use edit to keep your question up to date. It can become confusing to have to supplement your question with comments. – Nmath Oct 03 '20 at 00:26

3 Answers3

7

Root Cause:

  • /etc/resolv.conf file has immutable flag

Solution:

  • Remove the immutable flag using following command:
sudo chattr -i /etc/resolv.conf

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

Jerry Chong
  • 181
  • 1
  • 5
1

In my case, I was using automation to modify this configuration file and was seeing a similar error during the setup of a server.

The problem for me came down to file attributes. Somehow the /etc/resolv.conf had gained the i attribute which means the file cannot be modified.

From the chattr docs (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.

The fix for me was running this as the root user:

chattr -i /etc/resolv.conf

And you can check it has worked using the lsattr command:

[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

This is just the solution that worked for me. Posting just incase anyone else find themselves on this thread. I'd recommend running the lsattr command to see if this applies to you.

max
  • 11
0

resolve.conf is an autogenerated file by resolvconf package.

cd /etc/resolvconf/resolv.conf.d

There is a head file. First create a backup copy of head file. Then edit the head file so the nameserver is added.

sudo nano head

Do not change the rest and ignore warnings. Go to the end of the file, and add the nameservers you need. nameserver ip_here. Then generate the conf file

sudo resolvconf -u

Check if the nameserver is added to /etc/resolve.conf, then reboot. The nameservers will be there even after reboot.

resolve.conf are static pages and nameservers can be added using resolvconf package

Here is the manpage for resolvconf

See if this helps.

vicki
  • 141
  • 2
  • hi,sudo resolvconf -u command not found – imren Oct 03 '20 at 11:23
  • Then, install resolvconf package sudo apt install resolvconf

    Follow the procedure in this answer. After adding nameserver to the file run this sudo systemctl start resolvconf.service. This should do it. If not, then it should be enabled by running, sudo systemctl enable resolvconf.service.

    – vicki Oct 03 '20 at 13:34