WSL2 配置代理
发表于更新于
北京
一、WSL2 网络结构
在初代 WSL 中,Linux 子系统和 Windows 共享了网络端口,因此可以直接让子系统访问宿主机的代理服务。但在 WSL2 中,其基于 Hyper-V 运行,导致 Linux 子系统和 Windows 是两台在网络上独立的机器,因此需要通过 IP 进行访问。
二、配置代理软件
首先在自己的代理软件中打开允许来自局域网的连接,之后 WSL2 才可通过局域网使用代理。
三、配置 WSL2
修改.bashrc
修改自己对应的用户配置文件,这里以~/.bashrc为例
- 请将端口改为自己使用的代理软件的端口
- 创建
proxy.conf文件:touch /etc/apt/apt.conf.d/proxy.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\\ ).*') alias proxy=' export https_proxy="socks5://${hostip}:10808"; export http_proxy="socks5://${hostip}:10808"; export all_proxy="socks5://${hostip}:10808"; echo -e "Acquire::http::Proxy \\"<http://$>{hostip}:10808\\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null; echo -e "Acquire::https::Proxy \\"<http://$>{hostip}:10808\\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null; ' alias unproxy=' unset https_proxy; unset http_proxy; unset all_proxy; sudo sed -i -e '/Acquire::http::Proxy/d' /etc/apt/apt.conf.d/proxy.conf; sudo sed -i -e '/Acquire::https::Proxy/d' /etc/apt/apt.conf.d/proxy.conf; '
|
应用代理
1 2 3 4 5 6 7 8 9 10 11
| source ~/.bashrc
proxy
export cat /etc/apt/apt.conf.d/proxy.conf
curl ip.sb
|
四、代理问题
问题
参考的对象类型不支持尝试的操作。(The attempted operation is not supported for the type of object referenced.)
解决方案
- 下载该软件
http://www.proxifier.com/tmp/Test20200228/NoLsp.exe
- 运行命令
text1 2
| NoLsp.exe C:\\windows\\system32\\wsl.exe
|