Win11 下为 WSL2 安装的 Ubuntu 配置本地代理

网上的教程没一个靠谱的。

  1. 为 WSL2 防火墙添加新规则,或直接关闭防火墙
    添加新规则:New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action Allow
    2025-06-11T03:41:44.png
  2. 打开代理软件局域网连接
    2025-06-11T03:40:29.png
  3. 查看代理软件的网络接口中 WSL 对应的 ip 地址
    2025-06-11T03:40:49.png
  4. 查看代理软件的端口
    2025-06-11T03:42:49.png
  5. 打开 Ubuntu 终端,配置代理环境变量
    export http_proxy="http://<ip地址>:<端口>"
    export https_proxy="https://<ip地址>:<端口>"
    2025-06-11T03:43:07.png
  6. 检查代理是否正常,如果不正常,说明上面的步骤没有做对
    curl -L google.com
    2025-06-11T03:45:31.png

参考文献:

By Number_Sir On