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.key

Generate a Pre-Shared Key for WireGuard

wg generates a random pre-shared key for additional encryption:

wg genpsk > preshared.key

Start a WireGuard Tunnel

wg-quick brings up the interface defined in the config file:

sudo wg-quick up wg0

Stop a WireGuard Tunnel

wg-quick brings down the interface and removes routes:

sudo wg-quick down wg0

Enable WireGuard at Boot with systemd

systemctl enables the wg-quick service for automatic startup:

sudo systemctl enable wg-quick@wg0

Show WireGuard Tunnel Status

wg displays active interfaces, peers, handshake times, and data transfer:

sudo wg show

Show WireGuard Tunnel Status in JSON Format

wg outputs the status as JSON for scripting:

sudo wg show all dump

Add 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