curl: (6) Could not resolve host: on WSL

Viewed 10692

I have installed Ubuntu 20.04 LTS on WSL.

I'm trying to run the following command:

curl https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch

It fails with error:

curl: (6) Could not resolve host: developer.mozilla.org

I have tried something else, and it worked, e.g.

$ curl https://google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

Here's some details:

$ nslookup developer.mozilla.org
Server:         127.0.0.1
Address:        127.0.0.1#53

Non-authoritative answer:
developer.mozilla.org   canonical name = d1avawhiqh9uo1.cloudfront.net.
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 52.84.112.124
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 52.84.112.61
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 52.84.112.82
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 52.84.112.105
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 2600:9000:203c:8e00:13:e62f:2040:93a1
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 2600:9000:203c:9c00:13:e62f:2040:93a1
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 2600:9000:203c:a000:13:e62f:2040:93a1
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 2600:9000:203c:d800:13:e62f:2040:93a1
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 2600:9000:203c:f600:13:e62f:2040:93a1
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 2600:9000:203c:200:13:e62f:2040:93a1
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 2600:9000:203c:1c00:13:e62f:2040:93a1
Name:   d1avawhiqh9uo1.cloudfront.net
Address: 2600:9000:203c:4e00:13:e62f:2040:93a1

Please help to understand the problem.

3 Answers

For me it happened after the Windows 11 upgrade.

I had to update i /etc/wsl.conf and restart my WSL instance

[network]
generateResolvConf = true

for posterity ... ( lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.4 LTS Release: 20.04 Codename: focal)

the work around for wsl2 in windows 10 and trying to reach localhost is :

"cmd.exe /C curl http://127.0.0.1 ..."

Related