Fact-checked by Grok 2 weeks ago

nftables

nftables is a subsystem of the 's Netfilter project that provides a modern framework for packet classification, filtering, (), and other packet mangling operations, serving as the successor to the older , ip6tables, arptables, and ebtables utilities. Introduced in Linux kernel version 3.13, released on January 19, 2014, nftables aims to offer greater flexibility, performance, and simplicity in managing rules compared to its predecessors. At its core, nftables employs a network-specific that compiles user-defined rules into bytecode via the , allowing for efficient in-kernel execution and reducing the codebase size by shifting much of the logic to userspace tools. Key components include tables, which act as namespaces for organizing rules; chains, which define processing paths with hooks like prerouting, input, forward, output, and postrouting; and rules, which specify matching criteria and actions such as accept, drop, or log. Additional structures like sets and maps enable dynamic, efficient lookups for addresses, ports, and other elements, supporting features such as and tracking integration. nftables introduces a unified syntax that works consistently across address families (e.g., ip for IPv4, ip6 for , inet for both, arp for ), eliminating the need for protocol-specific commands and simplifying configuration. The primary userspace tool, nft, allows administrators to add, list, and flush rulesets, with configurations typically stored in files like /etc/nftables.conf and loaded via services in modern distributions. It also supports advanced capabilities like flow tables for accelerating in routers by caching flows and bypassing unnecessary hooks, as well as tools such as nftrace for rule traversal. Widely adopted in enterprise environments, nftables has become the default firewall backend in distributions like 8 and 20.10 onward, with migration tools like iptables-restore-translate easing the transition from legacy systems. Its design emphasizes atomic updates to rulesets, ensuring consistency during changes, and provides a API for integration with third-party applications.

Introduction

Overview

nftables is a packet classification and filtering subsystem within the , developed as part of the Netfilter project to succeed the legacy framework. It provides a unified configuration interface for defining rules that handle network packet processing, including classification, filtering, and manipulation across various protocol families such as IPv4, , , and . This framework replaces the disparate tools like , ip6tables, arptables, and ebtables with a single, more flexible syntax, enabling efficient management of complex policies. The core purpose of nftables is to allow system administrators to specify rules for incoming, outgoing, and forwarded network traffic, thereby enforcing security policies such as , (NAT), and packet mangling. It integrates directly with the kernel's Netfilter hooks, which are predefined points in the network stack where packets can be inspected and modified before routing decisions are made. This integration ensures low-overhead processing by leveraging existing Netfilter components like connection tracking and logging. nftables has been available in the Linux kernel since 3.13, released in 2014, and is now the recommended modern tool for configuration in contemporary distributions. Its adoption reflects a shift toward more scalable and performant mechanisms within the broader Netfilter ecosystem.

Key Concepts

nftables organizes its packet filtering and classification rules into a hierarchical structure beginning with tables, which serve as top-level containers for chains, sets, maps, flowtables, and other stateful objects. Each table is identified by a unique name and must belong to a specific protocol family, such as for IPv4 traffic, ip6 for IPv6 traffic, or inet for handling both IPv4 and IPv6 traffic simultaneously. This family-based organization allows rules to be scoped to particular network protocols, enabling efficient management of diverse traffic types without overlap. Chains within nftables are sequences of rules contained inside tables and attached to specific points in the network packet processing pipeline, known as Netfilter hooks. Base chains are directly registered with these hooks—such as prerouting for incoming packets before routing decisions or input for packets destined to local processes—while regular chains are user-defined and invoked only via jumps from base chains. Each chain specifies a type (e.g., filter for packet acceptance or dropping, nat for address translation), a hook point, and a priority to determine processing order among multiple chains at the same hook. Chains also have a default policy, typically accept or drop, applied to packets that reach the end without matching any rule. Rules form the core of nftables configuration, residing within chains and consisting of match expressions that evaluate packet attributes followed by verdict statements that dictate actions. Match expressions filter based on criteria like source IP address (e.g., ip saddr 192.168.1.0/24), destination port (e.g., tcp dport 80), or other protocol fields, with multiple expressions combined logically from left to right until a verdict is reached. Verdicts include accept to allow the packet to proceed, drop to silently discard it, or more advanced options like jump to another chain; these actions terminate rule evaluation and influence the packet's fate in the Netfilter pipeline. Sets in nftables provide an efficient way to handle unordered collections of matchable elements, such as addresses or , stored in optimized data structures like hash tables for fast lookups. Named sets can be dynamically updated and referenced in rules (e.g., ip saddr @blacklist , where @blacklist contains blocked addresses), while anonymous sets are inline and non-updatable. Complementing sets, maps function as key-value stores for dynamic matching, associating packet fields (e.g., destination ) with action values (e.g., 22 to accept, 23 to via tcp dport vmap { 22: accept, 23: }). Both sets and maps enhance scalability by reducing rule duplication and supporting runtime modifications without reloading entire rulesets.

History and Development

Origins and Design Goals

nftables was developed to address the shortcomings of the existing framework, which had fragmented tools for different families, such as for IPv4, ip6tables for , arptables for , and ebtables for Ethernet bridging. These separate tools led to significant code duplication in the , with similar extensions and protocol handling repeated across families, complicating maintenance and scalability. Additionally, required atomic replacement of entire rulesets for updates, causing performance bottlenecks in dynamic environments, and its was inconsistent and complex, making configuration error-prone for large-scale deployments. The primary design goals, spearheaded by Pablo Neira Ayuso, focused on creating a unified packet filtering with a single userspace binary called nft to simplify configuration across all protocol families. This approach aimed to shift much of the intelligence to userspace while keeping the kernel component lightweight through a simple for packet classification. Performance improvements were targeted via native support for advanced data structures like sets and maps, enabling efficient handling of large rulesets without linear traversal, and providing a more flexible, programmable interface inspired by concepts like BPF. The was envisioned to support modern networking needs, such as dynamic updates for cloud environments and reputation systems, without the ABI stability issues posed by ' binary mechanisms. Early development began in 2008 with initial work by Patrick McHardy, who presented an alpha version at the Netfilter Workshop that year, but progress stalled around 2010 due to lack of community involvement. Neira Ayuso restarted the project in 2012–2013, prioritizing integration into the mainline and leveraging funding from organizations like /Astaro to accelerate development, including contributions from participants. A key emphasis was on reusability of the existing Netfilter core components, such as connection tracking, , logging, and low-level hooks, to avoid reinventing foundational infrastructure while introducing the new engine.

