Protocol ExplorerGuidesPricing

WireGuard: Peer Keys, UDP and IP Routing

WireGuard creates a layer-3 encrypted tunnel using configured peers and public keys. Its cryptokey routing links allowed IP ranges to the peer that should receive them.

Updated · Editorial approach and simulation limits

Public keys identify configured peers

A WireGuard interface has private and public key material, and each peer is configured with the public key of the other side. A handshake establishes fresh session keys; the transport carries encrypted IP packets after the peers authenticate.

The protocol is intentionally compact, but operational behavior still depends on configuration: endpoints, keys, allowed IPs, routing and firewall policy. A peer with a valid key can still fail to exchange useful traffic if the route does not select it.

Allowed IPs connect peer identity to routing

Allowed IPs define which source addresses are accepted from a peer and which destination prefixes are routed to it. This cryptokey-routing model combines peer selection and traffic policy. Inspect both the operating system’s route table and the WireGuard peer configuration.

A successful handshake shows that peers exchanged authenticated protocol messages. It does not prove that an inner application packet was routed to the tunnel, accepted by the remote peer or allowed by the destination network.

UDP transport and roaming behavior

WireGuard sends encrypted transport over UDP. Endpoint addresses can be updated when authenticated packets arrive from a new source, supporting some roaming scenarios. UDP itself does not provide the reliability; WireGuard’s protocol and the inner application determine how traffic behaves.

A network capture can identify outer peer addresses and timing but not the encrypted inner packet without endpoint access. Use the official WireGuard protocol description, Quick Start and wg(8) manual when diagnosing key, route or reachability problems.

Peer keys identify who can speak, not where packets travel

The public key in a peer entry identifies the cryptographic peer. An IP address and UDP port in the Endpoint field are only the current network location used to send packets; they are not the identity check. A roaming client can start without a fixed endpoint, authenticate to its configured peer, and then have the observed source address used as its latest endpoint. DNS can help resolve a configured endpoint name, but changing that name does not change which public key is trusted.

This distinction helps separate a peer-identity failure from an ordinary reachability problem. If packets reach the listener but the key does not match an allowed peer, no useful tunnel session is established. If the key is right but the route points elsewhere, the handshake may work while application traffic never enters WireGuard.

AllowedIPs combine destination selection with source validation

AllowedIPs is more than a list of remote subnets. For outgoing traffic delivered to a WireGuard interface, its prefix map selects the peer that should receive each destination. On receive, the peer’s configured prefixes also constrain which inner source addresses are accepted from that peer. This is the cryptokey-routing model: a peer key and a set of IP prefixes are checked together.

There are two routing decisions to inspect. The operating system first decides whether a destination should use the WireGuard interface at all; the WireGuard interface then selects a peer using its AllowedIPs. With wg-quick, prefixes can also be installed in the operating-system routing table. A split tunnel might list only a private network such as 10.20.0.0/24. A full tunnel normally includes both 0.0.0.0/0 and ::/0 when IPv4 and IPv6 traffic should use the VPN. Missing one family can leave some traffic outside the intended path.

Read a minimal client configuration line by line

This illustrative wg-quick client configuration routes only the example private subnet through the gateway. The key names below are placeholders, and 198.51.100.10 is a documentation address; generate unique keys for an actual deployment and configure the matching client public key on the gateway.

[Interface]
Address = 10.20.0.2/32
PrivateKey = CLIENT_PRIVATE_KEY_PLACEHOLDER
DNS = 10.20.0.1

[Peer]
PublicKey = GATEWAY_PUBLIC_KEY_PLACEHOLDER
Endpoint = 198.51.100.10:51820
AllowedIPs = 10.20.0.0/24
PersistentKeepalive = 25

Address assigns an inner interface address. PrivateKey stays on this client. The peer’s PublicKey is the gateway identity, while Endpoint tells the client where to send UDP packets initially. AllowedIPs selects the private destinations for this peer; it is not a list of DNS names. The DNS setting is a convenience understood by wg-quick on supported systems, not a field in the WireGuard handshake itself. The gateway must also allow the client’s inner address and have a return route.

What a WireGuard packet capture reveals

A capture outside the tunnel shows outer IP addresses, UDP ports, packet direction, timing and approximate sizes. The WireGuard header identifies whether a packet is a handshake initiation, handshake response, cookie reply or transport-data packet. The handshake uses public-key authentication to establish fresh symmetric session keys; transport packets then carry encrypted inner IP packets. The inner source and destination addresses, DNS question and application payload are not readable from an ordinary outer-interface capture.

Use the trace to answer bounded questions: does a UDP packet leave, does a response return, and do encrypted data packets follow? Do not infer which web request is inside an encrypted packet. On an endpoint, compare the trace with wg show output such as the latest handshake and transfer counters. A recent handshake is evidence that peers authenticated; it is not proof that an inner route or application succeeded.

Why a handshake can succeed while the tunnel has no useful traffic

Trace the path in layers. First confirm that the interface is up and the peer’s key is correct. Next check that the operating-system route sends the destination to the WireGuard interface. Then confirm the peer’s AllowedIPs covers that destination and that the remote peer accepts the client’s inner source address. If the client’s transfer counter rises but the server’s does not, inspect the outer firewall and NAT mapping. If both counters rise but replies do not return, inspect forwarding, the destination firewall and the return route.

Name resolution is a separate clue: a tunnel can pass numeric-address traffic while the configured resolver is unreachable or not routed. A reduced MTU can matter when small packets work but larger transfers stall. Change one layer at a time and record the route, peer state and counter change; do not treat the handshake indicator as a complete connectivity test.

WireGuard and IPsec use different policy models

Both can protect IP traffic across an untrusted network, but their configuration and negotiation models differ. WireGuard maps configured peer keys to AllowedIPs and uses a compact handshake over UDP. Common IPsec deployments use IKEv2 to negotiate Security Associations and traffic selectors, then apply policy to matching packets. The useful comparison is operational: which peers and prefixes must be managed, what identities and certificates are required, which platforms interoperate, and how the organization audits changes. Neither label alone proves that a deployment is secure. Compare IPsec Security Associations and traffic policy with this peer-key model.

Use PersistentKeepalive only for a real NAT requirement

WireGuard is quiet when no traffic needs to move. A client behind stateful NAT may therefore lose the mapping that would let a peer initiate traffic back to it. PersistentKeepalive sends an authenticated empty packet at the configured interval to keep that mapping active; the official quick-start guide describes 25 seconds as a broadly useful value for this case. It is disabled by default because many peers do not need it. Enable it on the side that must remain reachable through NAT, and consider the extra traffic and network policy rather than adding it to every peer automatically.

Explore WireGuard interactively

Follow the matching exchange packet by packet. The animation is a scripted teaching model with illustrative timing, not a capture of your network.

Open the WireGuard animation · Compare Free and Pro

Specification and source

For exact protocol requirements, consult the primary document: WireGuard: Protocol and Cryptography. This page summarizes selected behavior and is not a substitute for the specification.

Related protocol lessons

Browse all security and access protocols · Read the outer tunnel packet and inner IP packet separately