What it does
WireGuard builds encrypted tunnels with small configs: each peer has a key pair, an interface address and a list of peers (public key, endpoint, AllowedIPs). AllowedIPs is both the routing table and the access list. It uses UDP (often port 51820), modern crypto (Curve25519, ChaCha20) and has no certificates. Use it for admin access to a lab, site-to-site links and node-to-node encryption (k3s wireguard-native, Tailscale is built on it).
On RHEL, NetworkManager also manages WireGuard (nmcli connection import type wireguard file wg0.conf).
How to write it
wg [show|showconf|set|genkey|pubkey|genpsk] ...
wg-quick up|down|strip INTERFACEMain parts
Commands
genkey/pubkey- Make a private key / its public key.
genpsk- Pre-shared key (extra layer).
show[IF]- Peers, handshakes, traffic.
showconfIF- Print the running config.
setIFpeerKEYallowed-ips…- Change a peer live.
wg-quickupIF/downIF- Start / stop from /etc/wireguard/IF.conf.
wg-quickstripIF- Config without wg-quick parts.
Options 6
Most used
Config keys
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Make keys
2Server config
cat /etc/wireguard/wg0.conf [Interface] Address = 10.99.0.1/24 ListenPort = 51820 PrivateKey = <server private key> [Peer] PublicKey = <laptop public key> AllowedIPs = 10.99.0.2/323Laptop config
cat wg0.conf [Interface] Address = 10.99.0.2/24 PrivateKey = <laptop private key> [Peer] PublicKey = <server public key> Endpoint = vpn.example.com:51820 AllowedIPs = 10.99.0.0/24, 192.168.122.0/24 PersistentKeepalive = 254Open the port and start
firewall-cmd --permanent --add-port=51820/udp && firewall-cmd --reload systemctl enable --now wg-quick@wg05Check the tunnel
wg show ping -c2 10.99.0.26Route the lab network through the server
sysctl -w net.ipv4.ip_forward=1 firewall-cmd --permanent --zone=trusted --add-interface=wg0 && firewall-cmd --reload7Add a peer without restart
wg set wg0 peer 'b3J4ZXhhbXBsZXB1YmxpY2tleW9ubHkwMDAwMDAwMDA=' allowed-ips 10.99.0.3/32 wg-quick save wg08Use NetworkManager on RHEL
9Show the last handshake (is the peer alive?)
wg show wg0 latest-handshakes10Stop it
wg-quick down wg0
Nothing matches this filter.
Watch out
- Private keys stay on their own host (
chmod 600); only public keys are shared. - A wrong AllowedIPs (like
0.0.0.0/0by mistake) sends all traffic through the tunnel. - WireGuard has no user login or MFA; for many users use a product on top (Tailscale, Netbird, Headscale).
Files
/etc/wireguard/*.conf- Interface configs (secret!).
Tips to remember
- Give every device its own key and /32 address, so you can remove one device alone.
Exit codes
0 | Success. |
1 | Error. |