Timeline of Releases

The development of nftables began with an initial release by Patrick McHardy on March 18, 2009, but the project saw a significant restart in 2013 under the leadership of Pablo Neira Ayuso, who announced efforts to revive and merge the core code into the mainline. On October 16, 2013, Ayuso submitted the nftables core pull request, leading to its integration into the version 3.13, released on January 19, 2014. This marked the availability of nftables' basic packet filtering framework in the kernel. The initial user-space tools followed with the nftables 0.4 release on December 16, 2014, providing the first stable nft utility for configuration and management. Subsequent milestones included the nftables 0.9 release on June 8, 2018, which introduced enhanced scripting capabilities and additional verdicts such as dynamic set element removal and improved rule processing options. The project reached version 1.0 on August 19, 2021, featuring a stabilized , better performance optimizations, and expanded support for sets and maps to handle complex rule matching more efficiently. In the kernel space, nftables progressed toward replacing legacy modules, with legacy modules maintained for compatibility. By the 2020s, major distributions began deprecating direct usage in favor of the nftables backend, exemplified by 9 in 2022, which marked iptables-nft tools as deprecated to encourage full migration. As of 2025, nftables continues to evolve with the latest user-space release, version 1.1.5 on August 27, 2025, incorporating fixes and compatibility updates. In 6.x series (ongoing through 2025), enhancements focus on improved hardware offloading for flowtables via SmartNIC integration and deeper compatibility for programmable packet processing, enabling higher throughput in networked environments.

Architecture

Tables and Families

In nftables, tables serve as organizational namespaces that group related chains, sets, and maps, providing a structured way to manage policies without inherent semantics of their own. They are created using the command nft add table [family] [name], where the family specifies the context and the name uniquely identifies the table within that family. For example, nft add table inet filter establishes a table named "filter" in the inet , which can then contain subordinate elements like chains. Tables ensure that all components within them—such as chains for rule sequencing—are confined to a single scope, preventing conflicts across different policy areas. Protocol families in nftables define the type of packets the table processes and influence the available hooks and selectors for packet matching. The primary families include ip for IPv4 packets, ip6 for IPv6 packets, and inet as a hybrid that handles both IPv4 and IPv6 traffic in a unified manner, reducing rule duplication by applying the same policies to both protocols. Additional families are arp for IPv4 Address Resolution Protocol packets, bridge for Layer 2 Ethernet packets on bridge devices, and netdev for early ingress or egress filtering before IP processing, supporting any EtherType. The choice of family determines the packet selectors (e.g., IPv4 addresses in ip versus IPv6 in ip6) and the hooks where base chains can be attached, such as prerouting, input, forward, output, postrouting for ip, ip6, and inet, or ingress/egress for netdev. Using the inet family is particularly advantageous for modern networks, as it allows a single set of rules to cover both IP versions without maintaining separate tables. Tables maintain ownership over all their subordinate objects, including chains, named sets for storing match elements like addresses, and maps for key-value associations such as address-to-verdict mappings. For instance, sets are added with nft add set [family] [table] [setname] { type [type]; }, ensuring they are scoped to the table and can be referenced in rules via @setname. Similarly, maps follow the same ownership model, created as nft add map [family] [table] [mapname] { type [keytype] : [valuetype]; }. This hierarchical structure promotes modularity, as deleting a table removes all its contents atomically. To maintain consistency, nftables supports transactions for operations, allowing batches of commands to be applied or rolled back as a unit via files processed with nft -f [filename], ensuring that partial failures do not leave the ruleset in an inconsistent state. can also include flags like dormant to defer evaluation until needed or owner to associate them with a specific , enhancing in dynamic environments. Overall, this design enables efficient organization of complex configurations while aligning with the protocol-specific needs of diverse network traffic.

Chains and Hooks

In nftables, chains serve as containers for rules that process network packets at specific points in the kernel's networking stack. There are two primary types of chains: chains and regular chains. chains are directly attached to Netfilter hooks, allowing them to intercept packets at defined stages of the packet processing pipeline, and must specify a type, , and during creation. Regular chains, in contrast, are user-defined and not directly hooked to the kernel; they are invoked from chains or other regular chains via jump or goto actions to organize complex rule logic. Netfilter hooks represent specific interception points in the kernel's packet journey, enabling nftables to filter, modify, or classify . The standard hooks for IPv4, , and inet families include prerouting (NF_INET_PRE_ROUTING), input (NF_INET_LOCAL_IN), forward (NF_INET_FORWARD), output (NF_INET_LOCAL_OUT), and postrouting (NF_INET_POST_ROUTING). The prerouting occurs immediately upon packet arrival, before any decisions, while input applies to packets destined for the local system after . Forward handles transit packets between interfaces, output processes locally generated packets before , and postrouting finalizes packets just before . The netdev family additionally supports ingress and egress hooks for layer 2 . Base chains attach to these hooks, and multiple base chains on the same are traversed in order of their priority, a signed value where lower numbers indicate higher precedence (e.g., -300 for or 0 for standard filtering). Packet flow in nftables follows the Netfilter architecture's defined traversal order. For incoming packets, processing begins at the prerouting , followed by connection tracking and , then a decision: locally destined packets proceed to the input , while forwarded packets go to the forward . Both paths converge at the postrouting for final adjustments before egress. Outgoing locally generated packets start at the output , undergo , and end at postrouting. If no rule in a base chain matches a packet, the chain's —either accept (default, allowing the packet to continue) or (silently discarding it)—determines the outcome. This structure ensures orderly interception without altering the core kernel networking code. To create a base chain, the nft utility is used with syntax specifying the address family, table, chain name, type (e.g., filter for connection-oriented processing or nat for address translation), hook, priority, and policy. For example, the command nft add chain inet filter_table input_chain { type filter hook input priority 0 \; policy accept \; } establishes a base chain in the inet family attached to the input hook at default filter priority, accepting unmatched packets. Regular chains are simpler, as in nft add chain inet filter_table regular_chain, and reside within tables to scope their rules.

