WireGuard Site-to-Site on Debian 13: Config, MTU Maths and What It Looks Like on the Wire

WireGuard is the VPN I reach for when I want something I can read in one screen. The whole configuration is a private key, a public key, an endpoint and a list of allowed IPs. There is no negotiation, no cipher suite menu and no state machine to debug.

For this post I built a site-to-site tunnel on my Debian 13 test VM. Two network namespaces, a and b, stand in for two sites, joined by a veth pair that plays the part of the internet. Everything below is real output from that lab.

The lab

sudo apt install wireguard-tools tcpdump iperf3

sudo ip netns add a
sudo ip netns add b
sudo ip link add va type veth peer name vb
sudo ip link set va netns a
sudo ip link set vb netns b
sudo ip -n a addr add 10.99.0.1/24 dev va
sudo ip -n b addr add 10.99.0.2/24 dev vb
sudo ip -n a link set va up
sudo ip -n b link set vb up

10.99.0.0/24 is the “underlay”, the network the tunnel travels over. The tunnel itself will use 10.100.0.0/30.

Keys

Each side needs its own key pair. I also generate a pre-shared key, which is optional but adds a symmetric layer on top of the key exchange.

umask 077
wg genkey | tee a.key | wg pubkey > a.pub
wg genkey | tee b.key | wg pubkey > b.pub
wg genpsk > psk

The umask 077 matters. wg genkey warns you if the output file is readable by others, and a private key with loose permissions is the one mistake that undoes the whole design.

Bringing up the tunnel

for n in a b; do sudo ip -n $n link add wg0 type wireguard; done

sudo ip netns exec a wg set wg0 private-key a.key listen-port 51820 \
  peer $(cat b.pub) allowed-ips 10.100.0.2/32 \
  endpoint 10.99.0.2:51820 preshared-key psk

sudo ip netns exec b wg set wg0 private-key b.key listen-port 51820 \
  peer $(cat a.pub) allowed-ips 10.100.0.1/32 \
  endpoint 10.99.0.1:51820 preshared-key psk

sudo ip -n a addr add 10.100.0.1/30 dev wg0
sudo ip -n b addr add 10.100.0.2/30 dev wg0
sudo ip -n a link set wg0 up
sudo ip -n b link set wg0 up

Before any traffic flows, wg show has no handshake line:

interface: wg0
  public key: uKQfa5qQUoD+ElWwIoizIoZ3w+ghbVpeht8A3I8erF4=
  private key: (hidden)
  listening port: 51820

peer: dLqg5b...
  preshared key: (hidden)
  endpoint: 10.99.0.2:51820
  allowed ips: 10.100.0.2/32

That is the first thing worth knowing. WireGuard is silent until it has something to send. A tunnel with no handshake is not necessarily broken, it is just idle. Send a ping and it comes alive:

$ sudo ip netns exec a ping -c 3 -q 10.100.0.2
3 packets transmitted, 3 received, 0% packet loss, time 2037ms
rtt min/avg/max/mdev = 0.405/0.487/0.636/0.105 ms

$ sudo ip netns exec a wg show
...
  latest handshake: 3 seconds ago
  transfer: 476 B received, 532 B sent

The same thing as a config file

On a real pair of hosts you would use wg-quick and a file in /etc/wireguard/wg0.conf (mode 600). This is site A’s file:

[Interface]
PrivateKey = <contents of a.key>
Address = 10.100.0.1/30
ListenPort = 51820

[Peer]
PublicKey = <contents of b.pub>
PresharedKey = <contents of psk>
AllowedIPs = 10.100.0.2/32
Endpoint = 10.99.0.2:51820
PersistentKeepalive = 25

PersistentKeepalive = 25 is for the side that sits behind NAT. It sends a tiny packet every 25 seconds so the NAT mapping does not expire. For a site-to-site link where both ends have public addresses you can leave it out.

Enable it with sudo systemctl enable --now wg-quick@wg0.

To route a whole remote LAN, extend AllowedIPs to include it, for example 10.100.0.2/32, 192.168.50.0/24. AllowedIPs does two jobs at once: it is the routing table for outgoing packets and the source filter for incoming ones. That is called cryptokey routing, and it is the single idea you need to understand WireGuard.

What it looks like on the wire

I captured on the underlay interface while forcing a fresh handshake and sending two pings:

