WireGuard command snippets
Copy-paste-ready wg and wg-quick commands for managing WireGuard VPN tunnels.
WireGuard command snippets
Copy-paste-ready wg and wg-quick commands for managing WireGuard VPN tunnels.
Generate a WireGuard Key Pair
wg generates a private key and derives the public key:
wg genkey | tee private.key | wg pubkey > public.keyGenerate a Pre-Shared Key for WireGuard
wg generates a random pre-shared key for additional encryption:
wg genpsk > preshared.keyStart a WireGuard Tunnel
wg-quick brings up the interface defined in the config file:
sudo wg-quick up wg0Stop a WireGuard Tunnel
wg-quick brings down the interface and removes routes:
sudo wg-quick down wg0Enable WireGuard at Boot with systemd
systemctl enables the wg-quick service for automatic startup:
sudo systemctl enable wg-quick@wg0Show WireGuard Tunnel Status
wg displays active interfaces, peers, handshake times, and data transfer:
sudo wg showShow WireGuard Tunnel Status in JSON Format
wg outputs the status as JSON for scripting:
sudo wg show all dumpAdd a Peer to a Running WireGuard Interface
wg adds a peer without restarting the tunnel:
sudo wg set wg0 peer <PUBLIC_KEY> allowed-ips 10.0.0.3/32