[英]Could not resolve host: github.com ONLY in windows bash
我在 win 10 64 位 1903 中安裝了 ubuntu 18.04(WSL)。
對於命令git clone https://github.com/facebookresearch/fastText.git
,
它在git bash
(Windows 的 git)和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
I have only two .gitconfig
file in my pc, one for git bash
and another for ubuntu 18.04
shell. I think ubuntu 18.04
shell may equal to bash
in some degree but the bash
must have problems.
可能是您的/etc/resolv.conf
文件已損壞 - 它發生在我身上!
症狀是:
/etc/resolv.conf
不是純文本,而是一些二進制垃圾。 它應該是純文本。ping google.com
或ping stackoverflow.com
。 旁白:有趣的是,今天我在所有機器上ping github.com
失敗了,但這並沒有阻止我在瀏覽器中訪問 github 或使用 git - 奇怪。
解決方案是執行sudo rm /etc/resolv.conf
並重新啟動 WSL - Windows 將為您重新創建該文件,您應該能夠從 WSL 中再次 ping 並再次使用 git。
要重新啟動 WSL - 在管理員模式下打開 Powershell 終端並運行以下命令。 (取自@germa-vinsmoke 的回答)
wsl --shutdown
Get-Service LxssManager | Restart-Service
wsl.conf
sudo nano /etc/wsl.conf
[network]
generateResolvConf = false
/etc/resolv.conf
。sudo nano /etc/resolv.conf
nameserver 1.1.1.1
wsl --shutdown
Get-Service LxssManager | Restart-Service
更多信息 - WSL2 - 無互聯網連接。 DNS 問題(名稱解析暫時失敗)
由 P.hunter編輯 1:
當你在 VPN 后面時,你需要將你的名稱服務器設置為與 VPN 提供的相同。
為了那個原因 -
我做了以下步驟來解決這個問題:
ping stackoverflow.com
nameserver 172.22.16.1
sudo vim /etc/resolv.conf
添加名稱服務器以指向谷歌服務器
nameserver 8.8.8.8
nameserver 8.8.4.4
並通過添加 # 向原始名稱服務器添加注釋
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.