WireGuard hot reload config

Problem

I have a server that I can only connect to using wireguard and I needed to change an Endpoint IP. Stopping wg first would therefore not be an option.

Solution

  • Open the wireguard config using whichever editor you like:
  1 [Interface]
  2 Address = 10.1.0.12/24
  3 SaveConfig = true
  4 ListenPort = 123521
  5 PrivateKey = sssdeefaau793K2sdsdsSVZpEQb+W2qVLibyRZDoXu2A=
  6 
  7 [Peer]
  8 PublicKey = sxcpX8ZdTP2L3y3fGsNLzXrf45dx8fJxxsef1qCn6Bum3Y=
  9 AllowedIPs = 10.1.0.2/32
 10 Endpoint = 10.21.7.30:538
  • Make the change and then save an exit:
 "wg0.conf" 28L, 692C written
  • Then run the following wg-quick command:
server1:/etc/wireguard# wg syncconf wg0 <(wg-quick strip wg0)

References

Wireguard Client Addition without restart

wg-quick and hot reload/sync

wg-quick – set up a WireGuard interface simply