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
3 Answers
Root Cause:
- /etc/resolv.conf file has immutable flag
Solution:
- Remove the immutable flag using following command:
sudo chattr -i /etc/resolv.conf

- 181
- 1
- 5
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.

- 11
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.

- 141
- 2
-
-
Then, install resolvconf package
sudo apt install resolvconf
Follow the procedure in this answer. After adding nameserver to the file run this
– vicki Oct 03 '20 at 13:34sudo systemctl start resolvconf.service
. This should do it. If not, then it should be enabled by running,sudo systemctl enable resolvconf.service
.
/etc/resolv.conf
is a managed configuration file. Simply editing it fails. Readman -a resolvconf;man -a resolv.conf;man dnsmasq
. – waltinator Oct 02 '20 at 23:56When 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/etc/resolv.conf
- it saysThis 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