zh
自建VPN服务器:WireGuard境外VPS完整配置教程
商业VPN服务有两个致命弱点:被GFW批量封锁的IP和无法验证的无日志承诺。自建VPN服务器彻底解决这两个问题——你的IP是私有的,从未被标记;你完全控制服务器,日志策略由你决定。本教程使用WireGuard协议,在AnubizHost境外VPS上15分钟完成搭建。
Need this done for your project?
We implement, you ship. Async, documented, done in days.
自建VPN vs 商业VPN对比
商业VPN的问题:
- 数千万用户共享相同的IP段,GFW只需封锁这些IP段就能批量封锁所有用户
- 无法独立验证「无日志」承诺——多个商业VPN曾因执法要求提交用户日志
- 月费积累成本高($10-15/月 × 12 = $120-180/年)
- 部分国家(中国、俄罗斯、伊朗)强制要求VPN服务商配合执法
自建VPN的优势:
- 专属IP——从未被任何VPN服务使用过,不在GFW封锁名单
- 完全控制——可以验证无日志(或亲自配置禁用日志)
- AnubizHost VPS每月$22.99,比大多数商业VPN便宜,同时获得完整服务器用途
- 可以同时运行VPN + 网站 + 其他服务
PiVPN一键安装WireGuard(推荐)
PiVPN是最简单的WireGuard/OpenVPN安装脚本,交互式引导配置:
curl -L https://install.pivpn.io | bash安装向导选项:
- 选择WireGuard(非OpenVPN)
- 端口:默认51820,或改为443(更难被封锁)
- DNS:选择Cloudflare (1.1.1.1) 或 Google (8.8.8.8)
- 公网IP:输入VPS的IP地址
安装完成后,生成客户端配置:
pivpn add -n phone
pivpn add -n laptop
pivpn add -n desktop每个命令生成一个独立的客户端配置文件。运行 pivpn -qr phone 显示手机扫描的二维码。
手动安装WireGuard(高级用户)
服务端安装:
apt update && apt install wireguard -y
cd /etc/wireguard && umask 077
wg genkey | tee server_private.key | wg pubkey > server_public.key服务端配置 /etc/wireguard/wg0.conf:
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = (服务端私钥)
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
PublicKey = (客户端公钥)
AllowedIPs = 10.8.0.2/32客户端配置:
[Interface]
PrivateKey = (客户端私钥)
Address = 10.8.0.2/24
DNS = 1.1.1.1
[Peer]
PublicKey = (服务端公钥)
Endpoint = VPS-IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25客户端安装
WireGuard官方提供全平台客户端,均免费开源:
- Android:Google Play搜索WireGuard,官方应用,导入配置文件或扫描二维码
- iOS:App Store搜索WireGuard,官方应用,同上
- Windows:wireguard.com下载安装程序,导入.conf文件
- macOS:App Store下载WireGuard或Homebrew安装
- Linux:包管理器安装(apt install wireguard),wg-quick up wg0启动
连接成功后,访问 ifconfig.me 验证出口IP是否为你的VPS IP,而非本地IP。
提升在中国的可用性
标准WireGuard(UDP 51820端口)在中国会被GFW的UDP封锁机制识别。以下是提升可用性的方案:
- 方案一:改用443端口(UDP) - 许多防火墙不封锁UDP 443,但GFW对UDP 443的检测在加强
- 方案二:WireGuard over TCP - 使用udp2raw或wstunnel将UDP包裹在TCP中传输,避免UDP QoS问题
- 方案三:WireGuard over WebSocket+TLS - 配置wstunnel,使WireGuard看起来像HTTPS流量
- 方案四:放弃WireGuard,改用VLESS+Reality - 对GFW抗性最强,推荐在WireGuard不稳定时使用
AnubizHost的VPS提供完整root权限,支持以上所有方案的部署。
Related Services
Why Anubiz Host
100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.