Skip to content

Move to nftables (from iptables) and use flowtables to improve performance #1889

@frankozland

Description

@frankozland

Hey Bill -

Migrating our firewall to nftables with flowtables offers significant performance improvements (lower CPU, higher throughput, reduced latency) for our routers, especially with established connections. This is achieved through a more efficient rule processing engine and, crucially for capable hardware, the ability to offload connection tracking and forwarding directly to the network interface hardware, completely bypassing the CPU for those packets. This not only scales better but also simplifies management in the long run.

Managing dynamic blacklists, whitelists, or even network service discovery becomes trivial, enabling more responsive security policies without performance penalties.

Software Flow Offloading (Applicable to ALL hardware, including Raspberry Pi):

Mechanism: For established TCP and UDP connections, flowtables enable a "fast path" that bypasses the bulk of the Netfilter chain traversal. The kernel performs a quick lookup in the flowtable at the earliest possible hook (ingress). If a match is found, the packet is immediately forwarded without further rule evaluation in forward, postrouting, etc.

Impact on Raspberry Pi 4B+:

Reduced CPU Cycles: The CPU spends significantly fewer cycles per packet for established flows, freeing up resources for other tasks (like WireGuard crypto or other services running on the Pi).

Higher PPS: The Pi can handle a much higher packet per second rate before CPU saturation, making it more capable of sustaining gigabit speeds, especially with many concurrent connections.

Lower Latency: Less processing time in the kernel translates directly to lower latency for ongoing data streams.

Even on resource-constrained devices like the Raspberry Pi, software flow offloading provides a measurable 20-50% (or more) reduction in CPU usage and a corresponding increase in throughput for established connections. This pushes the Pi's performance closer to line-rate for common traffic patterns.

On capable server hardware, hardware flow offloading effectively transforms the firewall into a wire-speed appliance for established traffic. This liberates the CPU for value-added services like robust VPN encryption, deep packet inspection, or application-layer firewalls, enabling true multi-gigabit routing performance without compromise.

While iptables commands on modern kernels might be translated to nftables bytecode (the xtables-nft backend), this only addresses syntax. It doesn't unlock the fundamental architectural advantages of nftables like flowtables, atomic updates, or direct hardware offload that a native nftables configuration provides.

While there's an initial learning investment, the unified syntax and clearer logic eventually simplify rule management. The long-term benefits in performance and maintainability far outweigh this initial overhead. We can start with a well-documented baseline configuration.

nftables does a better job at "kill switch" - Granular Control: nftables allows for precise rules that mark traffic intended for the VPN and strictly enforce that only marked traffic can leave the WAN. This is incredibly reliable.
Kernel-Level Enforcement: The rules are enforced directly by the Linux kernel, making them highly resilient to application crashes or user-space errors.
Zero-Trust by Default: By setting default policies to drop and only allowing traffic through specific, controlled paths (the VPN tunnel), nftables enables a truly secure-by-default posture.

I know this is somewhat of a radical departure from what you have, but modern iptables is being translated to nftables now (iptables is the old way). iptables is simple translation and does not embrace the flowtables concept. Moving fully to nftables and better, flowtables, you will gain a massive speed boost for your user community.

**

Image

**

https://docs.kernel.org/networking/nf_flowtable.html
https://www.ubicloud.com/blog/improving-network-performance-with-linux-flowtables
https://thermalcircle.de/doku.php?id=blog:linux:flowtables_1_a_netfilter_nftables_fastpath

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions