Stop WireGuard from falling over when your roaming peer changes IPs
Technical Briefing | 11/19/2026
You set up a WireGuard tunnel between your home server and a laptop that moves between coffee shops and office Wi-Fi. It works great for an hour, then it suddenly goes dead until you manually restart the service. I have seen this drive people crazy because the connection status looks fine until you try to push a packet and the kernel has already blacklisted the peer’s previous endpoint.
Why the kernel keeps holding onto stale state
WireGuard is stealthy by design. It does not actively hunt down roaming peers if the handshake fails a few times. When the roaming client jumps to a new network and gets a new public IP, the server side is still trying to send encrypted packets to the old endpoint address. This bit me in prod during a site-to-site migration where the ISP kept rotating upstream IPs on the client side, causing a silent drop.
PersistentKeepalive = 25
- Adding PersistentKeepalive to the client config forces a small packet out every 25 seconds even if there is no traffic.
- This keeps the server NAT mapping alive so incoming traffic does not get dropped by your router.
- It triggers an immediate handshake if the client IP changes, forcing the server to update its routing table for that peer.
Don’t ignore the mtu settings either
Even with keepalives, if your tunnel MTU is too high, some packets will just get silently discarded by intermediate routers, leading to a half-broken state where pings work but SSH hangs. Set your MTU to 1420 to avoid overhead issues. If you are still seeing weird drops, check if your ISP is throttling UDP ports, though usually, these connection stalls are just the kernel trying to be too polite by not shouting at a peer that has moved on.
Next time you debug a stuck tunnel, check the output of wg show to see when the last handshake actually happened. If that timestamp is older than thirty seconds, stop looking at your firewall rules and focus on the handshake timing instead.
