簡體   English   中英

無法解析主機:github.com 僅在 windows bash

[英]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.

1個

可能是您的/etc/resolv.conf文件已損壞 - 它發生在我身上!

症狀是:

  • WSL 內部的/etc/resolv.conf不是純文本,而是一些二進制垃圾。 它應該是純文本。
  • 例如,您不能從 WSL 內部ping google.comping stackoverflow.com
  • 您可以從 Windows 主機中的 powershell ping 這些域。 Windows git 也可以正常工作。

旁白:有趣的是,今天我在所有機器上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
  1. 編輯你的wsl.conf
sudo nano /etc/wsl.conf
[network]
generateResolvConf = false
  1. 保存此文件並退出。 然后編輯/etc/resolv.conf
sudo nano /etc/resolv.conf
  1. 添加/編輯此行
nameserver 1.1.1.1
  1. 然后關閉您的WSL 控制台 使用管理員打開 Powershell 並關閉 wsl。
wsl --shutdown
  1. 最后,重啟wsl服務
Get-Service LxssManager | Restart-Service

更多信息 - WSL2 - 無互聯網連接。 DNS 問題(名稱解析暫時失敗)

由 P.hunter編輯 1:

當你在 VPN 后面時,你需要將你的名稱服務器設置為與 VPN 提供的相同。

為了那個原因 -

  1. 轉到網絡狀態(在 Windows 上)並單擊更改適配器設置。
  2. 找到您的 VPN 適配器,右鍵單擊它並打開屬性。
  3. 從下拉列表中找到 IpV4 選項,然后將其打開。
  4. 找到提到的 DNS 並在步驟 3 中使用相同的 DNS。

以上答案都不適合我。 但是這個Github 線程答案確實如此。 為了方便重新發布:

啟動 VSCode 守護進程似乎把事情搞砸了

  1. 將其設為您的/etc/wsl.conf文件
[network]
generateResolvConf = false
  1. 關閉wsl
wsl --shutdown
  1. 啟動 wsl 並創建文件: /etc/resolv.conf包含
nameserver 8.8.8.8

PS 如果這個答案沒有幫助, Github 線程上的其他人可能會!

我可以假設您在代理方面遇到問題。

嘗試一下:

git config --global --unset http.proxy
git config --global --unset https.proxy

類似問題: #20370294#5377703

我做了以下步驟來解決這個問題:

  1. 檢查與 inte.net 的連接。
ping stackoverflow.com
  1. 編輯 /etc/resolv.conf,在我的例子中,原因是由於nameserver 172.22.16.1
sudo vim /etc/resolv.conf

添加名稱服務器以指向谷歌服務器

nameserver 8.8.8.8
nameserver 8.8.4.4

並通過添加 # 向原始名稱服務器添加注釋

  1. 重復步驟 1 以再次交叉檢查連接。

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM