Linux 与 WSL2 开发环境怎么走机场代理?命令行与包管理器配置指南
Ubuntu / Debian / WSL2 终端里 git、apt、curl、pip 连不上?一文搞定环境变量、Mirrored 网络模式与代理配置。
在 Windows 上使用 WSL2(Ubuntu / Debian) 或纯 Linux 桌面 进行开发时,即使宿主机已经打开了 Clash Verge Rev,终端里的 git clone、docker pull、apt update 依然可能走不通。
一、Windows + WSL2 最省心的两种方案
1. 开启 Windows 11 WSL2 的 mirrored 镜像网络模式(推荐)
在 C:\Users\<你的用户名>\.wslconfig 中加入:
[wsl2]
networkingMode=mirrored
重启 WSL(wsl --shutdown)后,WSL2 会直接共享宿主机的 127.0.0.1 回环地址,如果在 Windows 端开启了 Clash 的 TUN 模式,WSL2 内无需任何配置即可直接联网。
2. 手动设置代理环境变量
在 ~/.bashrc 或 ~/.zshrc 中添加快捷函数,按需开关:
export http_proxy="http://127.0.0.1:7897"
export https_proxy="http://127.0.0.1:7897"
export all_proxy="socks5://127.0.0.1:7897"
(注:端口请以你客户端实际显示的混合端口为准,常见为 7890 或 7897。)