将 WireGuard 隧道与 Clash 代理结合,实现更灵活的组网方案。
- 家庭组网: 多设备通过 WireGuard 连接到 VPS,再通过 Clash 出海
- 企业内网: 分支机构通过 WireGuard 加入统一内网
- 移动端优化: WireGuard 建立隧道,Clash 处理分流
手机/电脑 > --WireGuard隧道-- > VPS > --Clash-- > 互联网
^ |
+ --------- VPN 内网 ---------+
VPS 配置 WireGuard 接收连接,Clash 处理出站:
# VPS 安装 WireGuard
apt install wireguard -y
# VPS wg0.conf
[Interface]
PrivateKey = <vps-private-key>
Address = 10.0.0.1/24
ListenPort = 51820
[Peer]
PublicKey = <client-public-key>
AllowedIPs = 10.0.0.2/32
# 开启 IP 转发
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -i wg0 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE只有特定流量走代理,其他走 WireGuard 直连:
rules:
# WireGuard 内网直连
- IP-CIDR,10.0.0.0/24,DIRECT
# 国内直连
- GEOIP,CN,DIRECT
# 其他走代理
- MATCH,ProxyWireGuard 连不上? 检查服务端防火墙是否放行 UDP 51820 端口。
和 Clash TUN 冲突? Clash TUN 接管所有流量,建议分开使用或禁用其中一个的 TUN。
推荐工具: