wg-go 使用说明

项目地址: https://github.com/marlin2024/wg-go

介绍

wg-go 提供了一套工具,可以在 非 root 用户 下运行 WireGuard,并且支持通过 Cloudflare Warp 落地到指定国家或地区。 它的核心思路是把 WireGuard 封装成 SOCKS5 代理,避免直接使用 tun,这样既安全又方便,也非常适合容器环境。

特性

  • 非 root 用户即可运行 WireGuard
  • 提供 SOCKS5 代理接口
  • 支持 Warp 与其他代理叠加
  • 容器环境友好
  • 可以搭建 wg-over-wg 这样的实验场景

使用方法

1. socks-wg

直接将 WireGuard 转换成本地 SOCKS5 代理。

go run ./socks_over_wg \
  -config socks_over_wg/wg.conf \
  -listen 127.0.0.1:9999

效果对比:

# 直连(本机 IP)
curl https://ipinfo.io/json  

# 通过 socks-wg 代理(Warp IP)
curl -x socks5://127.0.0.1:9999 https://ipinfo.io/json

2. socks-wg-upstream_socks

socks-wg 的基础上,可以指定上游 SOCKS 代理。

go run ./socks_over_wg \
  -config=wg.conf \
  -listen 127.0.0.1:9999 \
  -wg-socks 127.0.0.1:8765

这样一来,:8765 是上游 VPN 的出口,:9999 是 Warp 出口,可以做到“套娃代理”。


3. wg-over-wg

支持双层 WireGuard(外层 VPN + 内层 Warp)。

go run wg_over_wg/main.go \
  --outer-config=configs/proton_jp.conf \
  --inner-config=configs/wg.conf \
  --socks-inner=0.0.0.0:2080 \
  --socks-outer=0.0.0.0:1080
  • :1080 → 外层 VPN (例如 ProtonVPN JP)
  • :2080 → 内层 Warp

4. OpenVPN + SOCKS5

如果想用 OpenVPN,但又不想影响宿主机的 tun,可以在 Docker 里运行:

docker run -it --cap-add=NET_ADMIN --device=/dev/net/tun \
  --dns 1.1.1.1 --dns 8.8.8.8 -p 8765:8765  \
  -v "$PWD":/work -w /work ubuntu bash

进入容器后:

  1. 启动 OpenVPN

    openvpn --config /work/client.ovpn
    
    • client.ovpn 中指定账号:

      auth-user-pass /work/credentials
      
    • credentials 文件内容:

      username
      password
      
    • 对旧版本 OpenVPN,可能需要添加:

      data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-128-CBC
      data-ciphers-fallback AES-128-CBC
      
  2. 启动 socks5 代理(推荐 gost):

    gost -L socks5://:8765
    

这样就可以通过 127.0.0.1:8765 来访问 OpenVPN 的出口。


使用场景

  • 需要 Warp 落地到指定国家
  • 测试 VPN over VPN 的链路
  • 容器环境下使用 VPN,而不影响宿主机
  • 本地调试代理出口 IP

总结

wg-go 提供了一种更灵活的方式来使用 WireGuard 和 Warp,绕开了必须 root 才能使用 tun 的限制,同时又能组合 OpenVPN、Warp、双层 wg 等多种场景。

项目地址: https://github.com/marlin2024/wg-go