Rules, Matches, and Verdicts

In nftables, rules form the core mechanism for inspecting and processing packets within chains, which serve as ordered containers for these rules. Each rule comprises a sequence of match expressions that evaluate packet attributes—such as headers, , or connection state—followed by one or more statements that dictate the packet's fate if the matches succeed. This structure allows for flexible, composable policies, where multiple matches can be combined logically using operators like (implicit AND) or disjunction (via anonymous sets). For instance, a rule might match packets from a specific range on a particular : ip saddr 192.168.1.0/24 tcp dport 80. Match expressions in nftables target various packet elements to enable precise filtering. Protocol fields from headers, such as source and destination addresses (ip saddr, ip daddr), and details like ports ([tcp](/page/TCP) dport, [udp](/page/UDP) sport) are commonly used for basic filtering. Payload inspection extends to layer-specific data, including Ethernet addresses (ether saddr) or raw byte offsets (@th,0,16 for transport header). Additionally, expressions access kernel-provided information, such as the layer-4 (meta l4proto [tcp](/page/TCP)) or interface indices (meta iif "eth0"). Stateful matching integrates with the connection tracking subsystem via expressions like ct state established,related or ct direction original, allowing rules to consider packet context for more sophisticated behaviors, such as permitting return traffic in established connections. Verdicts represent the terminal or control-flow decisions applied to matching packets, determining whether to allow, block, or redirect processing. Terminal verdicts include accept, which passes the packet and halts further evaluation in the current chain (though subsequent hooks may still process it); drop, which silently discards the packet without notification; reject, which discards the packet while sending an ICMP error message (e.g., port unreachable) to the sender; and queue, which enqueues the packet to userspace for custom handling, requiring an explicit accept or drop response. Non-terminal verdicts like continue proceed to the next rule in the chain, while return exits the current chain and resumes at the calling point (or applies the chain's policy if base). Control-flow verdicts such as jump chainname invoke another chain and return afterward, or goto chainname transfers without returning, enabling modular rule organization. Statements like log prefix "blocked" can precede verdicts to record events without altering flow. Rules are added to chains using the nft add rule command, which specifies the address family (e.g., ip, inet), table, chain, match expressions, and verdict in sequence, such as nft add rule [ip](/page/IP) filter input ip saddr 192.168.1.0/24 accept. By default, rules append to the chain's end, but insert places them at the beginning or a specific index/, ensuring ordered . For updates, nft replace rule enables substitution of existing rules by handle, preventing inconsistent states during modifications and supporting seamless changes in live environments.

Sets and Maps

Sets in nftables are unordered collections of elements that enable efficient bulk matching within rules, allowing multiple values to be grouped and referenced dynamically. Named sets are defined separately from rules and support runtime modifications, making them suitable for scenarios requiring frequent updates without reloading entire rule sets. For instance, a set of allowed IPv4 addresses can be created with the command nft add set ip filter allowed_ips { type ipv4_addr; elements = { 10.0.0.0/8 } }, and referenced in a rule as ip saddr @allowed_ips accept to permit traffic from those sources. Sets can include flags such as dynamic to enable updates from the packet processing path, interval for storing address or port ranges (e.g., 10.0.0.0-10.0.0.255), and timeout for automatic element expiration. Interval sets support auto-merging of adjacent ranges to optimize storage and lookup efficiency. Flag sets, which handle bitmasks for fields like packet marks or flags, allow compact representation of multiple bit combinations within a single set element, facilitating matches on complex flag states without enumerating every . For bitmask operations, sets of type mark or similar can store flag values, enabling rules like meta mark @flag_set accept to match specific bit patterns. Concatenation extends sets to compound keys by combining multiple data types, such as an and port (e.g., set type ipv4_addr . inet_service), which supports fast lookups on tuples like ip saddr . tcp dport @compound_set. This feature, introduced in 4.1, enhances performance for multi-field matching. Maps in nftables function as key-value stores, extending sets by associating data or verdicts with keys for dynamic decision-making. A verdict map, for example, can be defined as nft add map inet filter portmap { type inet_service : verdict; elements = { 22 : accept, 80 : drop } }, and used in a rule like tcp dport @portmap to apply the mapped action based on the destination port. Maps support the same types and flags as sets, including interval and dynamic options, and can output values to packet headers (e.g., for NAT) or counters. Like sets, maps permit concatenation for compound keys, such as ip saddr . tcp sport : ipv4_addr for address translation based on source tuples. The primary benefits of sets and maps lie in their support for runtime additions and deletions via commands like nft add element or nft delete element, avoiding the need to flush and reload rules, which reduces administrative overhead in dynamic environments. In modern kernels (5.3 and later), these structures can be offloaded to on compatible interface cards, accelerating lookups and improving throughput for high-traffic scenarios by shifting processing to specialized . This offload capability, particularly with flowtables, enhances overall efficiency without sacrificing flexibility.

The nft Utility

Command Syntax

The nft command-line tool serves as the primary interface for configuring and inspecting nftables rulesets in the . Its basic syntax follows the structure nft [options] [subcommand] [object] [parameters], where options apply globally, the subcommand specifies the operation, the object identifies the target (such as a table or chain), and parameters provide additional details for the action. This declarative syntax allows users to define rules and objects in a human-readable format, contrasting with the more procedural approach of legacy tools like . Global options modify the behavior of the command across subcommands. Key options include -f or --file to read commands from a specified file (using - for standard input), -i or --interactive to enter an interactive mode for direct command entry, and -j or --json to output results in JSON format for programmatic use. For debugging, the -d or --debug option enables detailed logging at specified levels, such as eval for expression evaluation or netlink for kernel communication traces, helping diagnose configuration issues. Additionally, -c or --check validates syntax and semantics without applying changes to the kernel, aiding in safe testing. Subcommands dictate the core actions performed on nftables objects. Common subcommands encompass add to create new elements like tables, chains, rules, or sets; delete to remove specified objects; list to display configurations such as rulesets or tables; flush to clear contents from rulesets, tables, or chains; and to observe real-time changes to the ruleset via kernel events. These subcommands operate on hierarchical objects, with more specialized variants like create, insert, replace, or reset available for precise control over tables, chains, rules, sets, and maps. Object paths in commands specify the scope and location of operations using the format [family] [table] [chain] [handle], where the family (e.g., ip, ip6, inet, arp, bridge, or netdev; defaults to ip if omitted) denotes the address family, followed by the table name, optional chain name, and handle for exact identification. For instance, ip mytable input targets the input chain in the mytable table for the IPv4 family. Handles, numeric identifiers assigned by the kernel, enable precise manipulation of rules or elements without relying on position, and can be revealed using the -a or --handle option in listing commands. Error handling in nft relies on exit status codes and diagnostic output to indicate issues. The command exits with status 0 on successful execution; status 1 for unspecified errors, including syntax or validation failures; and status 2 for memory allocation problems. Errors, such as invalid syntax or kernel rejection of rules, are reported to standard error, with the debug option providing verbose traces to facilitate troubleshooting. The -c check mode further supports error detection by simulating operations without kernel modifications.

