WireGuard 没有“账号密码”,
它是 每个用户一对密钥 = 一个用户。
🧩 一、新增一个用户(客户端)
假设:
-
服务器内网是
10.0.0.1/24 -
现有客户端是
10.0.0.2 -
我们要新增一个
10.0.0.3
✅ 第一步:生成客户端密钥(在服务器或客户端都行)
wg genkey | tee client2_private.key | wg pubkey > client2_public.key
得到:
-
client2_private.key
-
client2_public.key
✅ 第二步:把客户端公钥加到服务器
编辑服务器:
vim /etc/wireguard/wg0.conf
添加:
[Peer]
PublicKey = 这里填 client2_public.key 内容
AllowedIPs = 10.0.0.3/32
⚠️ 注意:
-
每个用户 IP 不能重复
-
必须
/32 -
不要写成
/24
✅ 第三步:重载配置(不用断线方式)
推荐用:
wg syncconf wg0 <(wg-quick strip wg0)
或者简单点:
systemctl restart wg-quick@wg0
🧩 四、给用户的客户端配置文件
给对方一个配置文件:
[Interface]
PrivateKey = client2_private.key 内容
Address = 10.0.0.3/24
DNS = 8.8.8.8
[Peer]
PublicKey = 服务器公钥
Endpoint = 服务器IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
对方导入客户端即可。
🧠 关键原则(非常重要)
| 项目 | 必须唯一 |
|---|---|
| PrivateKey | 每人一套 |
| PublicKey | 每人一套 |
| 内网IP | 每人一个 |
| AllowedIPs | 必须精确 /32 |
🔥 多用户结构示例
服务器 wg0.conf 最终会变成:
[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = 服务器私钥
[Peer]
PublicKey = 客户端1公钥
AllowedIPs = 10.0.0.2/32
[Peer]
PublicKey = 客户端2公钥
AllowedIPs = 10.0.0.3/32
[Peer]
PublicKey = 客户端3公钥
AllowedIPs = 10.0.0.4/32
就是这样一直加。
🚨 常见翻车点
❌ IP 重复
❌ 公钥复制错
❌ 忘了重启
❌ 客户端写错服务器公钥
❌ 客户端 Endpoint 写错端口
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
