WireGuard
Keys, server and client configs, bringing tunnels up and down, peers and troubleshooting.
Keys
Generate a key pair
umask 077 && wg genkey | tee private.key | wg pubkey > public.keyOptional pre-shared keyadvanced
wg genpsk > preshared.keyConfigs
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/32Client 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 --systemRunning
Bring the tunnel up / down
sudo wg-quick up wg0Start on boot
sudo systemctl enable --now wg-quick@wg0Peers, last handshake and traffic
sudo wg showNo 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