Basic Operations

Basic operations in nftables involve using the nft utility to create, modify, and manage tables, chains, and rules, which form the foundational elements of a firewall configuration. These operations allow administrators to build and adjust packet filtering policies interactively or via scripts, with commands executed directly in the terminal. The syntax follows a consistent pattern: nft [operation] [family] [table] [chain] [statements], where the address family (e.g., ip for IPv4) specifies the protocol domain, and statements define matches or actions. To create a , which serves as a container for and rules, the command nft add table [family] [table-name] is used. For example, to establish an IPv4 table named filter, the following command creates it:
nft add table ip filter
This operation initializes the table without any chains or rules, enabling subsequent additions. Tables must be created before chains can be attached to them. Once a table exists, chains can be added to organize rules by hook points in the network stack. Base chains, which connect to hooks, require specifications for type, , , and optionally a default . The command syntax is nft add chain [family] [table] [chain-name] { type [type] hook [hook] priority [priority] \; policy [policy] \; }. A common example for an input chain with a drop policy is:
nft add chain ip filter input { type filter hook input priority 0 \; policy drop \; }
This creates a chain that processes incoming packets, defaulting to dropping them unless a rule allows passage. Regular chains, lacking hook specifications, can be added for jumping from base chains but are not directly invoked by the . Rules define the logic for matching packets and issuing verdicts, such as accepting or dropping them, and are appended to chains using nft add rule [family] [table] [chain] [match] [verdict]. For instance, to allow incoming traffic from a local subnet:
nft add rule ip filter input ip saddr 192.168.1.0/24 accept
This rule matches packets with source IP addresses in the 192.168.1.0/24 range and accepts them. To insert a rule at a specific position, such as the beginning of the chain, use nft insert rule instead of add rule, which prepends the rule:
nft insert rule ip filter input ip saddr 192.168.1.0/24 accept
Rules can reference handles for precise management, obtained via nft list ruleset. Deleting elements ensures configurations remain current and efficient. To remove a specific , identify its (a unique numeric identifier) and use nft delete rule [family] [table] [chain] handle [handle-number]. For example:
nft delete rule ip filter input handle 5
This deletes the rule with handle 5 from the input . To clear all rules from a without removing the chain itself, employ nft flush chain [family] [table] [chain]:
nft flush chain ip filter input
Flushing resets the chain to its initial state, preserving the default . Configurations are typically persisted by exporting the ruleset to a file and reloading it as needed. To save the active ruleset, redirect the output of nft list ruleset to a file, such as:
nft list ruleset > /etc/nftables.conf
This captures the entire configuration in a human-readable format compatible with nft syntax. To load a saved ruleset, use nft -f [filename]:
nft -f /etc/nftables.conf
This command applies the rules from the file, overwriting the current ruleset; it is commonly invoked during system boot via service scripts.

Monitoring and Listing

nftables provides several commands for inspecting the current state of rulesets, including tables, chains, and rules, allowing administrators to verify configurations and track packet processing. The nft list tables [family] command displays all tables defined for a specified address family, such as ip or inet, offering an overview of the organized structure of firewall policies. To examine the full contents of a table, including its chains and rules, the nft list table [family] table command is used, for example, nft list table ip filter to show the standard input, output, and forward chains in the IPv4 filter table. Similarly, nft list chain [family] table chain lists the rules within a specific chain, such as nft list chain ip filter input, which includes details on matches, verdicts, and associated counters. Rules displayed in listings often include byte and packet counters, which accumulate on matched traffic to aid in performance analysis and troubleshooting. These counters appear in the output as packets X bytes Y, where X and Y represent the counts since the last reset. To zero these counters for a fresh measurement period, the nft reset counters [family] [table [chain]] command is employed; for instance, nft reset counters [ip](/page/IP) [filter](/page/Filter) input resets only the input chain counters, while omitting arguments resets all counters system-wide. For real-time observation of nftables activity, the monitoring subcommands enable tracking of dynamic changes and packet flows. The nft monitor trace command captures packet traces, showing the path through rules and chains where matches occur, provided the meta nftrace set 1 expression is included in relevant rules to enable tracing. This is particularly useful for debugging why packets are accepted, dropped, or altered, as traces reveal the exact rule hit and verdict applied. Complementing this, nft monitor events listens for notifications on ruleset modifications, such as additions or deletions of tables, chains, or rules, with options to filter by family or table for targeted output. Output from listing and monitoring commands can be customized for different use cases, enhancing readability or integration with scripts. The -n option produces numeric output, displaying addresses, ports, and protocols without hostname or service name resolution, which speeds up processing in automated environments. For programmatic handling, the -j flag outputs in format, enabling parsing by tools or applications, as in nft -j list ruleset. Additionally, -a includes numerical handles for each object, visible in listings like nft -a list chain ip filter input, which are essential for precise modifications or deletions in scripting workflows.

Configuration Examples

Simple Firewall Setup

