Useful or not, from you.
WSL WSL2 cannot access Windows proxy
  • Your Windows build number: Microsoft Windows [版本 10.0.18956.1000]

  • What you're doing and what's happening:

I come from China, because of GFW, I cannot access the API of Hacker News, so I have to start a proxy. I use shadowsocks to start a proxy on port 10808, it workd fine, I can access Google.com. I can access sites like Google and hacker news, with netstata -an in power shell:

...
  TCP    127.0.0.1:8080         0.0.0.0:0              LISTENING
  TCP    127.0.0.1:8080         127.0.0.1:59792        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54155        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54156        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54157        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54165        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54368        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54369        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54399        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54400        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54401        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:54409        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:59827        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60354        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60355        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60357        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60359        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60361        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60362        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60372        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:60374        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:60510        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:60512        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:60531        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:60596        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60598        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60600        FIN_WAIT_2
  TCP    127.0.0.1:10808        127.0.0.1:60602        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:60641        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:60678        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:60712        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60714        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60716        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60842        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60844        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60872        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60873        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60876        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60877        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60882        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60884        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60914        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60917        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60918        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60930        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60934        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60937        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60947        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60949        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60964        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:60966        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61002        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61007        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61009        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61015        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61030        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61032        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61034        FIN_WAIT_2
  TCP    127.0.0.1:10808        127.0.0.1:61036        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:61071        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61073        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61076        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61080        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61087        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61089        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61091        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61094        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61096        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61099        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61100        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61103        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61106        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61111        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61115        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61116        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61117        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61120        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61126        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61128        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61129        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61133        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61135        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61137        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61143        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61145        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61147        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61149        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61155        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61157        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61159        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61161        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61162        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61165        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61169        FIN_WAIT_2
  TCP    127.0.0.1:10808        127.0.0.1:61171        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:61173        FIN_WAIT_2
  TCP    127.0.0.1:10808        127.0.0.1:61175        TIME_WAIT
  TCP    127.0.0.1:10808        127.0.0.1:61179        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61181        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61185        ESTABLISHED
  TCP    127.0.0.1:10808        127.0.0.1:61187        ESTABLISHED
...

then I set the proxy:

export http_proxy=http://127.0.0.1:10808
export https_proxy=http://127.0.0.1:10808
// or
sudo nano /etc/apt/apt.conf.d/proxy.conf
Acquire::http::Proxy "http://127.0.0.1:10808";
Acquire::https::Proxy "http://127.0.0.1:10808";

and I want use this proxy in my WSL2, it shows in WSL2, the port is free for use

  • What's wrong / what should be happening instead:
 curl -vv 'https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty'                  
 *   Trying 220.250.64.225...                                                                                           
 * TCP_NODELAY set                                                                                                       
*   Trying ::...                                                                                                        
* TCP_NODELAY set                                                                                                       
* connect to :: port 10808 failed: Connection refused
// and even start a file server on port 10808 without error
That's a useful answer
Without any help

Thanks for first.

➜  ~ cat /etc/resolv.conf                                                                                                                                                                                                                                                                                                                                                  # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.18.144.1
➜  ~ export https_proxy='http://172.18.144.1:10808' 
➜  ~ export http_proxy='http://172.18.144.1:10808'
➜  ~ curl -vv google.com                                                                                                                                                                                                                                                                                                                                               * Rebuilt URL to: google.com/
*   Trying 172.18.144.1...
* TCP_NODELAY set

* connect to 172.18.144.1 port 10808 failed: Connection timed out
* Failed to connect to 172.18.144.1 port 10808: Connection timed out
* Closing connection 0
curl: (7) Failed to connect to 172.18.144.1 port 10808: Connection timed out

still not work. I give up and spin another shadowsocks server in WSL2, and it works.

➜  ~ export https_proxy='socks5://127.0.0.1:1081'                                                                                                                                                                                                                                                                                                                          ➜  ~ export http_proxy='socks5://127.0.0.1:1081'
➜  ~ curl -vv google.com                                                                                                                                                                                                                                                                                                                                                   * Rebuilt URL to: google.com/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* SOCKS5 communication to google.com:80
* SOCKS5 connect to IPv4 216.58.200.46 (locally resolved)
* SOCKS5 request granted.
* Connected to 127.0.0.1 (127.0.0.1) port 1081 (#0)
> GET / HTTP/1.1
> Host: google.com
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Location: http://www.google.com/
< Content-Type: text/html; charset=UTF-8
< Date: Mon, 12 Aug 2019 09:16:03 GMT
< Expires: Wed, 11 Sep 2019 09:16:03 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 127.0.0.1 left intact

You just need to turn on the "connection from private net work" option. image