0

My /etc/wsl.conf:

[network]
generateResolvConf = false

And yet my /etc/resolv.conf continues to regenerate. I specify:

nameserver 8.8.8.8

Only to find it changed to:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.29.128.1

Note: I tried the solutions suggested below, none of them helped:

Why does my resolv.conf file get regenerated every time?

Ya.
  • 249
  • 2
  • 6
  • 14
  • What release Ubuntu are you running in WSL? resolv.conf is a generated file these days, usually systemd, but it uses 127.0.0.53 for its nameserver, so you must be using something else to manage your network. – ubfan1 Jan 27 '24 at 16:38
  • @ubfan1 Ubuntu 20.04.6 LTS – Ya. Jan 27 '24 at 21:00
  • @Terrance Indeed: ls -al /etc/resolv.conf lrwxrwxrwx 1 root root 29 Dec 19 2022 /etc/resolv.conf -> ../run/resolvconf/resolv.conf – Ya. Jan 27 '24 at 21:01
  • 1
    In this case, @Ya. shows they're using the resolvconf not the newer systemd-resolved. You can follow the top answer's second last paragraph editing /etc/resolvconf/, or the last paragraph replacing the symlink with a regular file. – Daniel T Jan 27 '24 at 22:16
  • @DanielT Yep, you are correct. It has been a while since I have even messed with the resolvconf but for some reason the systemd was the first thing that came to my mind. – Terrance Jan 27 '24 at 23:33
  • @Daniel T Nope. Tried both prepending name server in dhcp as well as installing resolvconf. – Ya. Jan 28 '24 at 00:49
  • Also tried replacing the symlink with a regular file. – Ya. Jan 28 '24 at 00:57
  • @Ya. So what happens with ls -al /etc/resolv.conf when you replace it with a regular file? – Daniel T Jan 28 '24 at 00:58
  • It stays until I open or close any window to WSL or reload my vscode. Then it gets overwritten to 172... It is not being reset to the sym link. – Ya. Jan 28 '24 at 01:02
  • Btw. I've updated the question to include the additional lines in resolv.conf. Sorry, I should have done it to begin with. IT reads that 'the file was autonatically generated by WSL" – Ya. Jan 28 '24 at 01:04
  • I just realized both this question and my answer are a duplicate of https://askubuntu.com/q/1347712/1004020 . Except I added the -f flag for robustness, and I slightly cleaned up the commands in my answer – Daniel T Jan 28 '24 at 01:17
  • @mchid It does, thx. Looks like that's more or less the accepted answer. – Ya. Jan 28 '24 at 15:55

1 Answers1

2

It seems that the immutable file attribute (chattr +i) is required. Run the following:

sudo unlink /etc/resolv.conf
echo 'nameserver 8.8.8.8' | sudo tee /etc/resolv.conf
sudo chattr -f +i /etc/resolv.conf

Replace tee with tee -a if you want to keep wsl.conf modifications

echo $'[network]\ngenerateResolvConf = false' | sudo tee /etc/wsl.conf'

Daniel T
  • 4,594
  • Well I be damned, that seems to be working. Actually I've tried setting it to readonly (which didn't work of course) but didn't know about the immutable attribute. Thanks! – Ya. Jan 28 '24 at 01:11