0

This question already has an answer here:

I modified /etc/resolv.conf to configure DNS for my VPN. Now I would like to modify it again but I can't. The operation is not permitted even if I use

sudo nano /etc/resolv.conf

I tried to start in recovery mode but I have the same problem. How can I restore this file?

marked as duplicate by George Udosen, Eric Carvalho, Kevin Bowen, TheWanderer, Stormvirux Aug 21 '17 at 16:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Please check the file permission: ll /etc/resolv.conf – George Udosen Aug 18 '17 at 19:12
0

Just change permissions temporarily:

sudo chmod 744 /etc/resolv.conf

Add nameservers of your VPN provider by editing the file with text editor:

nameserver ip_of_nameserver_one
nameserver ip_of_nameserver_two

Save the file,then revert permissions.

sudo chmod 644 /etc/resolv.conf
sudo chattr +i /etc/resolv.conf

The last command will add immutable bit, so the file doesn't get overwritten. After you set immutable bit, even the root account will not be able to write to the file. If you wish to edit the file again latter on, and remove immutable bit, use this command:

sudo chattr -i /etc/resolv.conf
  • there is no need to use chmod to modify system files. Just use sudo for that. – Zanna Aug 18 '17 at 21:56
  • @Zanna Indeed. But I've added, because OP said he is unable to edit files due permission. – fugitive Aug 18 '17 at 22:33
  • 1
    Yeah but if sudo doesn't work chmod won't work, unless permissions were already set incorrectly... OP won't be the only one reading this. Chmodding system files is generally bad practice and I just wanted to comment to point that out to other readers. Apart from unnecessarily making it executable I don't have any issue with the settings you suggested, but as OP says, the exattr was the issue and chmod shouldn't be needed or used – Zanna Aug 18 '17 at 23:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.