A simple firewall setup with nftables for a standalone begins by creating an inet , which supports both IPv4 and protocols, to organize the ruleset. Base chains are then attached to the , and forward hooks. The chain uses a default drop policy to deny unsolicited incoming traffic, enhancing security for the , while the chain uses accept to allow all outgoing traffic. The forward chain has a drop policy to prevent unless explicitly allowed, with a rule restricting to local networks. Essential rules are added to permit traffic, established or related connections, and access to common services like SSH. To implement this configuration, start by flushing any existing ruleset and creating the table:
nft flush ruleset
nft add table inet [filter](/page/Filter)
Next, define the chains. The input chain processes incoming packets to the host:
nft add chain inet [filter](/page/Filter) input { type [filter](/page/Filter) hook input [priority](/page/Priority) 0; [policy](/page/Policy) [drop](/page/Drop); }
The output chain handles outgoing packets from the host:
nft add chain inet [filter](/page/Filter) output { type [filter](/page/Filter) hook output [priority](/page/Priority) 0; [policy](/page/Policy) accept; }
The forward chain manages packets routed through the host, assuming is enabled:
nft add chain inet filter forward { type filter hook forward priority 0; policy drop; }
These chains reference the hook points in the network stack, where the 0 ensures standard processing order. Add rules to the input for essential allowances. Permit all loopback traffic to allow local communications:
nft add rule inet filter input iif lo accept
Allow packets belonging to established or related connections to maintain ongoing sessions:
nft add rule inet filter input ct state established,related accept
Enable incoming SSH connections on port 22 for remote administration:
nft add rule inet filter input tcp dport 22 accept
These rules use interface matching (iif), connection tracking (ct state), and port matching (tcp dport) to selectively accept traffic. For the forward chain, add rules to drop packets exiting on the primary interface (e.g., eth0) destined for non-local networks, preventing unintended routing to external addresses. For IPv4:
nft add rule inet [filter](/page/Filter) forward oif eth0 ip daddr != 192.168.0.0/16 drop
For (assuming ULA fd00::/8 as local):
nft add rule inet [filter](/page/Filter) forward oif eth0 ip6 daddr != fd00::/8 drop
These use output matching (oif) and negated destination (ip daddr != or ip6 daddr !=) to enforce local-only forwarding. To make the persistent across reboots, the ruleset to a and enable the nftables service. First, generate the file:
nft list ruleset > /etc/nftables.conf
The resulting /etc/nftables.conf will contain the full ruleset in a loadable format, such as:
table inet [filter](/page/Filter) {
    chain input {
        type [filter](/page/Filter) hook input priority [filter](/page/Filter); policy drop;
        iif "lo" accept
        ct state { established, related } accept
        tcp dport 22 accept
    }
    chain output {
        type [filter](/page/Filter) hook output priority [filter](/page/Filter); policy accept;
    }
    chain forward {
        type [filter](/page/Filter) hook forward priority [filter](/page/Filter); policy drop;
        oif "eth0" ip daddr != 192.168.0.0/16 drop
        oif "eth0" ip6 daddr != fd00::/8 drop
    }
}
Then, enable and start the service using :
systemctl enable nftables
systemctl start nftables
This ensures the rules load automatically on boot via the service unit.

Advanced Features

nftables supports advanced configurations that enhance scalability and dynamism in packet filtering through the use of sets and maps for efficient matching and decision-making. Sets allow for the creation of dynamic collections of elements, such as addresses in whitelists, which can be referenced in rules without modifying the rule set itself. For instance, a set can be defined as follows:
nft add table ip filter
nft add set ip filter whitelist { type ipv4_addr; }
Elements are populated using the add element command, enabling runtime additions like nft add element ip filter whitelist { 192.168.1.1, 192.168.1.2 }. These sets are then referenced in rules with the @ syntax, such as nft add rule ip filter input ip saddr @whitelist accept, allowing whitelisted IPs to bypass further filtering. Dynamic updates are performed via nft add element ip filter whitelist { 10.0.0.5 }, supporting real-time adjustments without rule reloading. Verdict maps extend this capability by associating packet attributes, like ports, with actions or jumps, facilitating port-based enforcement. A named verdict map is declared with nft add map ip [filter](/page/Filter) portmap { type inet_service : [verdict](/page/Verdict); }, where keys are ports and values are . Elements are added as nft add element ip [filter](/page/Filter) portmap { 80 : accept, 22 : [jump](/page/Jump) ssh[chain](/page/Chain) }, mapping HTTP traffic to acceptance and SSH to a dedicated . For more granular control, concatenation enables tuple matching since Linux kernel 4.1, such as declaring nft add map ip [filter](/page/Filter) tuplemap { type ipv4_addr . inet_service : [verdict](/page/Verdict); } (CIDR support since kernel 5.6), with rule nft add rule ip [filter](/page/Filter) input ip saddr . tcp dport map @tuplemap and element nft add element ip [filter](/page/Filter) tuplemap { 192.168.1.0/24 . 80 : accept }, combining source IP network and destination port for precise . Logging integrates directly into rules to capture events with customizable prefixes and levels, aiding in intrusion detection and . The statement log prefix "intrusion" level info logs matching packets with the specified prefix at informational severity, as in nft add rule ip filter input tcp dport 22 log prefix "intrusion" level info drop. This logs unauthorized SSH attempts without affecting performance, directing output to the or NFLOG group. Rate limiting prevents abuse through filters embedded in rules, combining with for controlled event capture. The syntax limit rate 5/second burst 10 restricts actions to 5 packets per second with a burst of 10, as in nft add rule ip filter input ip protocol icmp limit rate 5/second burst 10 log prefix "icmp-flood" level info drop. This mitigates denial-of-service attempts by accepting initial bursts while throttling sustained traffic. Integration with kernel features like , tracking, and acceleration broadens nftables' applicability. For , masquerading dynamically alters source IPs using the outbound interface address, configured as nft add [table](/page/Table) nat; nft add [chain](/page/Chain) nat postrouting { type nat hook postrouting [priority](/page/Priority) 100; }; nft add [rule](/page/Rule) nat postrouting oifname "eth0" masquerade. Conntrack helpers extend tracking for protocols like FTP or , defined with nft 'add ct helper ftp { type "ftp" protocol [tcp](/page/TCP); }', enabling proper handling of related . Since 5.1, offload supports flowtable acceleration, where nft add flowtable inet myft { hook ingress [priority](/page/Priority) 0; devices = { eth0 }; } offloads established flows to for reduced CPU overhead. examples include offloading to Mellanox ConnectX-5 NICs via switchdev, adding flags offload; to flowtables for line-rate forwarding of up to 100 Gbps.

