问题原文
原帖链接 · 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
