-
-
Save akshayhiremath/1b3bff527b3eca6cd41cf60ce88f3a56 to your computer and use it in GitHub Desktop.
Fix DNS resolution in WSL2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -l (Get the <WSL distribution name>. Debian-XX or Ubuntu-XX (Default) etc.) | |
5. wsl --terminate <WSL distribution name> (Terminate WSL in Windows cmd, <WSL distribution name> from the step 4). | |
6. cd ~/../../etc (go to etc folder in WSL). | |
7. sudo rm -Rf resolv.conf (Delete the resolv.conf file). | |
8. In windows cmd, ps or terminal with the vpn connected do: Get-NetIPInterface or ipconfig /all for get the dns primary and | |
secondary. Look for Ethernet adaptor with Description "Cisco AnyConnect...". From under it take values for DNS Servers. | |
It has primary and secondary DNS server IPs. | |
9. Use commands in next two steps by replacing X.X.X.X for values of Primary and Secondary DNS server IPs respectively | |
10. echo "nameserver X.X.X.X" | sudo tee resolv.conf (Create resolv.conf and append the line.) | |
11. echo "nameserver X.X.X.X" | sudo tee -a resolv.conf (Append the line in resolv.conf) | |
12. wsl --terminate <WSL distribution name> (Terminate WSL in Windows cmd, <WSL distribution name> from the step 4). | |
13. sudo chattr +i resolv.conf | |
14. 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment