networking, updated

WireGuard

WireGuard is a lean VPN that tunnels IP packets in UDP, with one fixed set of modern cryptography and no negotiation. It is built into Linux, and it powers many commercial VPNs and mesh networks such as Tailscale.

OSI layer
3 Network
Carried in
UDP
Ports
51820/udp (default, configurable)
Specs
WireGuard whitepaper
Wireshark filter
wg
Encrypted
yes

Packet structure

A session starts with a handshake initiation:

WireGuard handshake initiation148 bytes

Select a field to see what it does.

WireGuard whitepaper, section 5.4.2. Always 148 bytes, in one UDP datagram. Multi-byte integers are little-endian. The response (type 2) is 92 bytes and looks alike.

After the handshake, every tunnelled packet looks like this:

WireGuard transport data16 bytes + variable

Select a field to see what it does.

WireGuard whitepaper, section 5.4.6. 16-byte header, then the encrypted inner IP packet padded to a multiple of 16 bytes, plus a 16-byte tag. A packet with an empty payload is a keepalive.

How it works

sequenceDiagram
    participant A as Peer A
    participant B as Peer B :51820
    A->>B: Handshake initiation (type 1, 148 bytes)
    B->>A: Handshake response (type 2, 92 bytes)
    Note over A,B: Session keys derived (Noise IK)
    A->>B: Transport data (type 4), first packet confirms the keys
    B->>A: Transport data
    Note over A,B: New handshake every 2 minutes or 2^60 packets
    A->>B: Keepalive (type 4, empty), optional

There is no algorithm negotiation and no version field: the crypto is fixed (Curve25519, ChaCha20-Poly1305, BLAKE2s, SipHash, HKDF). A future change would be a new protocol.

In Wireshark

FilterShows
wgAll WireGuard (default port 51820; use Decode As or enable heuristics for others)
wg.type == 1Handshake initiations (new sessions, every 2 minutes per active tunnel)
wg.type == 2Handshake responses
wg.type == 3Cookie replies: the responder is under load
wg.keepaliveKeepalives (data messages with an empty payload, 32 bytes)
wg.receiver_pubkeyInitiations Wireshark could match to a known public key (with keys configured)

With the peers’ static public keys configured (Preferences › Protocols › WireGuard), Wireshark can tell which peer each initiation is for (it checks MAC1 against each key); with a key log file of the ephemeral private keys it can also decrypt the tunnel.

What normal looks like: a handshake every two minutes per active tunnel, then data. UDP from a workstation to an unknown host on 51820 (or any port) with initiations of exactly 148 bytes and responses of 92 bytes is a WireGuard tunnel, sanctioned or not.

Security notes

References

§ home
~/knubertus/home/
1,1 Top