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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 29
Hi folks, just found another workaround:
If you have installed
Docker Desktop for Windows(with WSL2 backend, in my case), just usehost.docker.internal:and it just works!
I have no idea about the VM’s networking, but
host.docker.internalis something like192.168.1.5, so it accesses host just like someone else in LAN.You just need to turn on the “connection from private net work” option.
You can refer to this blog(Chinese version) to set WSL2 proxy.
You might be able to use your Window’s IP address as described here instead of
https_proxy=http://127.0.0.1:10808. But that address moves all over the place, and you might have to jump firewall and othershadowsocksconfig hurdles (dunno).If it were me I’d do the socks proxy WSL-side. Try setting up the socks proxy entirely in your WSL 2 distro, and point your WSL2-side
proxy.confto WSL’slocalhost. Both your Windows and your WSL socks proxies should both work okay simultaneously.Heads up the devs recently added tunneling
127.0.0.1in the Windows ➡️ WSL direction, but not the WSL ➡️ Windows direction. Once support for the other direction is implemented, your scenario will probably work out of the box.Do the profanity in 官话, that way it slips by. Bonne chance.
Thanks for first.
still not work. I give up and spin another shadowsocks server in WSL2, and it works.
Is there any place we can check to know when the
WSL->Windowsdirection will be completed?The mother f–ker is frowned upon and should probably be edited in your post. But if it translates into Mandarin well, no one will over here will notice.
#4619
用clash for windows改半天出不来, 默默打开了软路由里的clash
这里是一个更好的简易解决方案:WSL Proxy Configuration 2024 New Solution (using v2rayN as an example) - Simple and Effective
WSL2中使用
curl/wget raw.github...或git命令总是因为网速问题失败,因此在部署环境时需要配置网络,但WSL2通过虚拟机方式实现,网络不再像WSL1一样与Windows共享,所以想使用宿主机的网络proxy就比较麻烦。网上可找到的教程多为修改DNS服务器地址、通过局域网实现proxy,如:
但上述方案实现困难,稍有不慎(如Windows防火墙等配置不正确)就会前功尽弃。且新版WSL设置proxy环境变量后,会提示:
WSL: A localhost proxy configuration was detected but not mirrored into WSL. WSL in NAT mode does not support localhost proxies.此时,proxy设置失败。wsl: 检测到 localhost 配置,但未镜像到 WSL。NAT 模式下的 WSL 不支持 localhost。 #10753本文提出一种WSL配置网络实现代理的新解决方案,使用网络镜像极大简化了繁琐复杂的操作流程,同时给出v2rayN配置示例,无需修改DNS和防火墙,也无需开启局域网共享,可放心操作。
It is abnormal. If you are using V2RayN for proxy, I think that you mistake the socks port and HTTP port. As for V2RayN, the 10808 port is reserved for socks, 10809 is reserved for HTTP proxy by default.
sudo git config --global http.proxy socks5://172.23.144.1:10808
“Sudo” should be added, otherwise it will not take effect.
@solider245 分两种情况
(仅适用于 WSL2 环境下的 git 配置)
① HTTP 访问 git,命令行:
git config --global http.https://github.com.proxy http://host.docker.internal:1080② SSH 访问 git,编辑
~/.ssh/config文件:In English:
HOW TO CONFIG GIT WITH PROXY IN WSL2
a) You access git via HTTP:
Shell command
git config --global http.https://github.com.proxy http://host.docker.internal:1080b) You access git via SSH:
edit file
~/.ssh/configemmmmmm, and what’s this meaning?
sorry, my english is very bad. 🤣