Octet

What is cryptokey routing in WireGuard, and what does AllowedIPs do?

Show the answer

Say this first

Each peer is a public key plus a list of AllowedIPs. For outgoing packets, WireGuard picks the peer whose AllowedIPs best match the destination, like a routing table, and encrypts to that peer. For incoming packets, after decryption it checks that the inner source address is inside the AllowedIPs of the peer that sent it and drops the packet otherwise. So AllowedIPs is both the route and the source filter, and one prefix can belong to only one peer on an interface.

Go deeper

Site-to-site example

OnPeerAllowedIPs
GW1 (LAN 10.1.0.0/24)GW2172.16.99.2/32, 10.2.0.0/24
GW2 (LAN 10.2.0.0/24)GW1172.16.99.1/32, 10.1.0.0/24

If GW2 forgets 10.1.0.0/24, packets from GW1's LAN arrive, decrypt, and are dropped because their source is not allowed for that peer.

Kernel routing still matters

The kernel decides which interface a packet uses. wg-quick adds routes for each AllowedIPs entry; with plain ip link add wg0 type wireguard you add them yourself.

Behaviours worth knowing

  • AllowedIPs = 0.0.0.0/0 makes that peer the default for everything, the usual full-tunnel client.
  • Adding a prefix to one peer removes it from any other peer on the same interface.
  • For dynamic routing, a common pattern is one peer per wg interface with 0.0.0.0/0, and BGP or OSPF programming the kernel routes.

Traps

  • Calling AllowedIPs "just an ACL". It also decides which peer an outgoing packet is encrypted to.
How did you do?Book 8.5 Example Systems