2021-06-17 WSL报错:fatal: unable to look up github.com (port 9418) (Temporary failure in name resol...

原文解决方式: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:

  1. Boot your distro.
cd ~/../../etc
  1. Create wsl.conf, however you see fit. sudo vim wsl.conf, sudo touch wsl.conf and edit it later, whatever.
  2. Add these lines to wsl.conf:
[network]
generateResolvConf=false
  1. exit or in Windows cmd wsl --terminate [YourDistroName]
  2. Boot your distro.
    At this point, thanks to wsl.conf, run/resolvconf should no longer exist and will never be created again.
cd ~/../../etc
  1. sudo rm resolv.conf - this deletes the existing symlink file.
  2. Create a new resolv.conf, however you see fit. sudo vim resolv.conf, sudo touch resolv.conf and edit it later, whatever.
  3. Add this line to resolv.conf:
nameserver 8.8.8.8

replace 8.8.8.8 with your preferred functional nameserver.

  1. exit or in Windows cmd wsl --terminate [YourDistroName]
  2. wsl --shutdown just to be sure that you've definitely killed everything.
  3. Boot your distro.
  4. 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.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容