0 views 109 chars · 105 words 1 min read

WSL网络代理

我电脑开启了VPN,使用了localhost:port 的形式。但是打开WSL的Ubuntu,有如下报错:

Ubuntu Terminal
100%Bash / Shell
1wsl: 检测到 localhost 代理配置,但未镜像到 WSL。NAT 模式下的 WSL 不支持 localhost 代理。

查看WSL的版本为3以上。

PowerShell
100%Bash / Shell
1> wsl --version2WSL 版本: 3.0.5.03内核版本: 6.18.58.1-14WSLg 版本: 1.0.795MSRDC 版本: 1.2.73916Direct3D 版本: 1.611.1-815285117DXCore 版本: 10.0.26100.1-240331-1435.ge-release8Windows 版本: 10.0.26300.9974

在C:\Users\user_name\ 目录下新建.wslconfig 文件。然后在PowerShell下使用wsl --shutdown重启WSL。

.wslconfig
100%INI / TOML
1[wsl2]2networkingMode=mirrored3autoProxy=true4dnsTunneling=true5firewall=true6 7[experimental]8autoMemoryReclaim=gradual

如果,在WSL下网络配置和Windows一样就是就是成功了。

IP Check
100%Bash / Shell
1# PowerShell2> ipconfig /all3   IPv4 地址 . . . . . . . . . . . . : 192.168.0.28(首选)4   子网掩码  . . . . . . . . . . . . : 255.255.255.05 6# WSL7> ip a8    inet 192.168.0.28/24 brd 192.168.0.255 scope global noprefixroute eth0