Resolving Etc Resolv Conf E166: Can’t Open Linked File for Writing Error

Resolving Etc Resolv Conf E166: Can't Open Linked File for Writing Error

When attempting to modify the /etc/resolv.conf file, you might encounter the error message E166: Can't open linked file for writing. This issue typically arises because /etc/resolv.conf is a symbolic link to another file that either doesn’t exist or cannot be accessed for writing.

Understanding the Error

The error message '/etc/resolv.conf' E166: Can't open linked file for writing typically occurs due to issues with file permissions or symbolic links. Here’s a breakdown:

  1. File Permissions: The file /etc/resolv.conf might not have the necessary write permissions. This can happen if the file is owned by a different user or if it is set to read-only. You can check and modify permissions using commands like chmod and chown.

  2. Symbolic Links: /etc/resolv.conf is often a symbolic link to another file managed by a system service (e.g., systemd-resolved). If the target file of the symbolic link is missing or if the link itself is broken, you will encounter this error. To resolve this, you might need to recreate the symbolic link or ensure the target file exists and is accessible.

Common Causes

Here are the common causes of the /etc/resolv.conf E166 error:

  1. Read-only file systems: If the file system where /etc/resolv.conf resides is mounted as read-only, you won’t be able to write to it.
  2. Improper file permissions: If the file permissions do not allow writing, you will encounter this error. Ensure the file has the correct permissions (e.g., -rw-r--r-- for regular users or -rw-rw-r-- for group write access).
  3. Symbolic link issues: If /etc/resolv.conf is a symbolic link pointing to a non-existent or incorrect target, writing to it will fail.

Troubleshooting Steps

Sure, here’s a step-by-step guide to troubleshoot and resolve the /etc/resolv.conf E166 error:

  1. Check File Permissions:

    ls -l /etc/resolv.conf
    

    Ensure the file has the correct permissions. It should be writable by root:

    sudo chmod 644 /etc/resolv.conf
    

  2. Verify Symbolic Links:

    ls -l /etc/resolv.conf
    

    If /etc/resolv.conf is a symbolic link, verify its target:

    readlink /etc/resolv.conf
    

    If the link is broken, remove it and create a new file:

    sudo rm /etc/resolv.conf
    sudo touch /etc/resolv.conf
    

  3. Ensure File System is Not Read-Only:

    mount | grep ' / '
    

    Check if the root filesystem is mounted as read-only. If it is, remount it as read-write:

    sudo mount -o remount,rw /
    

  4. Edit /etc/resolv.conf:

    sudo nano /etc/resolv.conf
    

    Add your DNS settings, for example:

    nameserver 8.8.8.8
    nameserver 8.8.4.4
    

  5. Restart Network Services:

    sudo systemctl restart networking
    

This should help resolve the issue.

Preventive Measures

  1. Disable NetworkManager DNS Updates:

    • Create /etc/NetworkManager/conf.d/90-dns-none.conf with:
      [main]
      dns=none
      

    • Reload NetworkManager:
      systemctl reload NetworkManager
      

  2. Manual DNS Configuration:

    • Create a custom DNS file, e.g., /etc/resolv.conf.custom.
    • Link it to /etc/resolv.conf:
      ln -sf /etc/resolv.conf.custom /etc/resolv.conf
      

  3. Regular Maintenance:

    • Backup /etc/resolv.conf before changes.
    • Verify DNS settings periodically.
    • Ensure no conflicting services (e.g., systemd-resolved) are managing DNS.

These steps should help prevent the error and maintain a stable DNS configuration.

The ‘/etc/resolv.conf E166: Can’t open linked file for writing’ Error

The ‘/etc/resolv.conf E166: Can’t open linked file for writing’ error typically occurs due to issues with file permissions, symbolic links, or read-only file systems.

Resolving the Issue

  1. Check and modify file permissions using ‘chmod’ and ‘chown’
  2. Verify and recreate symbolic links if necessary
  3. Ensure the file system is not mounted as read-only
  4. Edit ‘/etc/resolv.conf’ with correct DNS settings
  5. Restart network services
  6. Disable NetworkManager DNS updates
  7. Perform manual DNS configuration

Prevention and Regular Maintenance

Regular maintenance such as backing up ‘/etc/resolv.conf’ before changes and verifying DNS settings periodically can also help prevent this error.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *