WireGuard is the modern, in-kernel VPN that replaced OpenVPN for most new deployments. Its config file is half a page, the daemon is a kernel module, and the cipher suite is fixed (no negotiation, no surprises). This article covers a production-ready WireGuard server, a per-peer config workflow that scales, and the DNS-aware routing that makes split-tunnel actually pleasant to use.
How to verify
Inspect what is up, what is connected, and the routing:
sudo wg show
sudo systemctl status wg-quick@wg0
sudo ip -4 route show table all | grep wg
sudo sysctl net.ipv4.ip_forward net.ipv6.conf.all.forwarding
sudo ss -tunlp | grep -E ':51820|wireguard'
sudo journalctl -u wg-quick@wg0 --since "1 hour ago"
wg show is the truth: peers, last handshake, transferred bytes. A peer that has never handshook is a misconfigured client or a blocked UDP port — the two most common WireGuard issues.
What’s happening
WireGuard runs on top of UDP. Each peer is identified by an Ed25519-shaped public key; there is no notion of usernames, just keys. The server’s config lists allowed peer public keys and the source IPs they are permitted to use; the client’s config lists the server’s public key and the endpoint to dial.
wg-quick is the systemd-friendly wrapper that reads /etc/wireguard/wg0.conf, sets up the interface, applies routes from the AllowedIPs field, and runs the optional PostUp/PostDown hooks. The kernel module is included in Linux 5.6+; on older kernels, the DKMS module is a clean install but a maintenance liability.
Split-tunnel vs full-tunnel is a routing decision, not a WireGuard one. AllowedIPs = 0.0.0.0/0, ::/0 on the client makes everything go through the tunnel; AllowedIPs = 10.0.0.0/8, 192.168.0.0/16 sends only RFC1918 traffic through. The server reuses AllowedIPs for input filtering — a packet from a peer arriving with a source IP not listed in that peer’s AllowedIPs is dropped.
The procedure
- Generate the server key.
umask 077 && wg genkey | tee /etc/wireguard/server.key | wg pubkey > /etc/wireguard/server.pub. Permissions matter — the private key must not be world-readable. - Write the server config.
/etc/wireguard/wg0.conf:[Interface] Address = 10.10.0.1/24, fd00:10:10::1/64 ListenPort = 51820 PrivateKey = <contents of server.key> PostUp = nft add table inet wgforward; nft add chain inet wgforward forward { type filter hook forward priority 0\; } PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE - Enable IP forwarding.
sudo sysctl -w net.ipv4.ip_forward=1 net.ipv6.conf.all.forwarding=1and persist in/etc/sysctl.d/99-wireguard.conf. - Bring up the tunnel.
sudo systemctl enable --now wg-quick@wg0.sudo wg showshould now list the interface with no peers. - Generate per-peer keys, server-side. A script:
for p in alice bob charlie; do umask 077; wg genkey | tee peers/$p.key | wg pubkey > peers/$p.pub; done. Each peer gets a.key(give to peer) and a.pub(add to server). - Add each peer to the server config and reload. Per peer, append:
then[Peer] PublicKey = <contents of alice.pub> AllowedIPs = 10.10.0.10/32, fd00:10:10::10/128 PresharedKey = <wg genpsk output, optional but recommended>sudo wg syncconf wg0 <(wg-quick strip wg0).syncconfadds peers without dropping the tunnel. - Hand the peer a config file. The matching client config:
[Interface] PrivateKey = <alice.key contents> Address = 10.10.0.10/32, fd00:10:10::10/128 DNS = 10.10.0.1 [Peer] PublicKey = <server.pub contents> PresharedKey = <same PSK as server side> Endpoint = vpn.example.com:51820 AllowedIPs = 10.10.0.0/24, fd00:10:10::/64 # split-tunnel; or 0.0.0.0/0, ::/0 for full PersistentKeepalive = 25 - Document key rotation. Per-peer keys can be rotated by generating a new keypair and replacing the
PublicKeyline on the server (and reloading). The peer keeps their old config until they receive the new one. A peer that loses their key file gets a new one — the old key continues to authenticate until you remove it from the server.
Common pitfalls
- A client behind a NAT that closes idle UDP flows needs
PersistentKeepalive = 25or the tunnel goes silent and the next packet sees the keepalive failure. Server side, set the same on the peer block if the server initiates traffic. AllowedIPson the server doubles as an input ACL — sending a peer config withAllowedIPs = 10.10.0.10/32and the peer using10.10.0.11results in dropped packets with no log entry. Match the addresses exactly.- DNS leaks: a full-tunnel client with
DNS = 10.10.0.1on Linux still uses systemd-resolved’s default per-interface DNS unlessresolvconfis installed. Verify on each client OS — Linux, macOS, Windows, iOS, Android all behave differently. - WireGuard logs minimally by design —
wg showshows handshake state and transferred bytes, that’s it. For per-flow logging, you need iptables/nftables LOG rules on the wg0 interface. - The
MTU = 1420default works on most paths but a low-MTU underlay (PPPoE, certain mobile carriers) needsMTU = 1300or lower to prevent fragmentation black holes. Test withping -M do -s 1372 <internal-host>.
In the engagements we run, WireGuard is the default operator VPN — paired with an SSH bastion behind it, the access pattern becomes “connect to WireGuard, then SSH to the box”. The peer-config issuance, key rotation, and offboarding live in Managed Operations — a VPN without an offboarding process is a backdoor with a TODO.