Comparison with iptables

Structural Differences

nftables represents a significant architectural shift from iptables by adopting a unified framework that consolidates packet filtering, NAT, and other network processing into a single tool and syntax. Unlike iptables, which requires distinct binaries—such as iptables for IPv4, ip6tables for IPv6, arptables for ARP, and ebtables for Ethernet bridging—nftables utilizes the sole nft utility to manage rules across all supported address families, including ip, ip6, inet, arp, bridge, and netdev. This unification eliminates the fragmentation inherent in iptables, where protocol-specific tools lead to inconsistent syntax and duplicated functionality. The organizational structure of nftables further diverges from through its use of flexible, user-defined tables and chains. In nftables, tables serve as namespaces containing chains, sets, and other objects, with no predefined tables like iptables' filter, nat, mangle, or raw; administrators create tables explicitly for specific address families. Chains in nftables are entirely user-defined, including base chains that attach to netfilter hooks (e.g., input, output) with customizable priorities, contrasting iptables' reliance on built-in chains such as INPUT, FORWARD, and PREROUTING within each table. This design allows for greater , as chains can be organized hierarchically without rigid, protocol-bound constraints. nftables employs a declarative rule language that enhances expressiveness and modularity compared to iptables' imperative, chain-oriented commands. Rules in nftables consist of left-to-right evaluated expressions and verdicts, supporting advanced constructs like references to sets (e.g., ip daddr @allowed_hosts accept) for dynamic matching without separate extensions. In contrast, iptables uses verbose, match-action pairs specific to chains and requires tools like ipset for similar bulk operations, resulting in less modular and more repetitive configurations. This declarative approach in nftables facilitates complex logic, such as verdict maps, in a concise manner. To support legacy systems, nftables includes an introduced in 3.13, which translates traditional commands into native nftables rulesets via the nf_tables backend. This layer enables seamless execution of iptables syntax through tools like iptables-nft, preserving while encouraging migration to the unified nftables structure.

Performance and Efficiency

nftables achieves efficiency gains over primarily through its single-pass evaluation mechanism, which processes packets in a unified manner across chains and tables, avoiding the multiple table traversals required in where packets are routed through separate , , and mangle tables sequentially. This design reduces processing overhead by compiling rules into an optimized kernel-space representation, minimizing redundant checks and context switches. Additionally, nftables minimizes kernel-userspace data copies by using a streamlined ABI that batches rule updates and leverages efficient communication, leading to lower latency in rule management compared to ' legacy interface. At the core of nftables' performance are its advanced data structures, including hash tables for sets and maps, which enable average O(1) lookup times for matching packet attributes against large collections of elements. Unlike ' linear chain traversal, these structures allow nftables to handle expansive rulesets—such as those exceeding 10,000 rules—with low CPU overhead, maintaining efficient under load as nftables scales better than . This scalability is particularly beneficial for scenarios involving frequent or matching, where nftables maintains consistent performance without the exponential degradation seen in ' custom chain jumps. Benchmarks demonstrate nftables' advantages in high-traffic environments, with studies showing slightly lower or comparable to iptables for large frame sizes (e.g., 1024 bytes or more) and modest rule counts (under 100 rules), though results vary by —nftables can exhibit higher for small frames (64-128 bytes) and very large rulesets (over 1,000 rules) using linear lookups. In throughput tests at 1 Gbps+ speeds, nftables sustains near-linear performance scaling with rule complexity, achieving better efficiency than in scenarios like multi-port matching or chain-heavy setups, where nftables scales more effectively without proportional performance drops due to sequential processing. For indexed structures, the two frameworks perform nearly identically, highlighting nftables' edge in optimized deployments. As of 2025, integrations like ' nftables mode for kube-proxy demonstrate continued performance improvements over in production environments. nftables further enhances efficiency through integration with for hardware offloading to NICs, allowing compatible network interface cards to execute rules in hardware, bypassing kernel processing for eligible flows and reducing CPU load in high-throughput environments like data centers. Despite these strengths, nftables has limitations, including initial setup overhead for complex maps due to the time required for compilation and backend selection, which can delay in dynamic environments. Dynamic sets also incur higher usage than static rules in , as tables and trees consume additional resources for elements with timeouts or frequent updates, though this is tunable via flags like flags interval to balance performance and footprint.

Adoption and Integration

In Linux Distributions

In Red Hat Enterprise Linux (RHEL) 8, released in 2019, nftables became the default backend for the service, replacing the previous -based implementation to leverage nftables' improved performance and flexibility. This shift applies similarly to downstream distributions like and , where nftables is packaged in the base repositories and integrated as the standard netfilter framework. Red Hat provides migration tools and guides, such as the iptables-restore-translate command, to convert legacy rulesets to nftables syntax during upgrades, ensuring compatibility for existing configurations. In , the nftables package has been available since version 8 (Jessie) in 2015, shortly after its upstream introduction, and is maintained in the main repository for easy installation via apt. , building on Debian, includes nftables since 14.04 (Trusty Tahr) in 2014, with the (ufw) frontend adopting nftables as its default backend starting in 21.10 (Impish ) and continuing in 22.04 LTS (Jammy ) and later releases. also supports with its nftables backend enabled by default in recent versions, allowing users to choose between ufw or for nftables management. The nftables.service unit is provided in both distributions for enabling persistent rule loading at boot, typically via systemctl enable nftables.service after installing the package. Arch Linux includes nftables as an official package in its extra repository, making it readily available for installation and considered a core component of the system's networking stack. The distribution encourages manual configuration using the nft command-line tool, with rules stored in /etc/nftables.conf for simplicity and direct control, rather than relying on higher-level frontends. Integration with ensures persistence through the nftables.service unit, which loads the on startup when enabled. openSUSE has adopted nftables as the backend for firewalld since Leap 15.4 (released in 2022), with Tumbleweed using it by default for dynamic firewall management. Gentoo provides nftables as the recommended successor to iptables, available via Portage, and recent kernel configurations (such as in 6.17) disable legacy iptables by default in favor of nftables compatibility. By 2025, nftables has achieved widespread adoption across major Linux distributions, with most deprecating or phasing out iptables in favor of nftables as the primary firewall framework, driven by its superior syntax and efficiency. In Linux kernel series 6.x and later, new netfilter features are developed primarily for nftables, with iptables supported through compatibility layers like iptables-nft.

Tools and Interfaces

Several higher-level front-ends simplify nftables management by providing abstracted interfaces for common firewall configurations. , a dynamic firewall management tool, has utilized nftables as its backend since version 0.6.0, enabling zone-based rule application and runtime changes without service restarts. , a user-friendly frontend originally designed for , added support for nftables in recent versions, allowing it to manage nftables rulesets on modern distributions like 22.04 and later. Graphical interfaces offer visual tools for nftables configuration, often layered over front-ends like . Firewall-config, the GNOME graphical frontend for , provides an intuitive interface for defining zones, services, and rules, leveraging nftables under the hood for backend enforcement on desktop environments. For more direct nftables interaction, limited options exist. Shorewall and Shorewall6, configuration tools for iptables-based firewalls, do not yet fully support an nftables mode, though community discussions explore potential migrations. Programmatic access to nftables is facilitated through libraries and automation integrations. The libnftables C library offers a high-level for interacting with the nftables interface, enabling applications to create, modify, and query rules programmatically without invoking the nft command-line tool. bindings, provided by the python3-nftables package, wrap libnftables to allow scripting nftables configurations in , supporting tasks like dynamic rule generation. Configuration management tools integrate nftables via dedicated modules: the Ansible nftables collection uses python3-nftables to automate deployments across hosts, while the Puppet nftables module generates opinionated nftables configurations for infrastructure-as-code setups. Monitoring nftables involves tools for traffic accounting and metrics export. Nfacct serves as the userspace utility for managing netfilter accounting objects, allowing the creation and querying of counters for packet and byte statistics within nftables rulesets. For observability, nftables integrates with through exporters like nftables-exporter, which scrapes counter data from nftables tables and exposes it in Prometheus format for alerting and visualization in tools like .

