WireGuard RX-ERROR Fix: Relay SNAT vs MASQUERADE Bug
Part two of the same investigation: MTU fixed, MSS clamping active, NICs upgraded — ping tests showed 0% loss. Then the VMs got rebooted to apply the hardware changes, and 5-8% loss came right back. The cause this time was a completely different counter than before.
Every fix in our WireGuard stability playbook was holding. TX-DROP — the counter that pointed at the original MTU problem — wasn't growing. And yet the tunnel was dropping packets again after the VMs came back up from their reboot. This is the second-layer investigation: what a different counter, RX-ERROR, actually means, and how a relay server's hardcoded NAT port was quietly breaking WireGuard's own anti-replay protection.
Need WireGuard Relay Fixed?
Need help? Connect on WhatsApp 👉 wa.link/uw9n3f
Or ask on website chat for freelancer support.
The Setup (One Extra Hop)
Office MikroTik (PPPoE)
↓ UDP :53
[RELAY SERVER] ← forwards to bypass ISP UDP blocking
iptables DNAT: UDP :53 → hub:443
↓ UDP :443
Hub MikroTik CHR
/ \
Remote-A Remote-B
The office router doesn't connect straight to the hub — it goes through a relay that DNATs port 53 traffic to the hub's real WireGuard port. That relay hop is invisible to wg show on either end, which is exactly why it was easy to overlook as a cause.
Step 1: Confirm TX-DROP Is Not the Cause
/interface print stats where type=wg
# NAME RX-BYTE TX-BYTE RX-PACKET TX-PACKET RX-DROP TX-DROP RX-ERROR
# wg-hub 383,361,332 2,474,547,168 944,049 2,023,530 0 2,588 43
TX-DROP sat at 2,588 — accumulated during the reboot's reconnection, but not increasing during a fresh 60-second ping test. The MTU fix was still holding. Something else was causing the new loss.
Step 2: RX-ERROR Was Growing
CheckTimeRX-ERROR
After rebootT+08
First checkT+30 min43
Second checkT+45 min71
Growing at roughly 4 per re-key cycle (WireGuard re-keys every 180 seconds by default). RX-ERROR counts packets that arrived at the WireGuard interface but failed authentication — WireGuard uses ChaCha20-Poly1305 authenticated encryption, and a failed MAC check gets rejected and counted here, not at TX-DROP. Common causes: the built-in anti-replay window rejecting an out-of-sequence packet, a packet encrypted with a key that's already been rotated out, or (rarely) genuine corruption.
Step 3: The Relay's iptables Rules
# On the relay
iptables -t nat -L -n -v --line-numbers
Chain POSTROUTING
3 638 379K SNAT udp → <hub-ip> to:<relay-ip>:44810
Every WireGuard packet leaving the relay toward the hub gets rewritten to a fixed source port — 44810, always. The hub sees every packet from the office, regardless of what "phase" of the WireGuard protocol it's part of, as coming from the exact same source/port pair.
Step 4: Why a Fixed SNAT Port Causes RX-ERROR
A fixed SNAT rule isn't stateful the way conntrack expects for tracking flows — the same port is reused for every packet with no per-flow distinction. During a WireGuard re-key event, the new handshake's Initiation packet goes out on the same source port as the still-active data stream's packets. The relay has no way to keep those two logical flows ordered relative to each other, so during the brief re-key window packets can arrive at the hub out of sequence.
WireGuard's anti-replay protection — a 64-packet sliding window designed specifically to reject replayed or badly-reordered packets as a security measure — sees those out-of-window sequence numbers and drops them. That rejection is exactly what RX-ERROR is counting.
A secondary factor made it worse: the relay's nf_conntrack_udp_timeout_stream was set to 120 seconds — shorter than WireGuard's 180-second re-key interval. If the tunnel ever went briefly quiet, the NAT state could downgrade before the next re-key, adding another path to the same symptom.
Step 5: The Fix — MASQUERADE, Not Fixed SNAT
# Remove the hardcoded SNAT rule
iptables -t nat -D POSTROUTING -p udp -d <hub-ip> -j SNAT --to-source <relay-ip>:44810
# Replace with MASQUERADE — fully stateful, port tracked per flow
iptables -t nat -A POSTROUTING -p udp -d <hub-ip> -j MASQUERADE
# Flush the old conntrack entry so the new rule takes effect immediately
conntrack -D -p udp --orig-src <office-ip> --orig-dst <relay-ip> --orig-port-src 443 --orig-port-dst 53
# Widen the UDP stream timeout past WireGuard's re-key interval
echo 'net.netfilter.nf_conntrack_udp_timeout = 60' >> /etc/sysctl.d/99-vpn.conf
echo 'net.netfilter.nf_conntrack_udp_timeout_stream = 600' >> /etc/sysctl.d/99-vpn.conf
netfilter-persistent save
MASQUERADE assigns a port dynamically per conntrack entry instead of reusing one fixed port for everything — the re-key handshake flow and the ongoing data flow get tracked separately, so they can't be reordered relative to each other by the NAT layer.
Verification: RX-ERROR Flatlines
CheckRX-ERROR
Before fixgrowing ~4 per 3-minute re-key cycle
After fix (+90s)86
After fix (+3 min)86 — unchanged
After fix (+6 min)86 — unchanged
A tight burst of drops during the re-key window (5 drops in 5 seconds — anti-replay rejecting a cluster of reordered packets) became a small number of scattered single drops, which is the inherent, effectively unavoidable cost of WireGuard's ~200ms handshake window — not a bug, just physics.
Three Counters, Three Different Meanings
CounterMeaningCommon cause
TX-DROPOutbound packet couldn't be sentMTU too large
TX-QUEUE-DROPOutbound queue fullSustained congestion / CPU overload
RX-ERRORReceived packet failed authenticationReplay protection triggered by reordering — often a NAT relay
FAQ
Why didn't this show up before the reboot?
The fixed SNAT port had been running for months without visible issues — a stable, long-lived tunnel doesn't re-key under the same timing conditions as one that just re-established every peer at once. The reboot's mass reconnection created exactly the packet-ordering conditions the fixed-port SNAT couldn't handle cleanly.
Is MASQUERADE always the right choice over a fixed SNAT port?
For any protocol with multiple concurrent logical flows through the same NAT — which includes WireGuard's handshake-vs-data distinction — yes. A fixed SNAT port is fine for simple single-flow port forwarding, but the wrong tool once a protocol needs its flows tracked independently.
Could this same bug happen without a relay in the path at all?
No — this specific failure mode requires a NAT device reusing one fixed port across multiple logical flows. A direct WireGuard connection with no relay doesn't have this problem, since there's no intermediate NAT layer to reorder packets in the first place.
Fixed one WireGuard problem and a different one appeared? That's usually a sign there are two separate root causes layered on top of each other — we dig past the first fix to find what's underneath. Talk to us.