12

I have installed ubuntu 18.04(WSL) in my win 10 64 bit, 1903.

For the command git clone https://github.com/facebookresearch/fastText.git,

it works well in git bash(git for windows) and ubuntu 18.04 shell but not in bash (C:\Windows\System32\bash.exe), the error message is

$ 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

Animeta
  • 1,241
  • 3
  • 16
  • 30
  • 2
    First try to `ping stackoverflow.com`, if not works check if Windows Firewallis blocking connections. Also try to add nameserver with `rm /etc/resolv.conf; echo nameserver 1.1.1.1 > /etc/resolv.conf`. – Biswapriyo Apr 13 '19 at 05:21

5 Answers5

24

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 or ping 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
d-man
  • 476
  • 4
  • 24
abulka
  • 1,316
  • 13
  • 18
15
  1. Edit your wsl.conf
sudo nano /etc/wsl.conf
[network]
generateResolvConf = false
  1. Save this file and exit. Then edit /etc/resolv.conf.
sudo nano /etc/resolv.conf
  1. Add/Edit this line
nameserver 1.1.1.1
  1. Then close your WSL console. Open Powershell with admin and shutdown the wsl.
wsl --shutdown
  1. At last, restart the wsl service
Get-Service LxssManager | Restart-Service

More info - WSL2 - No internet connectivity. DNS Issues(Temporary failure in name resolution)

Edit 1 By P.hunter:

When your are behind an VPN, you need to set your nameserver to same what the VPN provides.

For that -

  1. Go to Network Status (On Windows) and click on change adapter settings.
  2. Find the adapter of your VPN, right click on it and open properties.
  3. Find IpV4 option from the dropdown, and open it.
  4. Find the DNS mentioned and use the same in Step 3.
Germa Vinsmoke
  • 3,541
  • 4
  • 24
  • 34
4

None of the above answers worked for me. But this answer from this Github thread did. Reposting for ease:

It seems launching the VSCode daemon messes things up

  1. Make this your /etc/wsl.conf file
[network]
generateResolvConf = false
  1. Shutdown wsl
wsl --shutdown
  1. Start wsl and create the file: /etc/resolv.conf containing
nameserver 8.8.8.8

P.S. if this answer doesn't help, others on the Github thread might!

codeananda
  • 939
  • 1
  • 10
  • 16
3

I did the following step to resolve the issue:

  1. Check the connection to the internet.
ping stackoverflow.com
  1. Edit /etc/resolv.conf, in my case the reason is due to the nameserver 172.22.16.1
sudo vim /etc/resolv.conf

add the nameserver to point to google server

nameserver 8.8.8.8
nameserver 8.8.4.4

and add a comment to the original nameserver by adding #

  1. Repeat step 1 to cross-check the connection again.

Hope this helps!

0

I can assume that you have problems with proxying.

Try it:

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

Similar problem: #20370294 and #5377703

qwsj
  • 426
  • 3
  • 13
  • I take a try but not work, I don't think it's problem with proxying because that command works well in `git bash` and `ubuntu 18.04` shell. – Animeta Apr 12 '19 at 10:25