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

36,621

Solution 1

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.

Solution 2

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

Solution 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
Share:
36,621
JackyChan
Author by

JackyChan

Updated on September 18, 2022

Comments

  • JackyChan
    JackyChan over 1 year

    unable to update resolv.conf file.

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

    ubuntu 18.04.1

    • guiverc
      guiverc over 5 years
      Where or why did you get that error message? If it is in vim (which you haven't specified) E166 can be found in vimdoc.sourceforge.net/htmldoc/message.html
    • JackyChan
      JackyChan over 5 years
      Thanks for reply! i managed to to resolve issue the filesystem was mount with ro and user was not with root permission.
  • muuh
    muuh almost 3 years
    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...
  • guiverc
    guiverc almost 3 years
    /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,