References

  1. [1]
    The netfilter.org "nftables" project
    Documentation. You can check out the nftables HOWTO documentation, there is also a manpage. Copyright © 1999-2025 The Netfilter webmasters . Contact webmaster.Missing: firewall | Show results with:firewall
  2. [2]
    Linux_3.13 - Linux Kernel Newbies
    Linux 3.13 was released on Sun, 19 Jan 2014. Summary: This release includes nftables, the successor of iptables, a revamp of the block layer designed for ...
  3. [3]
    Chapter 41. Getting started with nftables | Red Hat Enterprise Linux | 8
    In nftables , tables provide a more flexible way to structure firewall rules and related components. While in iptables , the tables were more rigidly defined ...
  4. [4]
    nftables - Ubuntu security documentation
    nftables is a component in the Linux Netfilter subsystem that provides the most modern framework for defining packet classification and filtering functionality.
  5. [5]
    Netfilter's flowtable infrastructure - The Linux Kernel documentation
    This documentation describes the Netfilter flowtable infrastructure which allows you to define a fastpath through the flowtable datapath.
  6. [6]
    netfilter/iptables project homepage - The netfilter.org project
    nftables is the successor of iptables, it allows for much more flexible, scalable and performance packet classification. This is where all the fancy new ...Iptables project · Projects · About · Documentation about the...
  7. [7]
    Configuring tables - nftables wiki
    ### Summary of Tables in nftables
  8. [8]
    Configuring chains - nftables wiki
    ### Summary of Chains and Attachment to Netfilter Hooks
  9. [9]
    Simple rule management - nftables wiki
    ### Summary of Rules: Match Expressions and Verdicts
  10. [10]
    Sets - nftables wiki
    ### Summary of Introduction to Sets in nftables
  11. [11]
    Maps - nftables wiki
    ### Summary of Maps in nftables
  12. [12]
    [PDF] The nftables tutorial
    Feb 1, 2015 · Pablo Neira Ayuso. <kaber@trash.net> <pablo@netfilter.org>. Netdev 0.1 ... Currently under active development: – ~60% iptables supported ...Missing: history | Show results with:history<|separator|>
  13. [13]
    Nftables reaches 1.0 - LWN.net
    Aug 27, 2021 · The first public nftables release was made by Patrick McHardy in early 2009. At that time, the kernel had a capable packet-filtering subsystem ...Missing: date | Show results with:date
  14. [14]
    nftables - Wikipedia
    On 16 October 2013, Pablo Neira Ayuso submitted a nftables core pull request to the Linux kernel mainline tree. ... Pablo Neira Ayuso: [RFC] back on nf_tables ( ...Missing: early development
  15. [15]
    Releases of the nftables project - Netfilter.org
    Recent nftables releases include: 2025-Aug-27: nftables-1.1.5, 2025-Aug-06: nftables-1.1.4, 2025-Apr-22: nftables-1.1.3.Missing: timeline | Show results with:timeline
  16. [16]
    The ipset and iptables-nft packages have been deprecated
    Jun 13, 2024 · The ipset and iptables-nft packages have been deprecated in RHEL 9. The iptables-nft package contains different tools such as iptables, ip6tables, ebtables and ...Missing: 2020s | Show results with:2020s
  17. [17]
    nftables flowtables hardware offload with ConnectX-5
    Mar 23, 2024 · I'm stuck trying to get hardware offload working - every time I try to add flags offload to the flow table definition I get Error: Could not process rule: ...Missing: enhancements eBPF<|separator|>
  18. [18]
    Man page of NFT - Netfilter.org
    Jun 28, 2023 · nft is the command line tool used to set up, maintain and inspect packet filtering and classification rules in the Linux kernel, in the nftables framework.
  19. [19]
    nft.txt « doc - nftables - nft command line tool
    ### Summary of Tables, Families, Ownership, Chains, Sets, Maps, and Atomic Updates in nftables (from nft.txt)
  20. [20]
    [PDF] The nftables tutorial - people
    nftables: Tables and chains. ○ Tables are containers of chains (with no semantics). – families: ip, ip6, inet, bridge and arp. ○ Chains: list of rules. – Base ...
  21. [21]
    Linux netfilter Hacking HOWTO: Netfilter Architecture
    A module that registers a function must specify the priority of the function within the hook; then when that netfilter hook is called from the core networking ...
  22. [22]
    nft(8) — nftables - Debian Manpages
    nft is the command line tool used to set up, maintain and inspect packet filtering and classification rules in the Linux kernel, in the nftables framework.
  23. [23]
    nftables set of couples { IP/MAC address } - Server Fault
    Mar 7, 2023 · Since Linux kernel 4.1, nftables supports concatenations. This new feature allows you to put two or more selectors together to perform very fast ...Missing: compound | Show results with:compound
  24. [24]
    nftables 1.0.1 release - LWN.net
    Nov 18, 2021 · Hi! The Netfilter project proudly presents: nftables 1.0.1 This release contains new features available up to the Linux kernel 5.16-rc1 ...
  25. [25]
    nft quick reference - nftables wiki - Netfilter.org
    Missing: maps | Show results with:maps
  26. [26]
    nftables - ArchWiki
    ### Simple Firewall Configuration Example for a Standalone Host
  27. [27]
    Limits - nftables wiki
    ### Rate Limiting: 'limit rate 5/second burst 10'
  28. [28]
  29. [29]
    Netfilter's flowtable infrastructure - The Linux Kernel Archives
    This documentation describes the Netfilter flowtable infrastructure which allows you to define a fastpath through the flowtable datapath.
  30. [30]
    Nftables quick howto – To Linux and beyond !
    ### Summary: Nftables vs Iptables
  31. [31]
    ideas - people - Netfilter.org
    Jan 23, 2018 · The kernel components were already merged into mainstream Linux kernel 3.13 ... * which already includes the iptables compatibility layer working ...
  32. [32]
    nftables vs iptables Linux Firewall Setup - zenarmor.com
    Oct 7, 2025 · Introduced in kernel version 3.13 (2014), nftables is the new firewall framework for Linux that is meant to replace iptables. It has a single ...
  33. [33]
    Optimizing iptables-nft large ruleset performance in user space
    Apr 27, 2020 · Lean how to optimize iptables-nft performance when using large rulesets by configuring the kernel cache, complete with test benchmark ...
  34. [34]
    Benchmarking nftables - Red Hat Developer
    Apr 11, 2017 · While iptables performance suffers quite linearly with number of custom chains, nftables performance scales perfectly. Here, nftables even ...The First Test · Matching Multiple Ports · Measuring Chain Jumps
  35. [35]
    [PDF] latency and throughput comparison between iptables and nftables at ...
    Apr 8, 2018 · This project compared latency and throughput performance of both firewalls with ten different rule-set sizes and seven different frame sizes ...
  36. [36]
    8.0 Release Notes | Red Hat Enterprise Linux | 8
    The firewalld daemon now uses nftables as its default backend. Support for IPVLAN virtual network drivers that enable the network connectivity for multiple ...
  37. [37]
    Migrating my iptables setup to nftables - Red Hat Developer
    Jan 10, 2017 · The goal was to replace the existing iptables setup, ideally without any drawbacks. The following essay will guide you through what I have done in order to ...
  38. [38]
    nftables - Debian Wiki
    nftables is a framework by the Netfilter Project that provides packet filtering, network address translation (NAT) and other packet mangling.Missing: documentation | Show results with:documentation
  39. [39]
    Ubuntu 21.10 switched to nftables, so why is iptables still available?
    Oct 22, 2021 · According to 21.10 release notes: nftables is now the default backend for the firewall. However, having installed Ubuntu 21.10, I can see I ...
  40. [40]
    nftables backend - Firewalld
    Jul 24, 2018 · In firewalld 0.6.0 and later nftables is the default backend - so all you have to do is upgrade. The switch over should be transparent to users.Missing: ubuntu | Show results with:ubuntu
  41. [41]
    Ubuntu 22.04 : Nftables : Enable Service - Server World
    Oct 6, 2022 · On Ubuntu 22.04, nftables is used as the default UFW backend. If you use nftables directly, disable UFW service to avoid that the different ...
  42. [42]
    nftables 1:1.1.5-1 (x86_64) - Arch Linux
    nftables is a Netfilter tables userspace tool. It has dependencies like gmp, jansson, libmnl, libnftnl, ncurses, and readline.<|separator|>
  43. [43]
    nftables systemctl status inactive? - Arch Linux Forums
    Apr 16, 2022 · nftables.service - Netfilter Tables Loaded: loaded (/etc/systemd/system/nftables.service; enabled; vendor preset: disabled) Active: inactive (dead) since Sat ...iptables and nftables on same arch system[SOLVED] nftables deactivates itself - Arch Linux ForumsMore results from bbs.archlinux.org
  44. [44]
    What are the most essential Linux firewalls in 2025 and how do they ...
    Jul 23, 2025 · Is iptables still supported? While still available, iptables is being phased out in favor of nftables in many distributions as of 2025. Join ...Why Firewalls Matter In 2025 · Top Linux Firewall Tools In... · Nftables: The Future Of...<|separator|>
  45. [45]
  46. [46]
    Firewall - Ubuntu security documentation
    ufw is a firewall framework that acts as a frontend for both iptables and nftables . Details on configuring ufw can be found in the Ubuntu Server documentation.
  47. [47]
    Implement nftables support - Issue · shorewall/code - GitLab
    Dec 19, 2019 · Shorewall should provide support for nftables in addition to the current iptables support. Tom offered the following suggestion via email:
  48. [48]
    Debian -- Details of package python3-nftables in sid
    nftables/libnftables python3 module. The libnftables library provides high level semantics to interact with the nftables framework by the Netfilter project.Missing: C ansible puppet
  49. [49]
    Ansible modules to manage NFTables via libnftables - GitHub
    The ansible-modules of this collection use the python3-nftables module to interact with nftables. You can either install it using your package manager.Missing: C bindings puppet
  50. [50]
    The netfilter.org "nfacct" project
    nfacct is the command line tool to create/retrieve/delete accounting objects. Dependencies nfacct requires libnetfilter_acct, libmnl and a kernel that features ...Missing: monitoring prometheus