microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.54k stars 823 forks source link

Unable to save resolv.conf #9070

Closed glasko-dp closed 2 years ago

glasko-dp commented 2 years ago

Version

Microsoft Windows [Version 10.0.19045.2130]

WSL Version

Kernel Version

5.10.102.1

Distro Version

Debian 11

Other Software

No response

Repro Steps

  1. Create /etc/wsl.conf
  2. Add: [network] generateResolvConf = false
  3. Close terminal
  4. Open windows command prompt
  5. Run wsl --shutdown
  6. Open Debian terminal
  7. sudo vi /etc/resolv.conf
  8. Add nameserver 8.8.8.8
  9. Write & Quit (:wq)

Expected Behavior

After following instructions (that I've gleaned from delving through several other bugs related to name resolution issue in WSL2) to make resolve.conf changes permanent, I should be able to save the resolv.conf with the custom nameserver, and this should persist between restarts and reboots. As a bonus, name resolution will work from within WSL2.

Actual Behavior

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

Diagnostic Logs

No response

elsaco commented 2 years ago

@glasko-dp after you created /etc/wsl.conf and restart, /etc/resolv.conf no longer points to /run/systemd/resolve/stub-resolv.conf:

root@RIPPER:~# file /etc/resolv.conf
/etc/resolv.conf: broken symbolic link to ../run/systemd/resolve/stub-resolv.conf

Just remove the broken link and create a new /etc/resolv.conf with your settings.

OneBlue commented 2 years ago

Thanks for reporting this @glasko-dp.

If generateResolvConf is set to false then the /etc/resolv.conf will point to a file that doesn't exist. @elsaco's solution of simply deleting the file should solve the issue.