個人 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 產生QR 碼最快),開啟開關——您就在透過自己的伺服器路由了。
備註
- 在 DPI 之後(伊朗/中國/俄羅斯)? WireGuard 會被指紋識別並封鎖——請改用 VLESS + Reality。
- 偏愛網頁介面? 一條指令的 wg-easy 路徑 會帶一個QR 碼管理面板把這些搭好。
Nano-IP(每月 $8)綽綽有餘,流量不計量,大約一分鐘拿到 root,無 KYC,用加密貨幣付款。
評論
目前還沒有評論。歡迎成為第一位。