Skip to content

Instantly share code, notes, and snippets.

@1eedaegon
Last active August 17, 2023 12:07
Show Gist options
  • Save 1eedaegon/becd2003edf0ca3ab52a85ba5f219fd1 to your computer and use it in GitHub Desktop.
Save 1eedaegon/becd2003edf0ca3ab52a85ba5f219fd1 to your computer and use it in GitHub Desktop.
wsl2 with docker desktop unable to connect to dns

Because docker desktop use subnet 192.168.65.0/24

Could not resolve DNS after start Docker desktop

curl www.naver.com
curl: (6) Could not resolve host: www.naver.com

Solution 1: Change docker desktop network cidr

  1. Run Docker desktop > Settings > Resources > Network
  2. Change docker subnet 192.168.65.0/24 to 10.x.x.x/24 like 10.0.65.0/24
  3. Apply and Restart
  4. Test
curl www.naver.com
<html>
<head><title>302 Found</title></head>
<body>
<center><h1>302 Found</h1></center>
<hr><center> NWS </center>
</body>
</html>

Solution 2: Change hyper-v network switch(temporary)

  1. Run Win+Q > Hyper-V manager > right side Virtual switch manager
  2. Create external virtual switch
  3. Input this options:
    • Name: wsl-external
    • Connection type: External
    • Select "Allow management operating system to share this network adapter"
    • Apply ans Save
  4. Move C:\Users\[User name]
  5. Now add to .wslconfig text like this:
[wsl2]
networkingMode=bridged
vmSwitch=wsl-external
  1. Save and close
  2. Shutdown wsl2
wsl --shutdown
  1. Connect wsl2 distro and test connection
❯ curl google.com -vvv
*   Trying 142.251.42.174:80...
* Connected to google.com (142.251.42.174) port 80 (#0)
> GET / HTTP/1.1
> Host: google.com
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Location: http://www.google.com/
< Content-Type: text/html; charset=UTF-8
< Date: Wed, 01 Feb 2023 06:40:49 GMT
< Expires: Fri, 03 Mar 2023 06:40:49 GMT
< Cache-Control: public, max-age=2592000
< Server: gws
< Content-Length: 219
< X-XSS-Protection: 0
< X-Frame-Options: SAMEORIGIN
<
<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="http://www.google.com/">here</A>.
</BODY></HTML>
* Connection #0 to host google.com left intact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment