个人 WireGuard VPN 意味着服务器、密钥和日志全归你。这是手动配置指南;关于相较商业 VPN 的取舍、一条命令的 wg-easy 路径以及 DPI 注意事项,请看 自托管 WireGuard 和 面向 VPN 的 VPS 用例。你需要一个 专用 IP 套餐——WireGuard 监听一个入站 UDP 端口。
1. 安装 WireGuard 并生成服务端密钥
apt update && apt install -y wireguard
wg genkey | tee /etc/wireguard/server.key | wg pubkey > /etc/wireguard/server.pub
chmod 600 /etc/wireguard/server.key
2. 编写服务端配置
# /etc/wireguard/wg0.conf
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <contents of /etc/wireguard/server.key>
PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer] # your phone/laptop
PublicKey = <client public key — see step 4>
AllowedIPs = 10.8.0.2/32
3. 启用转发并启动
sysctl -w net.ipv4.ip_forward=1
echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
ufw allow 51820/udp
systemctl enable --now wg-quick@wg0
wg show
4. 生成客户端密钥并连接
在客户端上(或在服务器上生成再移过去):
wg genkey | tee client.key | wg pubkey > client.pub
把 client.pub 放进上面的 [Peer] 块(然后 systemctl restart wg-quick@wg0),并把这份配置给客户端:
[Interface]
PrivateKey = <client.key>
Address = 10.8.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = <server.pub>
Endpoint = YOUR.SERVER.IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
把它导入 WireGuard 应用(在手机上用 qrencode -t ansiutf8 < client.conf 生成二维码最快),打开开关——你就在通过自己的服务器路由了。
备注
- 在 DPI 之后(伊朗/中国/俄罗斯)? WireGuard 会被指纹识别并封锁——请改用 VLESS + Reality。
- 偏爱网页界面? 一条命令的 wg-easy 路径 会带一个二维码管理面板把这些搭好。
Nano-IP(每月 $8)绰绰有余,流量不计量,大约一分钟拿到 root,无 KYC,用加密货币付款。
评论
暂无评论。来做第一个吧。