Don’t let your nftables sets get stale when users roam

Networking & Firewalls (Nftables/Iptables/WireGuard)

Don’t let your nftables sets get stale when users roam

Technical Briefing | 11/25/2026

You probably use named sets in nftables to keep your rules clean. It beats listing a hundred individual IP addresses, right? But if you are using these for dynamic WireGuard peers or VPN clients that bounce between cellular and Wi-Fi, you might have noticed stale entries hanging around. The kernel doesn’t just clear these out because you feel like it should. Left unchecked, your rule base turns into a graveyard of disconnected sessions that still have hole-punched access to your internal subnets.

The trap of static timers in dynamic environments

Most people rely on the default timeout behavior or just purge the whole set on a timer. The problem is that netfilter has a specific way of handling element timeouts, and if you haven’t explicitly defined the timeout policy in your set definition, the entries just stay there forever. I have seen this cause some truly weird headaches where a user reconnects, gets a new lease, but hits an old rule entry that prevents their traffic from being correctly marked.

nft add set inet filter active_vpn_clients { type ipv4_addr; flags timeout; timeout 1h; gc-interval 1m; }

  • Enable the timeout flag when defining the set or it will not track expiration
  • Set a gc-interval that makes sense for your traffic load to avoid CPU spikes
  • Use dynamic updates via your VPN hook scripts to refresh the timestamp on active peers

If you are running a heavy amount of VPN traffic, do not set that garbage collection interval too low. You will end up waking the CPU every few seconds for essentially no reason. Aim for something sane, like 5 or 10 minutes. If a client hasn’t sent a packet in an hour, they probably aren’t coming back anyway. Keep an eye on the set occupancy in your monitoring dashboard before you go overboard with aggressive timeouts.

Linux Admin Automation  |  © www.ngelinux.com  |  11/25/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted