在自有 VPS 上搭建个人 WireGuard VPN - 5 分钟完成

在 VPS 上搭建你自己的 WireGuard VPN 服务器。真实命令,适用于 Ubuntu 22.04/24.04。你的流量,你的规则。12 €/月起。

您的服务器,您的流量,没有第三方 VPN 公司记录任何内容。适用于任何 Ubuntu VPS。

1. 服务器

在 /vps 选一个套餐:Core VPS 4(12 欧元)带独立 IP,正适合搭建 VPN。

2. 安装

ssh root@YOUR_SERVER_IP
apt update && apt install -y wireguard qrencode

3. 密钥与配置

wg genkey | tee /etc/wireguard/server.key | wg pubkey > /etc/wireguard/server.pub
cat > /etc/wireguard/wg0.conf <<'EOF'
[Interface]
Address = 10.66.66.1/24
ListenPort = 51820
PrivateKey = (insert server.key contents)
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
EOF
# client
wg genkey | tee client.key | wg pubkey > client.pub
cat > client.conf <<'EOF'
[Interface]
PrivateKey = (client.key)
Address = 10.66.66.2/24
DNS = 1.1.1.1
[Peer]
PublicKey = (server.pub)
Endpoint = YOUR_SERVER_IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
EOF
qrencode -t ansiutf8 < client.conf   # QR in terminal - scan with phone

4. 启动并设为开机自启

systemctl enable --now wg-quick@wg0
sysctl -w net.ipv4.ip_forward=1
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf

用 WireGuard 应用扫描二维码,隧道即建立。完整套餐列表:/vps。

相关内容

查看套餐指南常见问题