個人用の 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 を使ってください。
- Web UI がいい? ワンコマンドの wg-easy の道 が QR コードの管理パネル付きでこれを構築します。
Nano-IP(月 $8)で十分、無制限トラフィック、約1分で root、KYC なし、暗号資産で支払い。
コメント
まだコメントはありません。最初になりましょう。