Repository navigation
Description
- A brief description - Mainly a question: How do we get secondary dns suffixes into the /etc/resolv.conf since it is automatically generated? Under the advanced TCP/IP settings -> DNS -> Append these DNS suffixes setting in windows, I have several listed, but they don't make it into the WSL resolv.conf.
- Expected results - It should be possible to either override the /etc/resolv.conf auto-generation or it should import additional DNS suffixes from windows TCP/IP settings.
And here is ipconfig /all output:
C:\Users\dan>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : dan-MOBL
Primary Dns Suffix . . . . . . . : amr.corp.foo.com
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : amr.corp.foo.com
fm.foo.com
a.foo.com
b.foo.com
c.foo.com
d.foo.com
e.foo.com
f.foo.com
g.foo.comEthernet adapter Ethernet 3:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Realtek USB GbE Family Controller
Physical Address. . . . . . . . . : 00-E0-1B-6F-F7-69
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : YesEthernet adapter Ethernet 4:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Lenovo USB Ethernet
Physical Address. . . . . . . . . : 00-50-B6-60-CB-39
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : YesEthernet adapter VirtualBox Host-Only Network:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VirtualBox Host-Only Ethernet Adapter
Physical Address. . . . . . . . . : 0A-00-27-00-00-16
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.168.56.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
NetBIOS over Tcpip. . . . . . . . : EnabledWireless LAN adapter Local Area Connection* 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
Physical Address. . . . . . . . . : 44-85-00-13-03-95
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : YesWireless LAN adapter Local Area Connection* 4:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #2
Physical Address. . . . . . . . . : 46-85-00-13-03-94
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : YesEthernet adapter Ethernet:
Connection-specific DNS Suffix . : fm.intel.com
Description . . . . . . . . . . . : Intel(R) Ethernet Connection (2) I219-LM
Physical Address. . . . . . . . . : 50-7B-9D-A6-55-58
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 10.19.123.139(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Friday, July 29, 2016 7:21:32 AM
Lease Expires . . . . . . . . . . : Friday, July 29, 2016 7:21:28 PM
Default Gateway . . . . . . . . . : 10.19.123.251
DHCP Server . . . . . . . . . . . : 10.2.71.6
DNS Servers . . . . . . . . . . . : 10.2.3.4
10.5.6.7
10.4.5.6
Primary WINS Server . . . . . . . : 10.3.2.1
Secondary WINS Server . . . . . . : 143.9.9.9
134.8.8.8
NetBIOS over Tcpip. . . . . . . . : EnabledEthernet adapter VMware Network Adapter VMnet1:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet1
Physical Address. . . . . . . . . : 00-50-56-C0-00-01
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.168.223.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Friday, July 29, 2016 7:21:24 AM
Lease Expires . . . . . . . . . . : Friday, July 29, 2016 10:21:24 AM
Default Gateway . . . . . . . . . :
DHCP Server . . . . . . . . . . . : 192.168.223.254
NetBIOS over Tcpip. . . . . . . . : EnabledEthernet adapter VMware Network Adapter VMnet8:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
Physical Address. . . . . . . . . : 00-50-56-C0-00-08
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.168.32.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Friday, July 29, 2016 7:21:24 AM
Lease Expires . . . . . . . . . . : Friday, July 29, 2016 10:21:24 AM
Default Gateway . . . . . . . . . :
DHCP Server . . . . . . . . . . . : 192.168.32.254
Primary WINS Server . . . . . . . : 192.168.32.2
NetBIOS over Tcpip. . . . . . . . : EnabledEthernet adapter Bluetooth Network Connection:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
Physical Address. . . . . . . . . : 44-85-00-13-03-98
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : YesWireless LAN adapter Wi-Fi:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : fm.foo.com
Description . . . . . . . . . . . : Intel(R) Dual Band Wireless-AC 8260
Physical Address. . . . . . . . . : D6-9A-00-E2-08-BA
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : YesC:\Users\dan>
-
Actual results (with terminal output if applicable)
dan@dan-MOBL:~$ cat /etc/resolv.conf
DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.1.2.3
nameserver 10.4.5.6
nameserver 10.7.8.9
search fm.foo.com
dan@dan-MOBL:~$ -
Your Windows build number
14372

Activity
a8ksh4 commentedon Jul 29, 2016
updated w/ ipconfig /all content, instead of just ipconfig.
benhillis commentedon Jul 30, 2016
Thanks for providing this info, our networking wizard is getting back from vacation on Monday and I'll sync up with him to see if he can figure out what's going on.
a8ksh4 commentedon Aug 17, 2016
I think normal way to work around this would be to put additional search domains into the /etc/resolvconf/resolv.conf.d/post file and they should be appended to /etc/resolv.conf when it is generated, but I don't think this is working either.
Nindaleth commentedon Sep 8, 2016
I think on Ubuntu the additional search domains are added into /etc/resolvconf/resolv.conf.d/tail (see man resolvconf), but that doesn't work for me either.
sunilmut commentedon Sep 22, 2016
As per the current design, WSL tries to keep
/etc/resolv.confup to date and in sync with the Windows DNS entries. But the "stay up to date" does not seem to be happening (see #1028 for more details). Currently, we don't anything with secondary DNS suffixes. But, this is great feedback. I have opened a task internally to track the work needed to make this less painful. Meanwhile, please provide the same feedback on our User Voice Page and continue to post any suggestions around solutions. We love your feedback!bitcrazed commentedon Jan 14, 2017
In Linux, search domains are declared by adding the "search [,<domain]*" entries into resolv.conf, e.g.:
However. by default, WSL will auto-generate resolv.conf, overwriting any changes you make. But as Sunil Muthuswamy (@sunilmut) points out above, a recent Insider build adds the ability to turn-off auto-generation by removing the comment at the top of the file.
Also, the WSL resolv.conf auto-generator doesn't add search suffixes configured on Windows network connections. We have an internal task tracking this scenario and will update this thread if/when it pops off the backlog ;)
saxonww commentedon Oct 23, 2017
For anyone who reads the above and thinks removing the comment in resolv.conf will fix this - it won't. That method appears to only work while there is an active WSL session, i.e. if you close all open WSL windows and then open a new one, your /etc/resolv.conf is regenerated even if you've previously removed the comment line.
This is true at least in the Fall Creator's Update (build 16299.19) as of today. I also experienced this with the first Creator's Update in the spring. I assume it's always been this way.
I didn't see anything in User Voice for this as suggested here, so I created a new idea here if people want to go vote on it.
Finally, as a workaround, I set up a file ~/resolv.conf.add with my desired suffix search list in it. Then I modified my .bashrc to copy the generated /etc/resolv.conf minus the last line (which is the search line), cat my file with the result, then copy back to /etc.
Content of ~/resolv.conf.add:
search suffix1.com suffix2.com suffix3.com suffix-etc.comRelevant content of ~/.bashrc:
This will make you enter your WSL password every time you open a WSL window. There are various ways around this, but all of them (that I can think of) to get rid of the prompt completely involve changing /etc/sudoers to allow running that mv command without entering a password. Probably the 'safest' would be to locate all the bashrc commands above into a separate script, which is itself allowed to run for your user with NOPASSWD in /etc/sudoers. Then call that separate script from your .bashrc.
It would be really great if the WSL /etc/resolv.conf autogeneration/autoupdate handling were changed to include the entire configured DNS suffix search list from Windows, or to allow a more standard way of overriding the generated list that persists between WSL sessions. For most home users the existing behavior is fine, but workplace users are likely to have a need for more complicated DNS suffix search lists and the WSL behavior here is not ideal.
cfiderer commentedon Jul 17, 2018
I regard the current behavior as a bug: if WSL generates the
/etc/resolv.conffile, it should take all the information from the Windows network configuration and put it there, too. This includes the search domain list.mlheur commentedon Aug 14, 2018
I agree the current behavior is a bug. Secondary search suffixes from windows should be added to the search list in resolv.conf. Any other workaround, such as populating resolv.conf as part of your profile, or login routine, is simply a hack because the original product was wrong.
rennex commentedon Mar 13, 2019
At least now, for me, the following procedure seems to prevent WSL from overwriting resolv.conf:
/etc/resolv.confis a regular file, not a symlink like it is by defaultTo check that it doesn't get overwritten any more, you can force a "shutdown" of the Linux system by running this command in an elevated cmd.exe:
net stop LxssManager, then start a new WSL shell and check if your changes are still there.timriker commentedon May 15, 2019
Any update on this? I too would like to see all domains added to the one search line in /etc/resolv.conf
search domain1 domain2 ...
The current behavior appears to be incorrectly setting "search" to the Primary Dns Suffix. "search" should be set to a space separated list from the "DNS Suffix Search List"
jsmouret commentedon Jul 5, 2019
The problem with unlinking
/etc/resolv.confis that things will break when roaming around with a laptop and changing network.I would suggest an option in
/etc/wsl.conflike:or even something more generic:
schmitmd commentedon Jan 23, 2020
Any updates on this? Been open for 3.5 years now...
42 remaining items
arm000 commentedon Aug 24, 2023
Just ran into this issue also and surprised there is no official solution. If I install systemd under WSL does systemd take over generation of resolv.conf from WSL, and can I fix it there?
miiichael commentedon Aug 25, 2023
systemd-resolved can be optionally configured to manage /etc/resolv.conf. Obviously you would need to tell WSL to not manage /etc/resolv.conf itself first. Though I think doing this and adding domains to /etc/systemd/resolved.conf is probably just a more complicated way of adding the same domains to /etc/resolv.conf directly; systemd-resolved will use /etc/resolv.conf contents when not managing the conffile itself.
arm000 commentedon Aug 28, 2023
I want to avoid hardcoding the DNS server in resolv.conf as this is fragile. What I'm hoping is that I can override the search domain in one of the /etc/systemd/resolved.conf.d/*.conf files, use the systemd stub DNS and have systemd forward the DNS queries to the nameserver. I don't understand how systemd works inside WSL though. Normally systemd-resolved would get the nameserver from DHCP, does that work the same in WSL?
bramhaag commentedon Sep 27, 2023
It looks like 2.0.0 might finally fix this:
CatalinFetoiu commentedon Sep 27, 2023
Please try enabling "dnsTunneling" and let us know if it fixes the issue. thanks!
you can find more details at https://devblogs.microsoft.com/commandline/windows-subsystem-for-linux-september-2023-update/
CatalinFetoiu commentedon Nov 15, 2023
We have added the following documentation about how DNS suffixes are handled in WSL - https://github.com/MicrosoftDocs/WSL/blob/main/WSL/troubleshooting.md#dns-suffixes-in-wsl
At the moment, to get secondary Windows DNS suffixes configured in WSL you need to have one of the following 2 configs in your wslconfig file
A) networkingMode=nat and dnsTunneling=true
B) networkingMode=mirrored
ahsodex commentedon Jun 27, 2024
Unfortunately, these options are only available on Windows 11, as per:
https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconfig,
This is what I get in Windows 10:
wsl: Unknown key 'networkingMode' in C:\Users\username\.wslconfig:1Can you make this available for those of us in enterprises that still only support Windows 10?
Thanks!
ahsodex commentedon Jun 27, 2024
For now I've added this to my ~/.bashrc (based on above tips):
CatalinFetoiu commentedon Jun 28, 2024
hello Dan Dexter (@ahsodex), thanks for reaching out
Mirrored mode and DNS tunneling are Windows 11 only features, and we are currently not investigating backporting them to Windows 10
cc Craig Loewen (@craigloewen-msft) chanpreetdhanjal
xieve commentedon Jul 16, 2024
For connection-specific suffixes (set by DHCP), one can use this PowerShell command instead:
abenoit-reeliant commentedon Oct 8, 2024
Hello Cătălin Emil Fetoiu (@CatalinFetoiu) . I'm on Windows 11 Pro (23H2). I tried the following, but still do not get the DNS suffixes in WSL. What am I doing wrong ?
net stop LxssManagerAlso tried with this content, and no more luck.
jantari commentedon Oct 8, 2024
abenoit-reeliant did you look at the docs? It doesn't go under
[experimental]: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconfigabenoit-reeliant commentedon Oct 8, 2024
Thanks jantari I did look at the doc, but scrolled too fast and read the wrong header. However if I read correctly this time, it should be in
[wsl2], but this doesn't work either.After analyzing a bit more, I see that the suffixes are defined on one specific interface (they are set up when I connect to a VPN), so that might complicate things more.
The solution by xieve works for me when I use the
ConnectionSpecificSuffixvariant (with the drawback of having to sudo when opening a session).jantari commentedon Oct 14, 2024
There's been a bunch of good solutions posted here already, but the thread's gotten so long and scripts have been iteratively improved on it's not obvious what the best solution is. For any situation where
networkingMode=natordnsTunneling=trueis either unavailable or doesn't work, this should be easy to use and cover all bases:I've been using this for years now, from WSL1 to WSL2. No need to sudo and should cover all scenarios including VPNs without issues.