Skip to content

Custom resolv.conf being replaced by generated file, even with comment removed. #1908

Closed

Description

@j-c-m
  • 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

Activity

  1. j-c-m commented on Apr 13, 2017

    @j-c-m
    Author

    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?

  2. benhillis commented on Apr 13, 2017

    @benhillis
    Member

    Did you modify /etc/resolv.conf or /run/resolvconf/resolv.conf?

  3. j-c-m commented on Apr 13, 2017

    @j-c-m
    Author

    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.

  4. benhillis commented on Apr 17, 2017

    @benhillis
    Member

    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.

  5. benhillis commented on Apr 17, 2017

    @benhillis
    Member

    Sorry, did not mean to close.

  6. sunilmut commented on Apr 21, 2017

    @sunilmut
    Member

    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.

  7. bradley101 commented on Jul 17, 2017

    @bradley101

    The problem still persists in Insider Preview 16241.
    I solved this issue by following steps

    1. Delete /etc/resolv.conf
    2. Make /etc/resolv.conf by vim/nano
    3. Insert appropriate nameservers.
    4. Done!

    Logout and the again run bash on cmd

  8. benhillis commented on Jul 17, 2017

    @benhillis
    Member

    Sunil Muthuswamy (@sunilmut) is currently looking at this.

  9. sunilmut commented on Jul 25, 2017

    @sunilmut
    Member

    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.

  10. lmayorga1980 commented on Nov 29, 2018

    @lmayorga1980

    followed Shantanu Banerjee (@bradley101) workaround and back in business.

  11. 20 remaining items

  12. remiflament commented on Sep 11, 2020

    @remiflament

    Indeed the wsl --shutdown command from the windows command line was successfull! Thank you Jesse Miller (@j-c-m)

  13. stivo85 commented on Sep 24, 2020

    @stivo85

    This worked for me on WSL2 -

    /etc/wsl.conf

    [network]
    generateResolvConf = false
    

    Inside a wsl session -

    sudo rm /etc/resolv.conf
    # create your own /etc/resolv.conf
    sudo vim /etc/resolv.conf
    

    Immediately shutdown wsl, do not start another session until you execute from a windows command prompt.

    wsl --shutdown
    

    This solution works for me, thanks!

  14. Johawila commented on Oct 5, 2020

    @Johawila

    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

  15. niilz commented on Jan 28, 2021

    @niilz

    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.conf looks indeed like this:

    [network]
    generateResolvConf = false
    

    And NOT like this

    # [network]
    generateResolvConf = false
    
  16. mehrdadnd commented on Feb 15, 2021

    @mehrdadnd

    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.

  17. seffyroff commented on May 6, 2021

    @seffyroff

    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 :/

  18. KatSteinke commented on Jul 16, 2021

    @KatSteinke

    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.

  19. mezhgano commented on Jan 12, 2022

    @mezhgano

    Algorithm that worked for me:

    1. Add following to //etc/wsl.conf:
    [network]
    generateResolvConf = false
    
    1. Remove symlink and create new resolv.conf:
    sudo rm /etc/resolv.conf
    sudo micro /etc/resolv.conf
    
    1. Add following to resolv.conf:
    nameserver 192.168.1.1 
    # (or whatever DNS adress you need)
    
    1. Shutdown WSL from Powershell:

    wsl --shutdown

    1. Start WSL session again just like usual and check if it helps
  20. liechtir commented on Jan 21, 2022

    @liechtir

    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.

  21. mezhgano commented on Jan 21, 2022

    @mezhgano

    Thanks for the info, this looks more proper way to solve the issue.

  22. mezhgano commented on Feb 6, 2022

    @mezhgano

    liechtir I gave it a try and it doesn't work the way i expected in my case. Reasons:

    1. It does require root password every time i log in which is not comfortable.
    2. 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.
    3. 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.

  23. glasko-dp commented on Oct 25, 2022

    @glasko-dp

    Ben Hillis (@benhillis) How does this still not work consistently after 5.5 years?

  24. julian7 commented on Dec 23, 2022

    @julian7

    Ben Hillis (@benhillis) How does this still not work consistently after 5.5 years?

    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?

  25. mokonofua commented on Jan 5, 2023

    @mokonofua

    This worked for me on WSL2 -

    /etc/wsl.conf

    [network]
    generateResolvConf = false
    

    Inside a wsl session -

    sudo rm /etc/resolv.conf
    # create your own /etc/resolv.conf
    sudo vim /etc/resolv.conf
    

    Immediately shutdown wsl, do not start another session until you execute from a windows command prompt.

    wsl --shutdown
    

    Worked for me!!!

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions