Skip to content

/etc/resolv.conf keeps resetting after Windows restart, even when automatic file regeneration is disabled. #3928

Closed

Description

@StaticallyTypedRice
  • My Windows build number: [Version 10.0.17763.379]

  • 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).

Activity

  1. 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
  2. 0xbadfca11 commented on Mar 21, 2019

    @0xbadfca11
  3. benhillis commented on Mar 28, 2019

    @benhillis
    Member

    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.

  4. benhillis commented on Mar 28, 2019

    @benhillis
    Member

    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.

  5. StaticallyTypedRice commented on Mar 29, 2019

    @StaticallyTypedRice
    Author

    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.
    
  6. benhillis commented on Mar 29, 2019

    @benhillis
    Member

    StaticallyTypedRice - I'm going to change the header to refer to wsl.conf.

  7. Brian-Perkins commented on May 1, 2019

    @Brian-Perkins
    Contributor

    resolv.conf header change made in Windows Insider Build 18890

  8. therealkenc commented on May 2, 2019

    @therealkenc

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions