Windows 网络代理客户端配置完全指南:系统代理、PAC、TUN 模式、分应用代理与排障
Windows 上用代理不是简单填个 IP 端口就完事:系统代理只对走 WinINET 的程序有效,cmd/PowerShell/git/curl/WSL 各有自己的环境变量,TUN 模式全局接管又有路由冲突。本文从代理客户端使用者视角出发,覆盖 Windows 系统代理设置(GUI + 注册表 + netsh winhttp)、HTTP_PROXY/HTTPS_PROXY/NO_PROXY 环境变量逐个讲、PAC 自动配置文件、PAC URL、常见代理客户端 Clash Verge / v2rayN / Sing-box 的 TUN 模式与系统代理模式区别、按应用配置(Git/Docker/WSL/npm/pip/curl/PowerShell/IDE)、分应用路由规则、代理不生效排查 12 步、以及全局 TUN 与 WSL/虚拟机冲突的终极解决方案。
一、Windows 代理的三层体系
很多人以为「设了系统代理就全局走代理了」,实际不是。Windows 的网络栈是分层的,不同层有不同的代理机制:
flowchart TB L3["Layer 3:TUN 模式(虚拟网卡,全局接管所有流量)<br/>Clash TUN / v2rayN TUN / sing-box tun<br/>→ 几乎所有程序都走代理(包括 ping / ssh / RDP)"] L2["Layer 2:环境变量(HTTP_PROXY / HTTPS_PROXY)<br/>→ 只对读环境变量的程序有效(curl / git / npm / pip)<br/>→ cmd / PowerShell 各自独立,不继承系统代理"] L1["Layer 1:系统代理(WinINET / Internet Options)<br/>→ 只对走 WinINET API 的程序有效<br/>→ Edge / Chrome / IE / 部分 .NET 程序<br/>→ cmd / git / curl / Python / WSL 不走这层"] L3 --> L2 --> L1
| 层 | 覆盖范围 | 不覆盖 | 配置方式 |
|---|---|---|---|
| 系统代理 | 浏览器、.NET 程序、部分桌面应用 | 命令行工具、WSL、Docker、游戏 | 设置 → 网络 → 代理 |
| 环境变量 | curl/git/npm/pip/wget 等 CLI | 不读环境变量的 GUI 程序 | setx / $env: |
| TUN 模式 | 几乎所有流量(含 ICMP/SSH) | 被路由规则排除的 IP/域名 | 客户端 TUN 开关 |
为什么你的代理不生效:90% 是因为你的程序不读系统代理那一层,需要单独配环境变量或在 TUN 模式下跑。
二、系统代理设置(Layer 1)
1.1 图形界面设置
Windows 10/11 设置 → 网络和 Internet → 代理
手动设置代理
┌───────────────────────────────────────┐
│ 使用代理服务器 [开] │
│ │
│ 代理 IP 地址: 127.0.0.1 端口: 7890 │
│ │
│ 请勿对以下列表中的地址使用代理服务器 │
│ (例外): localhost;127.*;10.*;172.* │
│ │
│ [保存] │
└───────────────────────────────────────┘填的是你代理客户端的本地监听地址。常见客户端的默认端口:
| 客户端 | 默认 HTTP 代理端口 | 默认 SOCKS5 端口 | 默认 Mixed 端口 |
|---|---|---|---|
| Clash Verge Rev | 7890 | 7891 | 7890 |
| v2rayN | 10809 | 10808 | 10809 |
| sing-box | 2080 | 2080 | 2080 |
| Shadowsocks | — | 1080 | — |
例外列表(不经过代理的地址)用分号分隔,支持通配符:
localhost— 本地127.*— 回环10.*;172.16.*;192.168.*— 内网*.local— mDNS*.cn— 国内域名全直连
1.2 Internet 选项(传统面板)
控制面板 → Internet 选项 → 连接 → 局域网设置和设置 App 是同一个东西,改哪个都行。但这个面板多了 PAC 自动配置:
┌────────────────────────────────────────┐
│ 自动检测设置 [开/关] │
│ │
│ 使用自动配置脚本 [开] │
│ 脚本地址: http://127.0.0.1:7890/pac │
│ │
│ 使用代理服务器 [开] │
│ 地址: 127.0.0.1 端口: 7890 │
│ [高级] → 可以给 HTTP/HTTPS/FTP 分开配 │
└────────────────────────────────────────┘PAC 和手动代理不能同时用:如果填了 PAC 脚本地址,手动代理会被忽略。
1.3 注册表位置
系统代理存在注册表里,可以用 .reg 文件批量导入:
; 开启系统代理(HTTP 代理 127.0.0.1:7890)
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=dword:00000001
"ProxyServer"="127.0.0.1:7890"
"ProxyOverride"="localhost;127.*;10.*;172.16.*;192.168.*;*.local"
; 关闭系统代理
; "ProxyEnable"=dword:00000000应用注册表后需要通知系统刷新(不重启):
# 刷新代理设置(让 Edge/Chrome 立即生效)
$settings = Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$signature = @"
[DllImport("wininet.dll", SetLastError=true)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
"@
$type = Add-Type -MemberDefinition $signature -Name "WinINet" -Namespace "PInvoke" -PassThru
$type::InternetSetOption([IntPtr]::Zero, 39, [IntPtr]::Zero, 0) # PROXY_SETTINGS_CHANGED
$type::InternetSetOption([IntPtr]::Zero, 37, [IntPtr]::Zero, 0) # REFRESH1.4 netsh winhttp 设置(系统级)
# 管理员 PowerShell
# 查看当前 winhttp 代理
netsh winhttp show proxy
# 设置 winhttp 代理(影响 Windows Update、部分系统组件)
netsh winhttp set proxy 127.0.0.1:7890
# 设置带例外
netsh winhttp set proxy 127.0.0.1:7890 bypass-list="localhost;127.*;10.*;172.*;192.168.*"
# 清除
netsh winhttp reset proxy注意:netsh winhttp 和系统代理(Internet Options)是两套独立的设置,互不影响。Windows Update 走 winhttp,浏览器走 Internet Options。
1.5 PAC 自动配置文件
PAC(Proxy Auto-Configuration)是一个 JavaScript 函数,让浏览器自己判断每个 URL 走不走代理。
// proxy.pac
function FindProxyForURL(url, host) {
// 1. 本地直连
if (isInNet(host, "127.0.0.0", "255.0.0.0")) return "DIRECT";
if (isInNet(host, "10.0.0.0", "255.0.0.0")) return "DIRECT";
if (isInNet(host, "172.16.0.0", "255.240.0.0")) return "DIRECT";
if (isInNet(host, "192.168.0.0", "255.255.0.0")) return "DIRECT";
// 2. 国内域名直连
if (dnsDomainIs(host, ".cn")) return "DIRECT";
if (dnsDomainIs(host, "baidu.com")) return "DIRECT";
if (dnsDomainIs(host, "taobao.com")) return "DIRECT";
if (dnsDomainIs(host, "aliyun.com")) return "DIRECT";
// 3. 其他走代理
return "PROXY 127.0.0.1:7890";
}使用方式:把文件放到 Web 服务器或本地,在 Internet 选项里填 file:///C:/proxy.pac 或 http://127.0.0.1:8080/proxy.pac。
PAC vs 手动代理:
- 手动代理:所有流量走代理(除了例外列表)
- PAC:按 URL 动态决定走不走代理,更灵活但需要维护规则
Clash/v2rayN 自带 PAC:大部分代理客户端自带 http://127.0.0.1:端口/pac 接口,不需要自己写 PAC 文件。
三、环境变量配置(Layer 2)
2.1 三个核心变量
| 变量 | 作用 | 示例 |
|---|---|---|
HTTP_PROXY | HTTP 请求走代理 | http://127.0.0.1:7890 |
HTTPS_PROXY | HTTPS 请求走代理 | http://127.0.0.1:7890 |
ALL_PROXY | 所有协议(含 SOCKS) | socks5://127.0.0.1:7891 |
NO_PROXY | 不走代理的地址 | localhost,127.0.0.1,10.*,192.168.*,.internal |
⚠️ 注意:HTTP_PROXY 的值要带 http:// 协议头,不要只写 127.0.0.1:7890,否则有些程序解析不了。
2.2 永久设置(所有终端生效)
# PowerShell 永久设置(重启终端后仍然有效)
setx HTTP_PROXY "http://127.0.0.1:7890"
setx HTTPS_PROXY "http://127.0.0.1:7890"
setx NO_PROXY "localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,*.internal"
# 删除(设为空字符串不是删除,用 unset 方式)
# Windows 没有原生 unset,需要删注册表:
# HKCU\Environment 下删除对应键值2.3 临时设置(当前终端窗口)
CMD:
set HTTP_PROXY=http://127.0.0.1:7890
set HTTPS_PROXY=http://127.0.0.1:7890
set NO_PROXY=localhost,127.0.0.1PowerShell:
$env:HTTP_PROXY = "http://127.0.0.1:7890"
$env:HTTPS_PROXY = "http://127.0.0.1:7890"
$env:NO_PROXY = "localhost,127.0.0.1"Git Bash:
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export ALL_PROXY=socks5://127.0.0.1:78912.4 验证环境变量
# PowerShell
echo $env:HTTP_PROXY
echo $env:HTTPS_PROXY
# CMD
echo %HTTP_PROXY%
# Git Bash
echo $HTTP_PROXY
# 测试是否走代理
curl -v https://httpbin.org/ip 2>&1 | findstr "origin"
# 如果返回的 IP 是代理服务器 IP → 生效四、按应用配置代理
3.1 Git
# 全局配置代理
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
# 只对特定域名走代理
git config --global http.https://github.com.proxy http://127.0.0.1:7890
# 使用 SOCKS5
git config --global http.proxy socks5://127.0.0.1:7891
git config --global https.proxy socks5://127.0.0.1:7891
# 查看当前代理配置
git config --global --get http.proxy
git config --global --get https.proxy
# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
# 只取消 github 的
git config --global --unset http.https://github.com.proxy场景:clone GitHub 慢/超时,但内网 GitLab 不走代理:
# GitHub 走代理,内网 GitLab 直连
git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global https.https://github.com.proxy http://127.0.0.1:7890
# 不设全局 http.proxy → 其他仓库直连3.2 Docker
Docker Desktop 有自己的代理设置,不走系统代理也不走环境变量。
Docker Desktop GUI:
Settings → Resources → Proxies
┌───────────────────────────────────────┐
│ Manual proxy configuration [✓] │
│ │
│ HTTP proxy: http://127.0.0.1:7890 │
│ HTTPS proxy: http://127.0.0.1:7890 │
│ No proxy: localhost,127.0.0.1 │
│ │
│ [Apply & Restart] │
└───────────────────────────────────────┘Docker daemon 配置文件(~/.docker/config.json):
{
"proxies": {
"default": {
"httpProxy": "http://127.0.0.1:7890",
"httpsProxy": "http://127.0.0.1:7890",
"noProxy": "localhost,127.0.0.1,10.0.0.0/8"
}
}
}容器内构建镜像时(docker build 需要下载包):
# Dockerfile 里也可以传,但建议用 --build-arg
ARG HTTP_PROXY
ARG HTTPS_PROXY
RUN apt update # 会自动使用上面的代理变量# 构建时传代理
docker build --build-arg HTTP_PROXY=http://host.docker.internal:7890 \
--build-arg HTTPS_PROXY=http://host.docker.internal:7890 \
-t myapp .注意:容器内访问宿主机代理要用 host.docker.internal,不是 127.0.0.1(容器的 127.0.0.1 是容器自己)。
3.3 npm / yarn / pnpm
# npm
npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890
# 或者用环境变量(推荐,pnpm/yarn 也生效)
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
# pnpm
pnpm config set proxy http://127.0.0.1:7890
pnpm config set https-proxy http://127.0.0.1:7890
# 取消
npm config delete proxy
npm config delete https-proxy
# 验证
npm config get proxy更好的方案:直接设 npm 镜像源,不走代理:
npm config set registry https://registry.npmmirror.com/3.4 pip / uv
# 临时
pip install --proxy http://127.0.0.1:7890 requests
# 永久写入配置
mkdir -p ~/.pip
cat > ~/.pip/pip.conf << 'EOF'
[global]
proxy = http://127.0.0.1:7890
trusted-host = pypi.org
pypi.python.org
files.pythonhosted.org
EOF
# 或用环境变量
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
pip install requests
# uv(继承环境变量,不需要单独配)
export HTTP_PROXY=http://127.0.0.1:7890
uv pip install requests
# 取消
unset HTTP_PROXY HTTPS_PROXY
# 或删 pip.conf 里的 proxy 行更好的方案:用国内镜像源不走代理:
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/3.5 curl / wget
# curl 读环境变量,也可以命令行指定
curl -x http://127.0.0.1:7890 https://httpbin.org/ip
# 或用环境变量
export https_proxy=http://127.0.0.1:7890
curl https://httpbin.org/ip
# SOCKS5
curl -x socks5://127.0.0.1:7891 https://httpbin.org/ip
# curl 的小写环境变量优先级更高
# http_proxy(小写) > HTTP_PROXY(大写)
# 同时设了两个时 curl 用小写的
# wget
wget -e use_proxy=yes -e http_proxy=http://127.0.0.1:7890 \
-e https_proxy=http://127.0.0.1:7890 \
https://example.com/file.zip
# 或写配置 ~/.wgetrc
# use_proxy = on
# http_proxy = http://127.0.0.1:7890
# https_proxy = http://127.0.0.1:78903.6 PowerShell(Invoke-WebRequest)
# PowerShell 的 Invoke-WebRequest 不读 HTTP_PROXY 环境变量!
# 需要用 -Proxy 参数
# 临时
Invoke-WebRequest -Proxy http://127.0.0.1:7890 -Uri https://httpbin.org/ip
# 或设置 PSDefaultParameterValues 全局生效
$PSDefaultParameterValues['Invoke-WebRequest:Proxy'] = 'http://127.0.0.1:7890'
$PSDefaultParameterValues['Invoke-RestMethod:Proxy'] = 'http://127.0.0.1:7890'
# 写入 PowerShell Profile 永久生效
# 编辑 $PROFILE
notepad $PROFILE
# 加入上面两行3.7 WSL
WSL2 有独立网络,系统代理对 WSL 无效。
# NAT 模式(默认):获取宿主 IP 作为代理地址
# WSL 内执行:
WIN_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
export http_proxy="http://${WIN_IP}:7890"
export https_proxy="http://${WIN_IP}:7890"
export no_proxy="localhost,127.0.0.1"
# 写入 ~/.bashrc
cat >> ~/.bashrc << 'EOF'
export WIN_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
export http_proxy="http://${WIN_IP}:7890"
export https_proxy="http://${WIN_IP}:7890"
export no_proxy="localhost,127.0.0.1"
EOF
# Mirrored 模式(Win11):直接用 127.0.0.1
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"代理客户端需要开局域网共享:
Clash Verge → 设置 → 允许局域网连接 [开]
v2rayN → 参数设置 → 允许来自局域网的连接 [勾]3.8 IDE(IntelliJ / VS Code / Android Studio)
IntelliJ 系列:
File → Settings → Appearance & Behavior → System Settings → HTTP Proxy
┌────────────────────────────────────────┐
│ Manual proxy configuration │
│ Host name: 127.0.0.1 │
│ Port number: 7890 │
│ No proxy for: localhost,127.0.0.1 │
│ │
│ [Check connection] → 测试连接 │
└────────────────────────────────────────┘VS Code:
VS Code 本身的网络请求(扩展市场、更新)走系统代理。但 VS Code 里的终端不继承系统代理:
// settings.json
{
"http.proxy": "http://127.0.0.1:7890",
"http.proxyStrictSSL": false,
"http.proxySupport": "on"
}终端里需要单独设环境变量(见 2.3 节)。
五、代理客户端的两种模式
4.1 系统代理模式
大多数客户端(Clash Verge / v2rayN)默认提供「设置系统代理」按钮:
Clash Verge:
系统代理 [开/关]
端口: 7890 (Mixed)
开启后自动写入注册表 ProxyEnable=1效果:等价于手动在 Windows 设置里填了代理。只对走 WinINET 的程序有效,命令行工具不生效。
4.2 TUN 模式(全局代理)
TUN 模式创建一个虚拟网卡,接管所有网络流量:
flowchart TB
subgraph W["Windows 网络栈"]
direction TB
EDGE["Edge"]
CLI["curl"]
GIT["git"]
TUN["虚拟 TUN 网卡(Clash / v2rayN 管理)<br/>所有流量在这里被规则匹配:<br/>匹配代理规则 → 走代理出口<br/>匹配直连规则 → 走物理网卡"]
PHY["物理网卡(Wi-Fi)<br/>只处理直连流量"]
EDGE --> TUN
CLI --> TUN
GIT --> TUN
TUN --> PHY
end| 维度 | 系统代理模式 | TUN 模式 |
|---|---|---|
| 覆盖范围 | 浏览器 + 部分 GUI | 几乎所有程序 |
| 命令行工具 | ❌ 需要单独配环境变量 | ✅ 自动生效 |
| SSH / RDP / ping | ❌ | ✅ |
| WSL 流量 | ❌ | ✅(Win11 mirrored) |
| Docker 流量 | ❌ | ✅ |
| 游戏流量 | ❌ | ✅ |
| 性能 | 高(用户态转发) | 略低(虚拟网卡 + 内核转发) |
| 权限 | 不需要管理员 | 需要管理员(安装虚拟网卡) |
| 兼容性 | 好 | 可能和 VPN/虚拟机冲突 |
4.3 各客户端 TUN 开启方式
Clash Verge Rev:
设置 → 代理链
TUN 模式 [开]
栈: gVisor(兼容性好)/ System(性能好)
设备名: Meta
自动路由 [开]
自动检测接口 [开]v2rayN:
参数设置 → Core: TUN
或 v2rayN → TUN 模式设置 → 开启sing-box:
{
"inbounds": [
{
"type": "tun",
"tag": "tun-in",
"address": ["172.19.0.1/30"],
"auto_route": true,
"strict_route": true,
"stack": "system"
}
]
}4.4 什么时候用 TUN,什么时候用系统代理
| 场景 | 推荐模式 | 原因 |
|---|---|---|
| 只需要浏览器翻墙 | 系统代理 | 够用,开销最小 |
| 需要命令行工具走代理 | TUN 或 环境变量 | 系统代理不覆盖 |
| 需要全局所有程序走代理 | TUN | 最省心 |
| 玩外服游戏 | TUN | 游戏不走系统代理 |
| 跑 Docker/WSL 需要走代理 | TUN | 容器网络不走系统代理 |
| 担心兼容性 / 不想装虚拟网卡 | 系统代理 + 环境变量 | 传统方案最稳 |
| 需要精细分应用控制 | 系统代理 + PAC | TUN 是全局的 |
六、分应用代理(只让特定程序走代理)
5.1 Clash 规则模式
Clash 的规则可以在系统代理或 TUN 模式下做精细化分流:
# Clash 规则示例
rules:
# 特定域名走代理
- DOMAIN-SUFFIX,google.com,代理节点
- DOMAIN-SUFFIX,github.com,代理节点
- DOMAIN-SUFFIX,openai.com,代理节点
# 国内域名直连
- DOMAIN-SUFFIX,cn,DIRECT
- DOMAIN-SUFFIX,baidu.com,DIRECT
- DOMAIN-SUFFIX,taobao.com,DIRECT
# IP 段判断
- GEOIP,CN,DIRECT
- IP-CIDR,10.0.0.0/8,DIRECT
- IP-CIDR,192.168.0.0/16,DIRECT
# 兜底
- MATCH,代理节点5.2 Clash 进程匹配(TUN 模式下)
TUN 模式下可以按进程名匹配规则:
rules:
# 只有 Chrome 走代理节点
- PROCESS-NAME,chrome.exe,代理节点
# Docker Desktop 不走代理
- PROCESS-NAME,Docker Desktop.exe,DIRECT
# Steam 走代理(外服游戏)
- PROCESS-NAME,steam.exe,代理节点
# 其他默认直连
- MATCH,DIRECT5.3 Proxychains 替代方案(Windows 上)
Windows 上没有原生 proxychains,但可以用以下方式实现类似效果:
方法 A:用 proxychains-windows(第三方移植):
# 下载 proxychains-windows
# https://github.com/shunf4/proxychains-windows
# 配置 %USERPROFILE%\proxychains\proxychains.conf
[ProxyList]
socks5 127.0.0.1 7891
# 使用
proxychains curl https://httpbin.org/ip
proxychains git clone https://github.com/repo.git方法 B:开 TUN 模式 + 进程匹配规则(更推荐,不需要单独启动)
方法 C:命令行临时设环境变量 + 指定程序前加 env(Git Bash 里)
http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890 git clone https://github.com/repo.git七、特殊场景
6.1 Docker Desktop + 代理
Docker Desktop 4+ 在 Windows 上跑容器,容器要访问外网需要走宿主代理:
Docker Desktop Settings → Resources → Proxies
Manual proxy:
HTTP: http://host.docker.internal:7890
HTTPS: http://host.docker.internal:7890
No Proxy: localhost,127.0.0.1容器内访问宿主机用 host.docker.internal,不是 127.0.0.1。
如果用 WSL2 后端的 Docker Desktop + TUN 模式,容器流量自动走 TUN,不需要配 Docker 代理。
6.2 WSL2 + 代理
详见 3.7 节。核心要点:
| WSL 网络模式 | 代理地址 | 说明 |
|---|---|---|
| NAT(默认) | http://$(宿主IP):7890 | 宿主 IP 从 /etc/resolv.conf 取 |
| Mirrored | http://127.0.0.1:7890 | 和宿主共享网络栈 |
| TUN 开启 | 不需要配 | TUN 接管 WSL 流量 |
6.3 Windows Terminal + 代理
Windows Terminal 里的每个 profile(PowerShell/CMD/Git Bash)是独立进程,环境变量不互通:
// Windows Terminal settings.json
{
"profiles": {
"list": [
{
"name": "PowerShell (Proxy)",
"commandline": "powershell.exe -NoExit -Command \"$env:HTTP_PROXY='http://127.0.0.1:7890'; $env:HTTPS_PROXY='http://127.0.0.1:7890'\"",
"icon": ".Ribboned"
},
{
"name": "CMD (Proxy)",
"commandline": "cmd.exe /k \"set HTTP_PROXY=http://127.0.0.1:7890 && set HTTPS_PROXY=http://127.0.0.1:7890\"",
"icon": ".Ribboned"
}
]
}
}这样打开 Terminal 时选「PowerShell (Proxy)」profile 就自动带代理环境变量。
6.4 SSH 走代理
SSH 不读 HTTP_PROXY,需要用 ProxyCommand:
# ~/.ssh/config
# 通过 HTTP 代理 SSH
Host github.com
ProxyCommand connect -H 127.0.0.1:7890 %h %p
# 通过 SOCKS5 代理 SSH
Host github.com
ProxyCommand connect -S 127.0.0.1:7891 %h %p
# 或用 ncat(如果有 Nmap)
Host github.com
ProxyCommand ncat --proxy 127.0.0.1:7891 --proxy-type socks5 %h %pWindows 上需要装 connect 工具(Git for Windows 自带)或 ncat。
6.5 Windows Store 应用代理
UWP 应用(Windows Store 里的应用)有网络隔离,默认不能访问 127.0.0.1:
# 管理员 PowerShell
# 允许所有 UWP 应用访问本地回环
CheckNetIsolation LoopbackExempt -a -n="1"
# 或指定应用
CheckNetIsolation LoopbackExempt -a -n=<PackageFamilyName>
# 查看当前已豁免的应用
CheckNetIsolation LoopbackExempt -s
# 一键豁免所有 UWP(方便但不够安全)
Get-AppxPackage | ForEach-Object { CheckNetIsolation LoopbackExempt -a -n=$_.PackageFamilyName }八、排障:代理不生效的 12 步排查
排障流程图
flowchart TB
Q{"代理不生效?"}
Q -->|"是浏览器?"| B1["检查系统代理是否开启(第一节)"]
B1 --> B2{"开了但不行?"}
B2 -->|"例外列表把目标域名排除了"| B3["检查例外列表"]
B1 --> B4{"浏览器有自己的代理设置?"}
B4 -->|"Chrome 的 --proxy-server 覆盖"| B5["检查 Chrome 启动参数"]
Q -->|"是命令行 curl/git/npm?"| C1["设环境变量(第二节)"]
C1 --> C2{"设了还不行?"}
C2 -->|"变量值缺 http:// 前缀"| C3["检查变量值格式"]
C2 -->|"pip / Invoke-WebRequest 不读环境变量"| C4["改用命令行参数"]
Q -->|"是 Docker?"| D1["Docker Desktop Settings → Proxies(3.2 节)<br/>容器内用 host.docker.internal,不是 127.0.0.1"]
Q -->|"是 WSL?"| W1["WSL 里设环境变量(3.7 节)<br/>代理客户端开「允许局域网连接」"]
Q -->|"是 SSH / RDP / 游戏?"| T1["只有 TUN 模式才覆盖(第四节)"]
Q -->|"是 UWP 应用?"| U1["CheckNetIsolation LoopbackExempt(6.5 节)"]
Q -->|"以上都不是?"| TUN["开 TUN 模式一劳永逸"]逐项排查
# 1. 代理客户端在跑吗?
netstat -ano | findstr "7890"
# 有 LISTENING → 在跑
# 2. 代理端口能连通吗?
curl -x http://127.0.0.1:7890 https://httpbin.org/ip
# 有返回 → 代理本身没问题
# 3. 系统代理开了吗?
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable
# ProxyEnable=1 → 开了
# 4. 环境变量设了吗?
echo $env:HTTP_PROXY
echo $env:HTTPS_PROXY
# 有值 → 设了
# 5. 例外列表排除了目标吗?
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride
# 检查 ProxyOverride 里有没有目标域名
# 6. 程序有自己的代理设置?
# Chrome: chrome://settings → 搜索 proxy
# Firefox: about:preferences → 网络设置
# IDE: Settings → HTTP Proxy
# 7. DNS 解析对吗?
nslookup google.com
# 如果 DNS 走了代理的 fake-ip → 域名解析到假 IP → 需要开 DNS 代理
# 8. 是 HTTPS 证书问题?
curl -v https://目标地址 2>&1 | findstr "SSL\|certificate"
# SSL error → 代理做 TLS 拦截了 → 需要信任代理证书或关 TLS 拦截
# 9. 是 UWP 应用?
CheckNetIsolation LoopbackExempt -s
# 10. Docker Desktop 代理配了吗?
docker info 2>&1 | findstr "Proxy"
# 11. WSL 看得到宿主 IP 吗?
wsl -- cat /etc/resolv.conf
# nameserver 有 IP → 拿到了宿主地址
# 12. 开 TUN 模式试试
# 如果 TUN 开了还不行 → 检查虚拟网卡是否存在
ipconfig | findstr "Meta\|tun\|Wintun"九、TUN 模式常见冲突与解决
8.1 TUN + VPN 冲突
现象:开了 TUN 模式后 VPN 连不上 / VPN 连上后 TUN 不生效
原因:两个虚拟网卡抢路由表解决:
- 不要同时开:要么用 VPN 要么用 TUN
- 如果必须同时 → 在 TUN 规则里把 VPN 的目标 IP 设为 DIRECT
- 部分 VPN 客户端支持「通过代理连接」→ 先 TUN 再 VPN
8.2 TUN + VMware/VirtualBox 冲突
现象:开了 TUN 后虚拟机断网
原因:TUN 的 auto-route 覆盖了虚拟机的网段解决:
# Clash TUN 配置里排除虚拟机网段
tun:
enable: true
route-exclude-address:
- 192.168.56.0/24 # VirtualBox 默认
- 172.16.0.0/12 # VMware vmnet88.3 TUN + WSL 冲突
现象:开了 TUN 后 WSL 里访问不了外网
原因:WSL 的 NAT 网络和 TUN 路由冲突解决:
- 方法 A:在
.wslconfig里用 mirrored 模式 - 方法 B:在 TUN 规则里排除 WSL 的网段
- 方法 C:不开 TUN,用系统代理 + WSL 环境变量(3.7 节)
8.4 TUN 虚拟网卡消失
现象:TUN 模式开了但不生效,ipconfig 看不到虚拟网卡# 检查 Wintun 驱动(Clash/sing-box 用)
# Clash Verge 会自动安装 Wintun
# 手动安装
# 下载 wintun.dll 放到客户端目录
# https://www.wintun.net
# 或检查服务
Get-Service | Where-Object { $_.Name -like "*tun*" -or $_.Name -like "*wintun*" }
# 管理员重装
# Clash Verge → 设置 → 重装服务十、安全注意事项
9.1 不要在公共 WiFi 上开局域网共享
Clash → 允许局域网连接 [关]
v2rayN → 允许来自局域网的连接 [不勾]开了局域网共享 = 同一 WiFi 的人都能用你的代理。
9.2 代理客户端的 DNS 泄露
如果不配 DNS,浏览器会先用系统 DNS 解析域名,再走代理连接。这会导致:
- ISP 知道你访问了什么域名
- GFW 看到 DNS 查询可以阻断
解决:
# Clash 配置 DNS 走代理
dns:
enable: true
listen: :53
enhanced-mode: fake-ip # 或 redir-host
nameserver:
- https://223.5.5.5/dns-query # 国内 DNS
fallback:
- https://1.1.1.1/dns-query # 国外 DNS(走代理)
fallback-filter:
geoip: true
geoip-code: CN9.3 环境变量泄露敏感信息
# HTTP_PROXY 里不要写用户名密码
# 错误:
export HTTP_PROXY=http://user:password@proxy.company.com:8080
# 正确:用 .netrc 或 credential store十一、常用命令速查
| 命令 | 作用 | 示例 |
|---|---|---|
netsh winhttp show proxy | 查看 winhttp 代理 | — |
netsh winhttp set proxy IP:PORT | 设置 winhttp 代理 | netsh winhttp set proxy 127.0.0.1:7890 |
netsh winhttp reset proxy | 清除 winhttp 代理 | — |
reg query ...ProxyEnable | 查看系统代理开关 | 见 1.3 |
setx HTTP_PROXY "..." | 永久设环境变量 | setx HTTP_PROXY "http://127.0.0.1:7890" |
$env:HTTP_PROXY = "..." | 临时设(PS) | — |
curl -x 代理 URL | curl 走代理 | curl -x http://127.0.0.1:7890 URL |
git config --global http.proxy | Git 走代理 | 见 3.1 |
npm config set proxy | npm 走代理 | 见 3.3 |
pip install --proxy URL | pip 走代理 | pip install --proxy http://127.0.0.1:7890 pkg |
CheckNetIsolation LoopbackExempt | UWP 回环豁免 | 见 6.5 |
docker info | findstr Proxy | 查看 Docker 代理 | — |
十二、推荐配置方案
方案 A:日常使用(推荐大多数人)
Clash Verge Rev
├─ 系统代理 [开]
├─ TUN 模式 [关]
├─ 规则模式 [Rule]
└─ 端口 7890 (Mixed)
CMD/PowerShell:
setx HTTP_PROXY "http://127.0.0.1:7890"
setx HTTPS_PROXY "http://127.0.0.1:7890"
setx NO_PROXY "localhost,127.0.0.1,10.*,172.*,192.168.*"
Git:
git config --global http.proxy http://127.0.0.1:7890
Docker:
Docker Desktop → Proxies → 127.0.0.1:7890方案 B:全全局(不想折腾分应用配置)
Clash Verge Rev
├─ TUN 模式 [开]
├─ 自动路由 [开]
├─ 规则模式 [Rule]
└─ DNS [fake-ip]
不需要设环境变量
不需要设 Docker 代理
不需要设 Git 代理
TUN 接管一切方案 C:最小化(只浏览器翻墙)
代理客户端
└─ 系统代理 [开]
不需要环境变量
不需要 TUN