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
/etc/resolv.conf keeps resetting after Windows restart, even when automatic file regeneration is disabled. #3928
I'm using Ubuntu (straight from the Windows store), and my uname -a outputs the following:
Linux HOSTNAME 4.4.0-17763-Microsoft #379-Microsoft Wed Mar 06 19:16:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux
The problem and how to reproduce:
Initially, sudo nano /etc/resolv.conf shows the following:
# This file was automatically generated by WSL. To stop automatic generation of this file, remove this line.
Remove the comment (which tells you to remove it) and add a name server:
nameserver 1.1.1.1
Now, close WSL and restart Windows.
Open /etc/resolv.conf again. For me at least, it reverts to a blank file even though I removed the line that was supposed to be removed to stop automatic regeneration:
# This file was automatically generated by WSL. To stop automatic generation of this file, remove this line.
An additional problem is that without manually defining a name server, no DNS requests are revolved, and for me, no name servers are defined by default (I'd like to use my preferred one anyway).
Reacted by a_p_u_r_o, Karthikeyan, Baruch Odem (Rothkoff), Shital Shah, Michael Doyle, andyli, Gary Liu, Azat Safin, Hugo Manrique, Dmitry Nefedov and 1 more
changed the title [-]/etc/resolv.conf keeps resetting after Windows restart.[/-][+]/etc/resolv.conf keeps resetting after Windows restart, even when automatic file regeneration is disabled.[/+]on Mar 20, 2019
I tried this locally and confirmed this seems to be broken if /etc/resolv.conf is a symlink (which is very common). Since it's already broken and there's a wsl.conf entry, it probably makes sense to remove the old header-based mechanism.
Looked into this a bit more. The issue here is that /etc/resolv.conf is a symlink into /run, which is a tmpfs directory that gets deleted when the instance exits. If you want to use the header to take control of /etc/resolv.conf you'll also need to replace the /etc/resolv.conf symlink with a file.
Looked into this a bit more. The issue here is that /etc/resolv.conf is a symlink into /run, which is a tmpfs directory that gets deleted when the instance exits. If you want to use the header to take control of /etc/resolv.conf you'll also need to replace the /etc/resolv.conf symlink with a file.
That's what I did. rm -f'd /etc/resov.conf and created a new one with my custom configurations. Now it no longer regenerates the file.
Maybe we should update the comments in the generated file to something like:
# This file was automatically generated by WSL. To stop automatic generation, delete this file and recreate it.
Reacted by Ben Hillis, Vadym Serhiyovych Hapanchak, andyli, Manuel Garisto Zuna, Edgardo Ramírez and picklefan
The text of the comment (aka 'header') of /etc/resolv.conf changed. As of 18890 it now reads:
# 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
In a kinder, better world that wouldn't be the advice (there is nothing good in wsl.conf), but okay. The text speaks for itself.
The systemd-resolved behavior already understood by Linux types without having to look up imagined wsl.conf documentation also works. That behavior being, quoth from systemd-resolved's generated /etc/resolv.conf:
# This file is managed by man:systemd-resolved(8). Do not edit.
...
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
...
So for example:
$ sudo mv /etc/resolv.conf /etc/resolv.conf.bak
$ sudo bash -c "echo "nameserver 8.8.8.8 > /etc/resolv.conf"
$ # exit, do the wsl.exe --terminate raindance, and restart
In this case /etc/resolv.conf will be left alone on WSL as expected too, even if you don't have that section in wsl.conf.
This issue is currently in an unholy state of open and by-design. Tidying up with a status closed since the behavior cited in the OP is intended, even on Real Linux. I am not sure if the old (for some value of old) "header based mechanism" was removed in 18890 or earlier. Too lazy to look and academic.
Either way the now defunct comment text has been corrected, in the sense it no longer tells people "To stop automatic generation of this file, remove this line". You can quash regeneration either the systemd-resolved way, or the WSL way to taste.
Reacted by Biswapriyo Nath, StaticallyTypedRice, Lauren, yacovg, Nico Gallinal, Shawn Thuris, Christopher Peisert, and1er, Teemu Helenius, Mehrdad Nezamdoost and 1 more
Activity
[-]/etc/resolv.conf keeps resetting after Windows restart.[/-][+]/etc/resolv.conf keeps resetting after Windows restart, even when automatic file regeneration is disabled.[/+]0xbadfca11 commentedon Mar 21, 2019
Workaround or use generateResolvConf = false instead.
benhillis commentedon Mar 28, 2019
I tried this locally and confirmed this seems to be broken if /etc/resolv.conf is a symlink (which is very common). Since it's already broken and there's a wsl.conf entry, it probably makes sense to remove the old header-based mechanism.
benhillis commentedon Mar 28, 2019
Looked into this a bit more. The issue here is that /etc/resolv.conf is a symlink into /run, which is a tmpfs directory that gets deleted when the instance exits. If you want to use the header to take control of /etc/resolv.conf you'll also need to replace the /etc/resolv.conf symlink with a file.
StaticallyTypedRice commentedon Mar 29, 2019
That's what I did. rm -f'd /etc/resov.conf and created a new one with my custom configurations. Now it no longer regenerates the file.
Maybe we should update the comments in the generated file to something like:
benhillis commentedon Mar 29, 2019
StaticallyTypedRice - I'm going to change the header to refer to wsl.conf.
Brian-Perkins commentedon May 1, 2019
resolv.conf header change made in Windows Insider Build 18890
therealkenc commentedon May 2, 2019
The text of the comment (aka 'header') of
/etc/resolv.confchanged. As of 18890 it now reads:In a kinder, better world that wouldn't be the advice (there is nothing good in
wsl.conf), but okay. The text speaks for itself.The
systemd-resolvedbehavior already understood by Linux types without having to look up imaginedwsl.confdocumentation also works. That behavior being, quoth fromsystemd-resolved'sgenerated/etc/resolv.conf:So for example:
In this case
/etc/resolv.confwill be left alone on WSL as expected too, even if you don't have that section inwsl.conf.This issue is currently in an unholy state of open and by-design. Tidying up with a status closed since the behavior cited in the OP is intended, even on Real Linux. I am not sure if the old (for some value of old) "header based mechanism" was removed in 18890 or earlier. Too lazy to look and academic.
Either way the now defunct comment text has been corrected, in the sense it no longer tells people "To stop automatic generation of this file, remove this line". You can quash regeneration either the
systemd-resolvedway, or the WSL way to taste.