大网数据广告活动
服务器运维问答

Wireguard Client Addition without restart

· 52CE 我爱测

I am building a Wireguard VPN network, in which I want to add and remove peers on the server without restarting the service or losing connections with existing peers. Tried searching for the results, but I found nothing that can …

问题原文

原帖链接 · Anton2319 · CC BY-SA 4.0

I am building a Wireguard VPN network, in which I want to add and remove peers on the server without restarting the service or losing connections with existing peers. Tried searching for the results, but I found nothing that can suit my needs (all the solutions will cause a few second freeze or will require clients to redo handshake with server). Is it possible to implement this with Wireguard and if yes, how?

已采纳解答

原帖链接 · Ben Harper · CC BY-SA 4.0

I'm working on a similar project, and my conclusion is that you're better off keeping all configuration inside your own database, and completely skipping wireguard config files for the peer setup. You might still want to use the wireguard config file for the [Interface] section, which my example below uses. But you could do that programmatically too, should you need to.

So, assuming we have an interface called wg0, defined in /etc/wireguard/wg0.conf

[Interface]
ListenPort = 51820
Address = 10.100.1.1
PrivateKey = <your private key>

In the above config, there are zero peers.

Add a new peer:

wg set wg0 peer "K30I8eIxuBL3OA43Xl34x0Tc60wqyDBx4msVm8VLkAE=" allowed-ips 10.101.1.2/32
ip -4 route add 10.101.1.2/32 dev wg0

Remove a peer:

wg set wg0 peer "K30I8eIxuBL3OA43Xl34x0Tc60wqyDBx4msVm8VLkAE=" remove
ip -4 route delete 10.101.1.2/32 dev wg0

As far as I know, this will not cause downtime for other peers.

The technique I used to figure out the ip -4 route ... commands to run, is simply by using wg-quick up wg0 and taking note of the commands that it spits out.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-05-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。