$ command-helper

WireGuard

Keys, server and client configs, bringing tunnels up and down, peers and troubleshooting.

Requires Google sign-in

Keys

Generate a key pair
umask 077 && wg genkey | tee private.key | wg pubkey > public.key
Optional pre-shared keyadvanced
wg genpsk > preshared.key

Configs

Server config
# /etc/wireguard/wg0.conf
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <server private key>

[Peer]
PublicKey = <client public key>
AllowedIPs = 10.8.0.2/32
Client config
[Interface]
Address = 10.8.0.2/24
PrivateKey = <client private key>
DNS = 1.1.1.1

[Peer]
PublicKey = <server public key>
Endpoint = <host>:51820
AllowedIPs = 10.8.0.0/24
PersistentKeepalive = 25

AllowedIPs = 0.0.0.0/0 sends all traffic through the tunnel; a subnet sends only that subnet.

Let the server route client trafficadvanced
echo 'net.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/99-wireguard.conf && sudo sysctl --system

Running

Bring the tunnel up / down
sudo wg-quick up wg0
Start on boot
sudo systemctl enable --now wg-quick@wg0
Peers, last handshake and traffic
sudo wg show

No recent handshake = keys, endpoint or UDP port is wrong (check the firewall for 51820/udp).

Add a peer without restartingadvanced
sudo wg set wg0 peer <peer_public_key> allowed-ips 10.8.0.3/32
Apply config changes without dropping the tunneladvanced
sudo wg syncconf wg0 <(sudo wg-quick strip wg0)
QR code for the mobile app
qrencode -t ansiutf8 < client.conf