记录内容:WSL2 配置代理

前置条件

  • 确保 Windows 上已配置好代理工具(如 V2ray)。

步骤

  1. C:\Users\<user> 目录下创建 WSL 配置文件 .wslconfig
[wsl2]
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true
  1. 在 WSL 中配置动态代理,vi ~/.bashrc,输入以下内容
# 动态代理配置 - 使用 localhost(镜像网络模式下有效)
export http_proxy="http://localhost:10808"
export https_proxy="http://localhost:10808"
export HTTP_PROXY="http://localhost:10808"
export HTTPS_PROXY="http://localhost:10808"
 
# 可选:为某些地址不走代理
export no_proxy="localhost,127.0.0.1,::1"
  1. 运行 source ~/.bashrc 刷新配置
  2. 运行 curl cip.cc 进行测试