-
Star
(735)
You must be signed in to star a gist -
Fork
(125)
You must be signed in to fork a gist
-
-
Save coltenkrauter/608cfe02319ce60facd76373249b8ca6 to your computer and use it in GitHub Desktop.
More recent resolution: | |
1. cd ~/../../etc (go to etc folder in WSL). | |
2. echo "[network]" | sudo tee wsl.conf (Create wsl.conf file and add the first line). | |
3. echo "generateResolvConf = false" | sudo tee -a wsl.conf (Append wsl.conf the next line). | |
4. wsl --terminate Debian (Terminate WSL in Windows cmd, in case is Ubuntu not Debian). | |
5. cd ~/../../etc (go to etc folder in WSL). | |
6. sudo rm -Rf resolv.conf (Delete the resolv.conf file). | |
7. In windows cmd, ps or terminal with the vpn connected do: Get-NetIPInterface or ipconfig /all for get the dns primary and | |
secondary. | |
8. With the dns primary and secondary getted replace the numbers in the next step in the X.X.X.X | |
9. echo "nameserver X.X.X.X" | sudo tee resolv.conf (Create resolv.conf and append the line.) | |
10. echo "nameserver X.X.X.X" | sudo tee -a resolv.conf (Append the line in resolv.conf) | |
11. wsl --terminate Debian (Terminate WSL in Windows cmd, in case is Ubuntu not Debian). | |
12. sudo chattr +i resolv.conf | |
13. And finally in windows cmd, ps or terminal: | |
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000 | |
Credit: @MartinCaccia, @yukosgiti, @machuu and @AlbesK: | |
https://github.com/microsoft/WSL/issues/4277 | |
https://github.com/microsoft/WSL/issues/4246 | |
--- | |
Original resoltuion: | |
1. Create a file: /etc/wsl.conf. | |
2. Put the following lines in the file in order to ensure the your DNS changes do not get blown away | |
[network] | |
generateResolvConf = false | |
3. In a cmd window, run wsl --shutdown | |
4. Restart WSL2 | |
5. Create a file: /etc/resolv.conf. If it exists, replace existing one with this new file. | |
6. Put the following line in the file | |
nameserver 8.8.8.8 # Or use your DNS server instead of 8.8.8.8 which is a Google DNS server | |
7. Repeat step 3 and 4. You will see git working fine now. | |
Credit: https://github.com/microsoft/WSL/issues/4285#issuecomment-522201021 |
@ThePlenkov solution worked best, specifying just one DNS of my VPN software resulted in slow queries, but with your command,
it dumped all valid nameservers into WSL and now curl: time_namelookup: 0.001621s
Thank you for the simplest solution. It worked like a charm.
I have found that with dnsTunneling=true
in .wslconfig
in windows and generateResolvConf=true
in /etc/wsl.conf
in wsl (both of which are now the defaults), DNS is working well for me. I had generateResolvConf=false
from previous efforts to fix this, which was preventing dnsTunneling from working
dnsTunneling
The entire fix:
- Create
.wslconfig
under%USERPROFILE%
- Add:
[wsl2]
dnsTunneling=true
That's it. According to the documentation, it should be the default. Apparently it is not.
I have found that with
dnsTunneling=true
in.wslconfig
in windows andgenerateResolvConf=true
in/etc/wsl.conf
in wsl (both of which are now the defaults), DNS is working well for me. I hadgenerateResolvConf=false
from previous efforts to fix this, which was preventing dnsTunneling from working
dnsTunneling
The entire fix:
- Create
.wslconfig
under%USERPROFILE%
- Add:
[wsl2] dnsTunneling=true
That's it. According to the documentation, it should be the default. Apparently it is not.
I can confirm those posts. Enabling generateResolvConf=true
again and putting dnsTunneling=true
to .wslconfig
works on Windows 11.
I use WSL2 2.4.10.0.
By using the proposed solution (default setup with the .wslconfig file), I see strange behaviour:
ping google.com
works fine, however, after several minutes this command gives ping: connect: Network is unreachable
in the output.
The wsl—- shutdown
fixes the problem, but I have to do it repeatedly.
I have no VPN, just WiFi at home.
If anyone wants to propose changes to the gist, please provide a codebox with the desired state of the gist. (Perhaps we could do it in markdown) and I will gladly credit you for helping.
For Windows novices like me, you can cut-paste this to Powershell and press enter (thanks AI):
@"
[wsl2]
dnsTunneling=true
"@ | Set-Content -Path "$env:USERPROFILE\.wslconfig"
And remember to re-enable autogeneration of resolv.conf (within WSL), and restart WSL (again).
Created an issue for
DNS resolution for internal sites doesn't work from inside WSL2 distros when using Global Secure Access Client as VPN.
microsoft/WSL#11745