WireGuard VPN 配置

WireGuard 密钥生成与三方架构配置说明


# WireGuard 密钥生成与三方结构配置笔记

## 📌 1. 密钥生成

使用 `wg` 工具生成 Curve25519 公钥和私钥对。

### ✅ 单独生成

```bash
wg genkey > privatekey
cat privatekey | wg pubkey > publickey

✅ 一次性生成(推荐)

umask 077
wg genkey | tee privatekey | wg pubkey > publickey

🔐 可选:生成预共享密钥(Preshared Key)

wg genpsk > presharedkey

🌐 2. 三方结构架构说明

本机 ↔ 中转服务器(公网) ↔ 远程设备(内网)

[Client A]      [Relay Server]      [Client B]
10.45.200.6  ⇆  10.45.0.1(pubIP)  ⇆  10.45.200.10

⚙️ 3. 示例配置

🖥️ 本机 A 配置

[Interface]
Address = 10.45.200.6/32
PrivateKey = <A私钥>

[Peer]
PublicKey = <服务器公钥>
Endpoint = <服务器公网IP>:61002
AllowedIPs = 10.45.0.0/16
PersistentKeepalive = 16

🌍 中转服务器配置

[Interface]
Address = 10.45.0.1/16
PrivateKey = <服务器私钥>
ListenPort = 61002

[Peer] # Client A
PublicKey = <A公钥>
AllowedIPs = 10.45.200.6/32

[Peer] # Client B
PublicKey = <B公钥>
AllowedIPs = 10.45.200.10/32

📡 远程设备 B 配置

[Interface]
Address = 10.45.200.10/32
PrivateKey = <B私钥>

[Peer]
PublicKey = <服务器公钥>
Endpoint = <服务器公网IP>:61002
AllowedIPs = 10.45.0.0/16
PersistentKeepalive = 16

✅ 启动服务

sudo wg-quick up wg0
sudo wg show

🛡️ 安全建议