Skip to content

Lesson 1 of 9 · 24m

The WireGuard Mental Model: Keys, Peers, and Cryptokey Routing

Understand WireGuard as an identity-routing system rather than a traditional VPN server with users, passwords, and tunnels.

The first WireGuard outage I debugged was caused by treating it like OpenVPN with smaller config files. Someone expected a server-side user database, pushed routes, and client authentication callbacks. WireGuard has none of those concepts in the way people expect. It is a very small cryptographic routing engine: public keys identify peers, and allowed IPs decide which traffic may enter or leave through each peer.

Peers are identities and routing policy

A peer block does two jobs at once. PublicKey authenticates the remote endpoint cryptographically, while AllowedIPs constrains which source and destination addresses may use that peer:

[Interface]
PrivateKey = yAnz...redacted...=
Address = 10.44.0.2/32
ListenPort = 51820

[Peer]
PublicKey = q9fN...peer-forums...=
Endpoint = edge1.sudosecurity.org:51820
AllowedIPs = 10.44.0.0/24, 10.20.0.0/16
PersistentKeepalive = 25

This is not just encryption configuration. It is an authorization and routing statement compressed into one file. If a peer presents the correct key but sends traffic for an address outside AllowedIPs, WireGuard drops it. That tight coupling is a feature.

There is no implicit server mode

The same configuration shape appears on laptops, servers, routers, and gateways. A node listens if ListenPort is set. It initiates if a peer has Endpoint. "Server" is an operational role, not a WireGuard primitive. That means hub-and-spoke, mesh, and relay designs are all just different combinations of peer relationships.

Generate keys locally and keep private keys out of tickets, chat, and provisioning logs:

umask 077
wg genkey | tee privatekey | wg pubkey > publickey
wg-quick strip wg0 > stripped.conf

Never accept a private key generated by a central service unless you are intentionally operating escrowed device keys and understand the audit consequence.

Handshakes are cheap, silent, and roaming-friendly

WireGuard uses a modern Noise-based handshake over UDP. It does not maintain chatty control channels, and it can re-establish quickly when a laptop moves networks. PersistentKeepalive is not normally required everywhere; it exists mainly to preserve NAT or firewall state for nodes behind restrictive outbound networks.

Cryptokey routing is the core idea

The phrase sounds academic, but the operational meaning is simple: if you can reach a network through a peer key, possession of that key is part of the network permission. Losing or copying a private key therefore creates both authentication and routing consequences. Key rotation is network access revocation.

Field notes

  • Duplicate AllowedIPs across peers produce routing ambiguity that can look like random packet loss.
  • Endpoint belongs on the initiating side; a peer behind unknown NAT often has no stable endpoint at all.
  • WireGuard logs almost nothing by default because silence is part of the design. Build observability elsewhere.
  • The config file is not the desired state of the whole network; it is only one node's view.

Was this lesson helpful?

Sign in to rate