All guides
Home Glossary nftables
Term

nftables

A Linux kernel subsystem for network packet filtering and classification, designed as a modern replacement for the legacy iptables framework.

nftables is a Linux kernel subsystem for network packet filtering and classification, designed as a modern replacement for the legacy iptables framework. It unifies the separate IPv4, IPv6, ARP, and Ethernet bridging utilities into a single architecture. By executing compact bytecode inside an in-kernel virtual machine, nftables processes network traffic with lower CPU overhead and greater configuration flexibility than its predecessors.

How it works

Unlike iptables, where protocol parsing and matching logic are hardcoded into individual kernel modules, nftables uses a generic evaluation engine. Most protocol intelligence lives in the user-space nft command-line utility, which compiles human-readable rules into bytecode and loads them into the kernel. This design reduces kernel code duplication and simplifies adding support for new network protocols without recompiling the kernel.

  • Atomic rule replacement: Entire rulesets are loaded and swapped in a single transaction, eliminating race conditions or brief security gaps while a firewall reloads.
  • Native data structures: Built-in sets, dictionaries, and concatenations allow rules to match thousands of IP addresses, ports, or interface pairs in constant or logarithmic time rather than scanning rules linearly.
  • Unified address families: A single inet table can evaluate both IPv4 and IPv6 packets simultaneously, cutting duplicate firewall logic in half.

Example

Administrators typically define rulesets declaratively in /etc/nftables.conf so the entire configuration loads atomically at boot or reload. The following snippet creates an inet filter table that blocks a hostile subnet, allows established connections, and permits SSH and web traffic:

table inet filter {
  set blocklist {
    type ipv4_addr
    flags interval
    elements = { 192.0.2.0/24, 198.51.100.14 }
  }

  chain input {
    type filter hook input priority 0; policy drop;
    ct state established,related accept
    iif "lo" accept
    ip saddr @blocklist drop
    tcp dport { 22, 80, 443 } accept
  }
}

For quick ad-hoc changes on a live host, you can also append a rule directly from the shell, such as nft add rule inet filter input ip saddr 203.0.113.0/24 drop.

What matters when choosing a server or hosting

When provisioning virtual private servers or dedicated hardware, verify that the provider supplies a standard upstream Linux kernel with nf_tables modules enabled. Container-based VPS platforms using older shared kernels sometimes restrict netfilter capabilities or lack support for advanced features like flowtables and dynamic sets. If you plan to run high-throughput edge routers, DDoS mitigation appliances, or heavily loaded Kubernetes nodes, choose dedicated hardware or KVM-based instances with full kernel control so you can tune connection tracking tables and offload packet forwarding.

Common mistakes

  • Mixing iptables and nftables backends: Running legacy iptables-legacy rules alongside native nft rules creates parallel hooks that evaluate packets independently, causing unexpected drops or bypassed restrictions.
  • Using incremental CLI commands in scripts: Executing hundreds of individual nft add rule calls sequentially defeats atomic updates and slows down initialization compared to loading a single file with nft -f.
  • Forgetting loopback and established traffic: Setting a default drop policy on the input chain without explicitly accepting lo and established,related states breaks local inter-process communication and active SSH sessions.

FAQ

Is nftables enabled by default on modern Linux distributions?

Yes. Major distributions including Debian, Ubuntu, Red Hat Enterprise Linux, and Fedora use nftables as their default packet-filtering backend, often providing an iptables-nft translation layer for older tools.

Can existing iptables rules be migrated automatically?

You can convert existing rule files using the iptables-restore-translate and ip6tables-restore-translate utilities, which output equivalent nftables syntax for review before deployment.

How does nftables interact with higher-level firewall managers?

Tools such as firewalld, UFW, and Docker configure nftables under the hood. When using these managers, avoid editing raw nftables chains manually unless you isolate custom rules inside dedicated tables with clear hook priorities.

All glossary terms

Glossary

Related terms

Full glossary

New guides every week.

A digest of the best pieces on servers, VPN and self-hosted software. No ads, no spam.

1 email a weekOne-click unsubscribeRU · EN
Only slipjar.app articles, nothing else.