WireGuard has become a go-to VPN for its minimal codebase, high performance, and cryptographic modernity. However, when a tunnel misbehaves—intermittent connectivity, asymmetric routing, MTU issues, or NAT timeouts—you need packet-level visibility to quickly identify the root cause. tcpdump remains one of the most powerful tools for that purpose. This article walks through practical, technical techniques for using tcpdump to debug WireGuard tunnels, explaining what you can see on different interfaces, useful capture filters and formats, and common WireGuard problems you can diagnose with packet traces.
Why packet captures matter for WireGuard
WireGuard operates as a kernel network interface (usually named wg0, wg1, etc.) that encrypts IP packets and sends them over UDP between peers. This split between the encrypted UDP on the physical interface and the decrypted IP on the wg interface makes packet captures especially valuable. With the right capture strategy you can:
- Correlate encrypted UDP packets on the transit interface (e.g., eth0) with decrypted IP packets on wg0.
- See handshake behavior—initiations, responses, keepalives—and timing gaps.
- Detect MTU-related fragmentation or PMTU black holes by observing packet sizes and ICMP.
- Validate routing and AllowedIPs mapping by inspecting inner IP source/destination addresses on wg0.
- Identify NAT/conntrack resets or firewall drops by combining tcpdump evidence with conntrack/iptables state.
Practical tcpdump commands and what they show
Below are battle-tested tcpdump commands to capture the different aspects of WireGuard traffic. Use these on the WireGuard host and adjust interface names and UDP ports as appropriate.
Capture encrypted WireGuard traffic on the physical interface
To record the raw UDP traffic that WireGuard transmits:
Command:
tcpdump -i eth0 udp and port 51820 -nn -s 0 -w wg-encrypted.pcap
- -i eth0: capture on the physical interface.
- udp and port 51820: filter to standard WireGuard UDP port (adjust if using a different port).
- -nn: numeric IPs and ports (avoid DNS resolution).
- -s 0: capture full packet payloads so you can inspect UDP payload bytes.
- -w: write to a pcap file for later analysis in Wireshark.
This capture contains only encrypted UDP datagrams. You will not be able to read inner IPs without breaking cryptography, but you can analyze timing, packet sizes, and handshake exchanges.
Capture decrypted inner IP traffic on the wg interface
On the WireGuard interface you see post-decryption traffic—the real IP packets delivered to the kernel by WireGuard:
Command:
tcpdump -i wg0 -nn -s 0 -w wg-decrypted.pcap
- Captured frames show inner IP headers and payloads (ICMP, TCP, etc.).
- This capture lets you confirm whether traffic enters the tunnel, matches AllowedIPs, and whether MTU/fragmentation occurs inside the tunnel.
Live inspection and correlation
For on-the-fly troubleshooting you may prefer verbose, human-readable output rather than pcap files:
tcpdump -i any -nn -s 0 -A 'udp port 51820 or (ip and (src host 10.8.0.0/24 or dst host 10.8.0.0/24))'
- -A prints ASCII payload which can help spot plaintext application-level signalling, DHCP, or other cleartext protocols inside the tunnel.
- any interface (-i any) captures both encrypted and decrypted packets—useful for short bursts to correlate timestamps.
Understanding WireGuard handshake patterns in captures
WireGuard’s handshake uses the Noise protocol, producing identifiable packet flows even if the contents are opaque. Typical handshake-related observations in encrypted UDP captures:
- Initiation packets: one peer sends a small UDP datagram to the other—often followed by a larger response.
- Response packets and cookies: if the server is behind a cookie challenge or anti-DoS mechanism, you may see a cookie response before normal traffic resumes.
- Keepalive packets: if NAT is present, peers often send intermittent small packets (WireGuard’s PersistentKeepalive, typically every 25 seconds) to maintain NAT state. Look for periodic small UDP packets matching that cadence.
When troubleshooting failed handshakes, compare timestamps between hosts. A persistent lack of Response packets on the encrypted capture suggests the remote peer does not receive or cannot respond (NAT, firewall). If encrypted packets are exchanged but inner decrypted traffic never appears on wg0, check keys and AllowedIPs mismatches.
Correlation techniques: mapping encrypted packets to inner IP flows
To troubleshoot tricky cases you must correlate entries in the encrypted capture (physical interface) with the decrypted capture (wg interface). Useful correlation points:
- Timestamps: match precise packet times to identify which encrypted packet corresponds to which inner IP frame.
- Packet sizes: the encrypted UDP length often correlates to inner payload plus WireGuard header overhead—consistent size changes help match records.
- Keepalive frequency: a small UDP handshake followed by a burst of inner packets after a successful handshake indicates restored connectivity.
Example workflow:
- Start tcpdump on eth0 and wg0 to separate files with synchronized system clocks (use NTP).
- On eth0, find the UDP datagram that looks like a handshake or large data packet at time T.
- Open the wg0 capture and look for a decrypted IP packet within microseconds or milliseconds of T. That is the inner packet corresponding to the encrypted datagram.
Common problems you can identify with tcpdump
Below are frequent WireGuard issues and how tcpdump helps confirm or rule them out.
1. MTU and fragmentation problems
Symptoms: TCP stalls, packets hang at a particular size, PMTU discovery fails. Use tcpdump to check packet sizes and look for ICMP “Fragmentation Needed” messages on the path.
Inspection tips:
- Capture inner packets on wg0 and check IP total lengths. If inner packets are near or exceed the path MTU minus WireGuard overhead, they will be dropped upstream.
- Check for ICMP Type 3 Code 4 (fragmentation needed) messages on the encrypted or intermediate interface captures.
- Fixes: reduce tunnel MTU (e.g., ip link set mtu 1420 dev wg0) or adjust MSS clamping on iptables to reduce TCP segment size.
2. NAT and conntrack timeouts
Symptoms: Connections work briefly after activity but fail after idle periods; host behind NAT becomes unreachable from peer.
Use tcpdump to observe periodic keepalives on the physical interface. If no keepalives, NAT state will expire. Also check conntrack and firewall logs.
Commands and tips:
- tcpdump -i eth0 udp and port 51820 -nn -s 0 -A (to watch for keepalives).
- On Linux, sudo conntrack -L | grep to see NAT state lifetimes.
- Configure PersistentKeepalive=25 on the client side where NAT exists to maintain a mapping.
3. AllowedIPs and routing mismatches
Symptoms: Some destinations are reachable while others are not; traffic returns via the wrong interface.
On wg0 capture you will see which inner IPs are actually routed into the tunnel. If packets for a given IP never appear on wg0, the host’s routing table or AllowedIPs on the peer likely excludes them.
Verify configuration:
- ip -4 route show
- wg show wg0
- Use tcpdump on the local host to see if the OS tries to send traffic into wg0.
4. Firewall drops and iptables/nftables issues
Symptoms: Encrypted packets arrive, but no inner packets appear—packets may be blocked by FORWARD rules or nat masquerade issues.
Use tcpdump to verify traffic reaches the interface, then run:
- sudo iptables -L -v -n
- sudo iptables -t nat -L -v -n
- For nftables: sudo nft list ruleset
Combining these with tcpdump shows whether packets are dropped before or after netfilter hooks.
Advanced tips and integrations
- Use Wireshark for deeper analysis: load pcap files for visual timelines. Note: WireGuard payloads remain encrypted; Wireshark can display UDP payload bytes and help annotate timing and packet sizes. If you have full key and specialized dissector support configured (rare in production), you may get more protocol-level detail.
- Timestamp synchronization: ensure both peers have synchronized clocks (NTP) for reliable correlation between captures.
- Scripted correlation: use tshark to extract timestamps and lengths and correlate by time delta automatically (helpful for high-volume captures).
- Short captures plus ring buffers: use tcpdump -W and -C options for rolling captures during intermittent failures to avoid massive files.
Final checklist for efficient debugging
- Capture both encrypted UDP on the physical interface and decrypted inner IP on the wg interface.
- Use -s 0 to capture full payload; write to pcap for post-analysis.
- Correlate by timestamp and packet size; look for keepalive cadence and handshake patterns.
- Check MTU/ICMP and apply MSS clamping or reduce wg MTU when necessary.
- Verify firewall and conntrack state when packets arrive but connections don’t form.
By combining targeted tcpdump captures with an understanding of WireGuard’s kernel interface semantics and common failure modes, you can resolve most tunnel issues quickly and with high confidence. Keep captures focused, synchronize clocks, and document the correlation steps so you can reproduce and fix issues permanently.
For more articles and practical guides on dedicated VPN configurations and troubleshooting, visit Dedicated-IP-VPN.