WireGuard
项目状态: ✅ 活跃 | 推荐度: ⭐⭐⭐⭐⭐(海外)⭐⭐(中国+混淆)| 世代: 第四代
快速概览
WireGuard 是下一代 VPN 协议,以极简的代码(约4000行)、卓越的性能和现代密码学设计而闻名。它已被整合进 Linux 内核,是现代 VPN 的首选方案。
核心特性
- 🚀 极致性能: 比 OpenVPN 快 3-5 倍
- 📝 代码极简: ~4000 行代码 vs OpenVPN 的 ~70,000 行
- 🔒 现代密码学: ChaCha20, Curve25519, BLAKE2s
- ⚡ 快速握手: 1-RTT 连接建立
- 🎯 简单配置: 配置文件清晰直观
关键数据
| 指标 | WireGuard | OpenVPN |
|---|---|---|
| 吞吐量 | ~1000 Mbps | ~300 Mbps |
| 延迟 | ~0.5 ms | ~2 ms |
| CPU 占用 | 低 | 高 |
| 代码行数 | 4K | 70K |
在中国的使用
现状
- ❌ 直接使用: UDP 流量特征明显,易被识别
- ⚠️ 配合混淆: 可用,但需要额外工具
混淆方案
1. udp2raw (推荐)
将 UDP 转换为 TCP:
bash
# 服务端
udp2raw -s -l0.0.0.0:4096 -r127.0.0.1:51820 -k password --raw-mode faketcp
# 客户端
udp2raw -c -r服务器IP:4096 -l127.0.0.1:51820 -k password --raw-mode faketcp2. wstunnel
通过 WebSocket 传输:
bash
# 服务端
wstunnel -s 0.0.0.0:443 -t 127.0.0.1:51820
# 客户端
wstunnel -c ws://服务器:443 -t 127.0.0.1:51820基本配置
服务端
ini
[Interface]
PrivateKey = <SERVER_PRIVATE_KEY>
Address = 10.0.0.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
[Peer]
PublicKey = <CLIENT_PUBLIC_KEY>
AllowedIPs = 10.0.0.2/32客户端
ini
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 10.0.0.2/24
DNS = 1.1.1.1
[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
Endpoint = SERVER_IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25密钥生成
bash
# 生成私钥
wg genkey > privatekey
# 从私钥生成公钥
wg pubkey < privatekey > publickey性能优化
系统参数
bash
# /etc/sysctl.conf
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.ip_forward = 1MTU 设置
ini
[Interface]
MTU = 1420 # 推荐值,避免分片与其他VPN对比
| 特性 | WireGuard | OpenVPN | IPSec |
|---|---|---|---|
| 性能 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ |
| 安全性 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| 易用性 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ |
| 代码复杂度 | 极简 | 复杂 | 极复杂 |
| 中国可用性 | ⭐⭐(需混淆) | ❌ | ❌ |
使用建议
推荐场景
- ✅ 海外 VPN 使用(首选)
- ✅ 点对点加密
- ✅ 家庭网络/路由器
- ⚠️ 中国翻墙(需配合混淆)
不推荐场景
- ❌ 中国大陆直接使用
- ❌ 需要 TCP 的严格环境
客户端
- Windows: WireGuard for Windows
- macOS: WireGuard for macOS
- Linux: 内核内置
- Android: WireGuard for Android
- iOS: WireGuard for iOS
- OpenWrt: luci-app-wireguard
参考资源
- 官网: https://www.wireguard.com/
- 快速开始: https://www.wireguard.com/quickstart/
- GitHub: https://github.com/WireGuard
总结: WireGuard 是现代 VPN 的最佳选择,性能和安全性都是顶级。在中国使用需要配合混淆工具,或者考虑使用专为翻墙设计的工具(Xray, Trojan等)。