IP 10.99.0.1.51820 > 10.99.0.2.51820: UDP, length 148
IP 10.99.0.2.51820 > 10.99.0.1.51820: UDP, length 92
IP 10.99.0.1.51820 > 10.99.0.2.51820: UDP, length 128
IP 10.99.0.2.51820 > 10.99.0.1.51820: UDP, length 128
IP 10.99.0.1.51820 > 10.99.0.2.51820: UDP, length 128
IP 10.99.0.2.51820 > 10.99.0.1.51820: UDP, length 128

The first two packets are the handshake: a 148 byte initiation and a 92 byte response. Everything after is encrypted data. Each ICMP echo is 84 bytes inside the tunnel, padded up to a multiple of 16 (96), plus 32 bytes of WireGuard header and authentication tag, which gives 128. It is all UDP on one port. A firewall in the middle sees nothing but UDP 51820.

Capturing inside the tunnel on wg0 instead shows the clear text ICMP, which is handy for debugging:

IP 10.100.0.1 > 10.100.0.2: ICMP echo request, id 55359, seq 1, length 64
IP 10.100.0.2 > 10.100.0.1: ICMP echo reply, id 55359, seq 1, length 64

The MTU maths

WireGuard defaults the interface MTU to 1420. The reason is the worst case encapsulation overhead on a 1500 byte path:

LayerBytes
Outer IPv6 header (worst case)40
UDP header8
WireGuard data header and tag32
Total overhead80

1500 minus 80 is 1420. Over IPv4 the overhead is only 60, so 1440 would fit, but 1420 works for both and you do not need to know which the peer will use.

I checked the boundary with do-not-fragment pings through the tunnel. A ping payload of 1392 plus 8 bytes ICMP and 20 bytes IP is 1420:

payload 1392: 1400 bytes from 10.100.0.2: icmp_seq=1 ttl=64 time=0.161 ms
payload 1393: ping: sendmsg: Message too long

One byte more and the kernel refuses to send it. The MTU is exactly what the maths says.

When the path is smaller than 1500

This is where tunnels earn their reputation. I dropped the underlay MTU to 1400 to mimic a path with extra encapsulation, such as PPPoE, and repeated the large ping:

sudo ip -n a link set va mtu 1400
sudo ip -n b link set vb mtu 1400

Both the 1392 and 1300 byte pings still succeeded. WireGuard does not set the DF bit on the outer packet, so the kernel fragmented it. The capture shows the evidence, a 1452 byte UDP datagram followed by a bare fragment:

IP 10.99.0.1.51820 > 10.99.0.2.51820: UDP, length 1452
IP 10.99.0.1 > 10.99.0.2: ip-proto-17

The fragment line with no ports is the tell. It works, but fragmentation costs CPU, doubles the packet count and some firewalls drop fragments. The fix is to lower the tunnel MTU so nothing needs fragmenting:

sudo ip -n a link set wg0 mtu 1340
sudo ip -n b link set wg0 mtu 1340

In wg-quick you set it with MTU = 1340 in the [Interface] section. The rule of thumb is underlay MTU minus 80.

Throughput

With the MTU back at 1420 I ran iperf3 through the tunnel:

[  5]   0.00-4.00   sec   626 MBytes  1.31 Gbits/sec   50            sender
[  5]   0.00-4.01   sec   624 MBytes  1.30 Gbits/sec                  receiver

1.3 Gbit/s on a 2 vCPU VM, with both ends and the encryption on the same host, so treat it as an upper bound for the lab and not a prediction for a real link.

What a wrong key looks like

I replaced site B’s view of A with a bogus public key and pinged again:

2 packets transmitted, 0 received, 100% packet loss

No error, no log line, nothing. That is by design: WireGuard does not respond to packets it cannot authenticate, so a port scanner sees nothing there. The cost is that debugging is quiet. My checklist is:

  1. wg show: is there a latest handshake? If not, the keys, endpoint or firewall are wrong.
  2. tcpdump -ni <underlay> udp port 51820: do packets leave, and does anything come back?
  3. Compare AllowedIPs on both sides. A handshake with no traffic usually means the allowed IPs do not cover the destination.
  4. If small pings work and large transfers hang, it is the MTU.

Verdict

The config is short enough to keep in your head, the packets are predictable, and the failure modes are few. The two things to remember are cryptokey routing, which means AllowedIPs is both route and filter, and the 80 byte overhead, which means the tunnel MTU is always the path MTU minus 80.