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.
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:
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
.
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.
Here are the common causes of the /etc/resolv.conf
E166 error:
/etc/resolv.conf
resides is mounted as read-only, you won’t be able to write to it.-rw-r--r--
for regular users or -rw-rw-r--
for group write access)./etc/resolv.conf
is a symbolic link pointing to a non-existent or incorrect target, writing to it will fail.Sure, here’s a step-by-step guide to troubleshoot and resolve the /etc/resolv.conf
E166 error:
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
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
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 /
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
Restart Network Services:
sudo systemctl restart networking
This should help resolve the issue.
Disable NetworkManager DNS Updates:
/etc/NetworkManager/conf.d/90-dns-none.conf
with:[main]
dns=none
systemctl reload NetworkManager
Manual DNS Configuration:
/etc/resolv.conf.custom
./etc/resolv.conf
:ln -sf /etc/resolv.conf.custom /etc/resolv.conf
Regular Maintenance:
/etc/resolv.conf
before changes.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 typically occurs due to issues with file permissions, symbolic links, or read-only file systems.
file permissions
using ‘chmod’ and ‘chown’symbolic links
if necessaryfile system is not mounted as read-only
Regular maintenance such as backing up ‘/etc/resolv.conf’ before changes and verifying DNS settings periodically can also help prevent this error.