You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Custom resolv.conf being replaced by generated file, even with comment removed. #1908
A brief description
Custom /etc/resolv.conf overwritten, even when "# This file was automatically generated by WSL. To stop automatic generation of this file, remove this line." is removed.
Expected results
Custom /etc/resolv.conf should not be overwritten when comment is removed.
Actual results (with terminal output if applicable)
Custom /etc/resolv.conf replaced with standard generated /etc/resolv.conf
Your Windows build number
1703 - OS Build 15063.138
Reacted by Sean G. Wright, Frederic Charette, Zhong Zhenyu, Peter Conerly, Daniel Hiller, Giuseppe Crinò, Andrew Huang, Krzysztof Zawadzki, Haitham Maya, gurpreetshanky and 17 more
If I remove /etc/resolv.conf - which was a symlink -> /run/resolvconf/resolv.conf it will not remove my custom /etc/resolv.conf.
I can't verify but is it possible that this behavior changed from 14.04 -> 16.04 so the symlink isn't being followed by WSL when checking for the comment?
Reacted by AP-Nothize, Peter Conerly, doctorbal and TY
If the /etc/resolv.conf symlink was in place it would implicitly only modify /run/resolvconf/resolv.conf - and changes would always be automatically overwritten as long as /etc/resolv.conf was a symlink.
It looks like there is an issue that is causing the resolv.conf file to be regenerated each time an instance is launched. We are looking at ways to improve this experience.
Here is some more background. By default, bash.exe will auto-generate /etc/resolv.conf every time you launch bash.exe. Then it will try to keep it up to date with changes from Windows, when bash is running. We somehow screwed up the logic to stop-auto generation when you remove the first line. It looks like if you remove the first line, we stop auto-update of the file while bash is running, but forgot to disable the logic to auto-generate during bash launch. We do apologize for the inconvenience and as Ben Hillis (@benhillis) mentions, we are looking to improve the experience here.
Reacted by Sean G. Wright, Daniel Hiller, Jack McKernan, Erik Bernoth, Victor Noel and asherhe
Thanks Shantanu Banerjee (@bradley101). For this release (Fall Creators Update), we will have to live with the workaround you have pointed out, here. For next release, we will relook at the better support for other VPN solutions.
Once you edit the resolv.conf file, you can do: sudo chattr +i /etc/resolv.conf - which will make the file immutable and won't be overwritten next time you start wsl.
I've been searching for a solution to this for ages, this did the trick for me! Thanks
I found this solution to work very well. Is important to shutdown WSL2 in a correct way so it accepts the changed settings.
do above or here settings. then shutdown WSL via command from cmd or powershell .
wsl.exe --terminate NAME_OF_YOUR_LINUX
and open a WSL one more time, this time the settings should be persisted as it supposed.
Behavior is slightly different than written above for me. I've added the correct entry to wsl.conf:
[network]
generateResolvConf = false
After wsl --shutdown then wsl -d Ubuntu-20.04 There is no symlink or any other kind of /etc/resolv.conf. I make a new one with the entries I want. DNS resolution starts working again properly.
On subsequent launch of wsl the /etc/resolv.conf is gone. It seems to be removed upon launch every time.
The only fix that has worked for me is chattr +i /etc/resolv.conf. That's treating the symptom rather than the cause though :/
Reacted by Mike MacCana, Andrew Bezuglov, elmorekevin, Jonas Kemper, Jeff Sharp, Andy Bolton, Samu B, Michael Mercurio and Zen
For me /etc/resolv.conf also resets despite having added the correct entry to wsl.conf, removing the symlink and creating my own resolv.conf, and it's not even just on restarting WSL or opening a new session - sometimes it seems to happen even when I leave the computer running overnight.
EDIT: now it's happened in the span of hours.
when not generating the resolv.conf you risk to loose your network connectivty from WSL as soon as your IP changes on the host.
easiest way to mittigate that is to have in wsl.conf
[network]
generateResolvConf = **true**
this leads to a generated resolv.conf
and within your ~/.bashrc you add: sudo bash -c 'echo "nameserver xxx.xxx.xxx.xxx" >> /etc/resolv.conf'
for every name server you want to have in there. Like this, every time you login, your additional network config is added to the resolv conf and all is fine, no more headache.
Reacted by Sven Krefeld, Dmitry Meshkoff, liechtir, kobever1, wolszakp, ahmedsabriz and Mohammad Bahmani
liechtir I gave it a try and it doesn't work the way i expected in my case. Reasons:
It does require root password every time i log in which is not comfortable.
Generated resolv.conf already have nameserver ip (172.25.16.1). It is Virtual Ethernet Adapter (WSL) ip, i don't know how it supposed to work this way, but it never works.
Then i echoing my nameserver as you mentioned, it leads to significant delay in name resolution, for example i use simple ping command and only after 5-6 seconds it start actually pinging. Maybe because it tries first (in my case broken) ip in a list of nameservers.
My DNS ip never changes, because it is ip of my home router, so for now, i decided to turn off autogenerate resolv.conf.
If i doing something wrong anybody please correct me.
Since the file is regenerated when bash.exe starts, and it keeps the file updated while it runs (see #1350 (comment)), I'm not surprised that WSL is not stable. I mean, where the architects were, when this decision was made?
Activity
j-c-m commentedon Apr 13, 2017
If I remove /etc/resolv.conf - which was a symlink -> /run/resolvconf/resolv.conf it will not remove my custom /etc/resolv.conf.
I can't verify but is it possible that this behavior changed from 14.04 -> 16.04 so the symlink isn't being followed by WSL when checking for the comment?
benhillis commentedon Apr 13, 2017
Did you modify /etc/resolv.conf or /run/resolvconf/resolv.conf?
j-c-m commentedon Apr 13, 2017
If the /etc/resolv.conf symlink was in place it would implicitly only modify /run/resolvconf/resolv.conf - and changes would always be automatically overwritten as long as /etc/resolv.conf was a symlink.
benhillis commentedon Apr 17, 2017
It looks like there is an issue that is causing the resolv.conf file to be regenerated each time an instance is launched. We are looking at ways to improve this experience.
benhillis commentedon Apr 17, 2017
Sorry, did not mean to close.
sunilmut commentedon Apr 21, 2017
Here is some more background. By default, bash.exe will auto-generate
/etc/resolv.confevery time you launch bash.exe. Then it will try to keep it up to date with changes from Windows, when bash is running. We somehow screwed up the logic to stop-auto generation when you remove the first line. It looks like if you remove the first line, we stop auto-update of the file while bash is running, but forgot to disable the logic to auto-generate during bash launch. We do apologize for the inconvenience and as Ben Hillis (@benhillis) mentions, we are looking to improve the experience here.bradley101 commentedon Jul 17, 2017
The problem still persists in Insider Preview 16241.
I solved this issue by following steps
Logout and the again run bash on cmd
benhillis commentedon Jul 17, 2017
Sunil Muthuswamy (@sunilmut) is currently looking at this.
sunilmut commentedon Jul 25, 2017
Thanks Shantanu Banerjee (@bradley101). For this release (Fall Creators Update), we will have to live with the workaround you have pointed out, here. For next release, we will relook at the better support for other VPN solutions.
lmayorga1980 commentedon Nov 29, 2018
followed Shantanu Banerjee (@bradley101) workaround and back in business.
20 remaining items
remiflament commentedon Sep 11, 2020
Indeed the wsl --shutdown command from the windows command line was successfull! Thank you Jesse Miller (@j-c-m)
stivo85 commentedon Sep 24, 2020
This solution works for me, thanks!
Johawila commentedon Oct 5, 2020
I've been searching for a solution to this for ages, this did the trick for me! Thanks
niilz commentedon Jan 28, 2021
First of all Jesse Miller (@j-c-m)'s suggestion also worked for me.
But! I did a silly mistake, that kept me struggling for a bit longer. So my here it is, just in case.
Make sure you also uncomment the
[network]header.So that the change in
wsl.conflooks indeed like this:And NOT like this
mehrdadnd commentedon Feb 15, 2021
I found this solution to work very well. Is important to shutdown WSL2 in a correct way so it accepts the changed settings.
do above or here settings. then shutdown WSL via command from cmd or powershell .
and open a WSL one more time, this time the settings should be persisted as it supposed.
seffyroff commentedon May 6, 2021
Behavior is slightly different than written above for me. I've added the correct entry to wsl.conf:
After wsl --shutdown then wsl -d Ubuntu-20.04 There is no symlink or any other kind of /etc/resolv.conf. I make a new one with the entries I want. DNS resolution starts working again properly.
On subsequent launch of wsl the /etc/resolv.conf is gone. It seems to be removed upon launch every time.
The only fix that has worked for me is
chattr +i /etc/resolv.conf. That's treating the symptom rather than the cause though :/KatSteinke commentedon Jul 16, 2021
For me /etc/resolv.conf also resets despite having added the correct entry to wsl.conf, removing the symlink and creating my own resolv.conf, and it's not even just on restarting WSL or opening a new session - sometimes it seems to happen even when I leave the computer running overnight.
EDIT: now it's happened in the span of hours.
mezhgano commentedon Jan 12, 2022
Algorithm that worked for me:
//etc/wsl.conf:resolv.conf:resolv.conf:wsl --shutdownliechtir commentedon Jan 21, 2022
when not generating the resolv.conf you risk to loose your network connectivty from WSL as soon as your IP changes on the host.
easiest way to mittigate that is to have in wsl.conf
this leads to a generated resolv.conf
and within your ~/.bashrc you add:
sudo bash -c 'echo "nameserver xxx.xxx.xxx.xxx" >> /etc/resolv.conf'for every name server you want to have in there. Like this, every time you login, your additional network config is added to the resolv conf and all is fine, no more headache.
mezhgano commentedon Jan 21, 2022
Thanks for the info, this looks more proper way to solve the issue.
mezhgano commentedon Feb 6, 2022
liechtir I gave it a try and it doesn't work the way i expected in my case. Reasons:
My DNS ip never changes, because it is ip of my home router, so for now, i decided to turn off autogenerate resolv.conf.
If i doing something wrong anybody please correct me.
glasko-dp commentedon Oct 25, 2022
Ben Hillis (@benhillis) How does this still not work consistently after 5.5 years?
julian7 commentedon Dec 23, 2022
Since the file is regenerated when bash.exe starts, and it keeps the file updated while it runs (see #1350 (comment)), I'm not surprised that WSL is not stable. I mean, where the architects were, when this decision was made?
mokonofua commentedon Jan 5, 2023
Worked for me!!!