Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generateResolvConf = false did not work in wsl.conf #5611

Closed
scyto opened this issue Jul 19, 2020 · 15 comments
Closed

generateResolvConf = false did not work in wsl.conf #5611

scyto opened this issue Jul 19, 2020 · 15 comments
Labels

Comments

@scyto
Copy link

scyto commented Jul 19, 2020

I have WSL2 with debian -all good.
I created a /etc/wsl.conf file
it contains

[network]
generateResolvConf = false

as per https://docs.microsoft.com/en-us/windows/wsl/wsl-config#network

if i delete /etc/resolv.conf (or edit and save) on start of the next debia WSL2 session it has been regenerated again.

running WSL2 in windows 10 build 20170.rs_prerelease.200710-1419

Environment

Windows build number: Microsoft Windows [Version 10.0.20170.1000]
Your Distribution version: 
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian

 WSL 2 

Steps to reproduce

Expected behavior

Actual behavior

@scyto
Copy link
Author

scyto commented Jul 19, 2020

solution seems to have been restarting LxssManager - maybe wsl.conf is only read once per boot (per start of the service?) .
is that expected or a bug?

@therealkenc
Copy link
Collaborator

A wsl.exe --shutdown (rather than mucking LxssManager) should be sufficient. Yeah that is (as a practical matter) by-design for better or worse. It isn't the service, which is responsible for managing the state of all distros (both WSL1 and WSL2). Your /etc/wsl.conf is read at the point WSL-brand /init fired up for a given distro. Once /init has started and is running, it is oblivious to changes that happen in /etc/wsl.conf.

@bersbersbers
Copy link

The need to shutdown WSL for this setting to take effect should be stated as a comment in the default /etc/resolv.conf.

@therealkenc
Copy link
Collaborator

The need to shutdown WSL for this setting to take effect should be stated

here

@mikezerosix
Copy link

M$ keep closing these bug tickets without solving the bug. Or they keep repeating and making this bug worse with every update.

Windows 10 Entrprise H20 it does not matter what you shutdown it has no absolutely effect. You can cold reboot the computer and it has no effect, the resolv.conf is always overwritten. Now even if you try to make the file immutable chattr +i /etc/resolv.conf, that no longer works.

And why this setting is not available in global .wslconfig ?

@therewillbeblood
Copy link

therewillbeblood commented Apr 26, 2022

@mikezerosix i see the same behaviour with a fresh Ubuntu 22.04 installed through the Microsoft Store.
I am on Windows 10 Version 10.0.19044 Build 19044

wsl --shutdown did not help either.

It is working fine though with Ubuntu 18.04 and 20.04

EDIT: a reboot of the host did the trick

@Blarnix
Copy link

Blarnix commented Apr 26, 2022

Still happening on Windows 11 even after the update that came out literally yesterday/today. No dice on any of the fixes.

@davidnussio
Copy link

It works for me (the first time I forgot to remove symlink and I got the problem)

  1. I create a /etc/wsl.conf
[network]
generateResolvConf = false
  1. Remove symlink sudo rm /etc/resolv.conf
  2. Enter my nameservers

@arms11
Copy link

arms11 commented Jul 2, 2022

Just got windows 11 update. No work-around seems to be helping. This is indeed annoying.

Update:
while I find wsl.conf setting not letting the file to be overridden, what I observed was when I performed wsl --shutdown and came back to the instance, I see no etc/resolv.conf. So, now the file is removed completely!

@dan-ryan
Copy link

dan-ryan commented Jul 4, 2022

I am also having this problem.
I need to set "nameserver 8.8.8.8"; otherwise, I get another bug. But this keeps getting wiped.

@DanielSmedegaardBuus
Copy link

OMG, I hate Microsoft so much. How are you still in business when you cannot make a single piece of software that isn't fundamentally broken and riddled with bugs? Upgrade from WSL1 to WSL2 fails. Useless error message. Googling provides help, WSL2 won't install on compressed drive, gets upgrade working. Boots upgraded distro. Network broken. No help. Googling lets you know that you need to install a kernel package thing. wsl --set-version neither did this nor mentioned it needed to be done. Do it manually. Network still broken. Internet helps you to know that you need the Hyper-V feature enabled. wsl --set-version neither did this nor mentioned it needed to be done. Network still broken. Internet tells you that if your temporary folder is compressed, WSL2 can't create a swap file in %TEMP%. No error message provided by WSL to tell you this, no mention of it anywhere, WSL incapable of itself creating the uncompressed VHD file it needs because incompetence and brain damage. Network still broken. WSL for reasons unknown (aka incompetence and brain damage in the room in Redmond filled with drunken clowns with "Developers" written on the door) puts in a random DNS ip in resolv.conf. This is generated automatically, unless, as Google again helps you to understand you need to add generateResolvConf = false in your [network] session in the %userprofile%/.wslconfig file that you just created to get WSL2 to not attempt to create the swap file it doesn't know how to create. Alright, I mean, we are riding the clown car, so let's just keep on smashing windows and pouring sugar in the tank. Fine, add the setting, shut down, restart and edit resolv.conf. Works until I open up another WSL session which overwrites resolv.conf because... Yeah, incompetence and brain damage. This isn't beta. This isn't alpha. This is "oh, I'm sorry, we don't have a position for you, because you're not actually a developer, you're a clown with brain damage." I hate you so, so much, Microsoft. The only thing worse than trying to use your brittle self-destructing pain-inflicting clownish garbage you call software, would be forced to work alongside the clowns you call developers. Imagine that nightmare. Christ.

@CopilotTestes
Copy link

Works to me

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

#5420 (comment)

@Konstantin-Glukhov
Copy link

Why is this closed? The issue still persists.

@janikaja-tet
Copy link

Forget about /etc/wsl.conf file that is mentioned in /etc/resolv.conf, because it has no effect.
Instead add a single line to your ~/.bashrc script:
sudo sh -c "echo nameserver 8.8.8.8 > /etc/resolv.conf"
Yes, it will ask for your sudo password, but at least you are good to go.

@kingaj12
Copy link

kingaj12 commented Nov 15, 2024

Here is what worked for me (so far so good). This seems to be a one-time thing, unless you use multiple different VPNs.

You may need reset the Net IP Interface (the very last step) every time you start the VPN.

Edit wsl.conf and restart WSL

In WSL2 terminal:

# Prevent wsl2 from overwriting resolve.conf 
cat <<EOF | sudo tee -a /etc/wsl.conf
[network]
generateResolvConf = false
EOF

In Windows Powershell with admin privileges:

# Reinitialize WSL so it picks up the new /etc/wsl.conf
wsl.exe --shutdown
wsl.exe -d <your WSL distribution>

Edit resolv.conf and add DNS information for your VPN

Start your VPN (I use AnyConnect).

In Windows Powershell with admin privileges:

# Get the DNS server ip addresses
Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object -ExpandProperty ServerAddresses

# Get the  DNS search list
Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList

In WSL terminal:

# unlink default wsl2 resolv.conf
sudo unlink /etc/resolv.conf 

# generate new wsl2 resolv.conf with the DNS server addresses and search domains for your VPN
cat <<EOF | sudo tee -a /etc/resolv.conf
# list of DNS server ip addresses
nameserver x.x.x.x
nameserver y.y.y.y
nameserver 8.8.8.8
nameserver 8.8.4.4
# search list
search searchdomain1.com searchdomain2.com ... searchdomainN.com
EOF

Reset the Net IP Interfaces

In Windows Powershell with admin privileges:

Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000

You may need to do this reset every time you restart the VPN.

Hat Tips

https://jamespotz.github.io/blog/how-to-fix-wsl2-and-cisco-vpn

#5611 (comment)

https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6#file-fix-wsl2-dns-resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests