bash - 无法解析主机:github.com ONLY in windows bash
问题描述
我已经在我的 win 10 64 位 1903 中安装了 ubuntu 18.04(WSL)。
对于命令git clone https://github.com/facebookresearch/fastText.git
,
它在git bash
(git for windows) 和ubuntu 18.04
shell 中运行良好,但在bash
(C:\Windows\System32\bash.exe) 中运行良好,错误消息是
$ git clone https://github.com/facebookresearch/fastText.git
Cloning into 'fastText'...
fatal: unable to access 'https://github.com/facebookresearch/fastText.git/': Could not resolve host: github.com
我的电脑里只有两个.gitconfig
文件,一个用于shell git bash
,另一个用于ubuntu 18.04
shell。我认为shell可能在某种程度上ubuntu 18.04
等于但肯定有问题。bash
bash
解决方案
It could be that your /etc/resolv.conf
file is corrupt - it happened to me!
Symptoms are:
- Inside WSL
/etc/resolv.conf
is not plain text but some binary garbage. It should be plain text. - You cannot e.g.
ping google.com
orping stackoverflow.com
from inside WSL. - You can ping those domains OK from powershell in the windows host. Windows git also works OK.
Aside: Interestingly ping github.com
fails for me today on all my machines but that doesn't stop me from visiting github in my browser or using git - strange.
The solution is to sudo rm /etc/resolv.conf
and restart WSL - windows will recreate that file for you and you should be able to ping away and use git once more from within WSL.
To restart WSL - open a Powershell terminal in Administrator mode and run the following commands. (taken from @germa-vinsmoke 's answer)
wsl --shutdown
Get-Service LxssManager | Restart-Service
推荐阅读
- javascript - shopify-api-node 为私有应用返回状态 401 未授权
- python - 对象列表的自定义列表表示
- python - 我们可以对 pandas 数据帧上的任何函数进行矢量化吗?
- html - 列表项中的 CSS 边框
- cuda - CUDA 如何知道何时同步?
- javascript - preact-compat 提供了哪些 preact 没有的功能?
- algorithm - 合并长度为 N 的 K 个排序数组
- php - 更新数据库中的外键以在 PHP 中注册用户的日志
- c++ - if (a & 1) 表示 a 是 int 是什么意思?
- python - 第一行未被识别为列标题