原文解决方式:WSL2 DNS issues
环境
本人环境是wsl1,Ubuntu
报错情况
无法更新github上的代码,报错如下:
fatal: unable to look up github.com (port 9418) (Temporary failure in name resolution)
意思就是网络不行,会发现去ping google等都不行
解决方式
Incredibly unhelpful.
It is the issue for many people, it is the same in issue trackers/forums/etc across the internet.
The WSL instance cannot resolve domain names. Editing resolv.conf to point to a functioning nameserver "works" for the duration of the session, but as soon as the distro is rebooted resolv.conf is regenerated using WSL's original template. Because etc/resolv.conf
is actually a symlink to run/resolvconf/resolv.conf
Steps that have worked for me:
- Boot your distro.
cd ~/../../etc
- Create
wsl.conf
, however you see fit.sudo vim wsl.conf
,sudo touch wsl.conf
and edit it later, whatever. - Add these lines to
wsl.conf
:
[network]
generateResolvConf=false
-
exit
or in Windows cmdwsl --terminate [YourDistroName]
- Boot your distro.
At this point, thanks to wsl.conf, run/resolvconf should no longer exist and will never be created again.
cd ~/../../etc
-
sudo rm resolv.conf
- this deletes the existing symlink file. - Create a new
resolv.conf
, however you see fit.sudo vim resolv.conf
,sudo touch resolv.conf
and edit it later, whatever. - Add this line to
resolv.conf
:
nameserver 8.8.8.8
replace 8.8.8.8 with your preferred functional nameserver.
-
exit
or in Windows cmdwsl --terminate [YourDistroName]
-
wsl --shutdown
just to be sure that you've definitely killed everything. - Boot your distro.
- Confirm that your resolv.conf changes are still in effect, or just ping a domain name and cry tears of joy after struggling to get this working for far too fucking long.
网友评论