10

unable to update resolv.conf file.

"/etc/resolv.conf" E166: Can't open linked file for writing

ubuntu 18.04.1

JackyChan
  • 184
  • 1
  • 1
  • 10
  • Where or why did you get that error message? If it is in `vim` (which you haven't specified) E166 can be found in http://vimdoc.sourceforge.net/htmldoc/message.html – guiverc Sep 03 '18 at 13:10
  • Thanks for reply! i managed to to resolve issue the filesystem was mount with ro and user was not with root permission. – JackyChan Sep 03 '18 at 13:11

3 Answers3

5

This is an assumption that you're asking about a vim error message (you didn't specify where you got the error message).

Vim documentation reports E166 as

E166 Can't open linked file for writing

You are trying to write to a file which can't be overwritten, and the file is a link (either a hard link or a symbolic link). Writing might still be possible if the directory that contains the link or the file is writable, but Vim now doesn't know if you want to delete the link and write the file in its place, or if you want to delete the file itself and write the new file in its place. If you really want to write the file under this name, you have to manually delete the link or the file, or change the permissions so that Vim can overwrite.

http://vimdoc.sourceforge.net/htmldoc/message.html

guiverc@d960-ubu2:~$   stat /etc/resolv.conf 
  File: /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
  Size: 39          Blocks: 0          IO Block: 4096   symbolic link
Device: 801h/2049d  Inode: 130757      Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-09-03 12:34:28.189468370 +1000
Modify: 2017-11-16 12:32:04.777265492 +1100
Change: 2017-11-16 12:32:04.777265492 +1100

A stat of my /etc/resolv.conf confirms the file is a link.

I can happily write to that file (using sudo) so you have an issue beyond what you've provided.

guiverc
  • 28,623
  • 5
  • 46
  • 74
  • 1
    In my case it links to `./resolv.conf -> ../run/resolvconf/resolv.conf`. Either way, how do I fix the problem? The file and folder it links to do not exist. I can not `cd ../run/resolvconf/`. Says no such file or directory... – muuh Jun 10 '21 at 12:44
  • `/run/systemd/resolve/stub-resolv.conf` exists on my current system (likely the same box I was using with the answer; only it's running *impish* now where it would have been *cosmic* then). If you used "../run" in a command it would have been interpreted as a *relative location* (ie. relative to $PWD) which is different to the intention of the command output. You're likely best asking a new question though, – guiverc Jun 10 '21 at 12:52
3

In my case it worked when I used sudo while opening resolv.conf file through vi. If file is not already present then it creates one.

$ sudo vi /etc/resolv.conf
ThunderBird
  • 1,915
  • 13
  • 19
  • 31
3

if /etc/resolv.conf is a symbolic link, you won't be able to write it. If you want to overwrite the content in the file, remove the file and then create a new fi

  1. Remove symbolic link
sudo rm /etc/resolv.conf
  1. Write to new file. E.g.
sudo echo "nameserver 8.8.8.8"  > /etc/resolv.conf
Gabriel Ziegler
  • 1,426
  • 2
  • 14
  • 23