nftables is a subsystem of the
Linux kernel
The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
providing filtering and classification of
network packet
In telecommunications and computer networking, a network packet is a formatted unit of Data (computing), data carried by a packet-switched network. A packet consists of control information and user data; the latter is also known as the ''Payload ...
s/datagrams/frames. It has been available since Linux kernel 3.13 released on 19 January 2014.
nftables replaces the legacy
iptables
iptables is a user-space utility program that allows a system administrator to configure the IP packet filter rules of the Linux kernel firewall, implemented as different Netfilter modules. The filters are organized in a set of tables, whi ...
component of
Netfilter. Among the advantages of nftables over iptables is less code duplication and easier extension to new protocols. Among the disadvantages of nftables is that
DPI
DPI may refer to:
Organizations
* Department of Public Information, related to U.N.
*Daffodil Polytechnic Institute, an educational institution of Bangladesh
* Dhaka Polytechnic Institute, an educational institution of Bangladesh
* Disabled Peop ...
that was provided by "iptables string match" like
SNI
In chemistry, Si (substitution nucleophilic internal) refers to a specific, regio-selective but not often encountered reaction mechanism for nucleophilic aliphatic substitution. The name was introduced by Cowdrey et al. in 1937 to label nucleo ...
filtering is not supported.
nftables is configured via the
user-space
A modern computer operating system usually uses virtual memory to provide separate address spaces or regions of a single address space, called user space and kernel space. This separation primarily provides memory protection and hardware protec ...
utility ''nft'', while legacy tools are configured via the utilities ''
iptables
iptables is a user-space utility program that allows a system administrator to configure the IP packet filter rules of the Linux kernel firewall, implemented as different Netfilter modules. The filters are organized in a set of tables, whi ...
'', ''ip6tables'', ''
arptables'' and ''ebtables'' frameworks.
nftables utilizes the building blocks of the
Netfilter infrastructure, such as the existing hooks into the networking stack, connection tracking system, userspace queueing component, and logging subsystem.
nft
Command-line syntax
A command to drop any packets with destination IP address
1.2.3.4
:
nft add rule ip filter output ip daddr 1.2.3.4 drop
Note that the new syntax differs significantly from that of iptables, in which the same rule would be written:
iptables -A OUTPUT -d 1.2.3.4 -j DROP
The new syntax can appear more verbose, but it is also far more flexible. nftables incorporate
advanced data structuressuch as dictionaries, maps and concatenations that do not exist with iptables. Making use of these can significantly reduce the number of chains and rules needed to express a given packet filtering design.
The
iptables-translate
tool can be used to translate many existing iptables rules to equivalent nftables rules.
Debian 10 (Buster), among other
Linux distributions
A Linux distribution, often abbreviated as distro, is an operating system that includes the Linux kernel for its kernel (operating system), kernel functionality. Although the name does not imply distribution (marketing), product distribution pe ...
, uses nftables along with
iptables-translate
as the default packet filtering backend.
History
The project was first publicly presented at Netfilter Workshop 2008 by Patrick McHardy from the Netfilter Core Team. The first preview release of kernel and userspace implementation was given in March 2009. Although the tool has been called "the biggest change to Linux firewalling since the introduction of iptables in 2001", it has received little press attention.
Notable hacker
Fyodor Vaskovich (Gordon Lyon) said that he is "looking forward to its general release in the mainstream
Linux kernel
The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
".
The project stayed in alpha stage, and the official website was removed in 2009. In March 2010, emails from the author on the project mailing lists showed the project was still active and approaching a beta release, but the latter was never shipped officially. In October 2012, Pablo Neira Ayuso proposed a compatibility layer for iptables and announced a possible inclusion of the project into mainstream kernel.
On 16 October 2013, Pablo Neira Ayuso submitted a nftables core
pull request
In software development, distributed version control (also known as distributed revision control) is a form of version control in which the complete codebase, including its full history, is mirrored on every developer's computer. Compared to centr ...
to the
Linux kernel mainline
The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
tree. It was merged into the kernel mainline on 19 January 2014, with the release of Linux kernel version 3.13.
Overview
The nftables kernel engine adds a simple
virtual machine
In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
to the Linux kernel which is able to execute bytecode to inspect a network packet and make decisions on how that packet should be handled. The operations implemented by this virtual machine are intentionally made basic. It can get data from the packet itself, have a look at the associated metadata (inbound interface, for example), and manage connection-tracking data. Arithmetic, bitwise and comparison operators can be used for making decisions based on that data. The virtual machine is also capable of manipulating sets of data (typically, IP addresses), allowing multiple comparison operations to be replaced with a single set lookup.
The above-described organization is contrary to the iptables firewalling code, which has protocol awareness built-in so deeply into the logic that the code has had to be replicated four times—for
IPv4
Internet Protocol version 4 (IPv4) is the first version of the Internet Protocol (IP) as a standalone specification. It is one of the core protocols of standards-based internetworking methods in the Internet and other packet-switched networks. ...
,
IPv6
Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communication protocol, communications protocol that provides an identification and location system for computers on networks and routes traffic ...
,
ARP, and Ethernet
bridging—as the firewall engines are too protocol-specific to be used in a generic manner.
The main advantages of nftables over iptables are the simplification of the Linux kernel
ABI, reduction of
code duplication In computer programming, duplicate code is a sequence of source code that occurs more than once, either within a program or across different programs owned or maintained by the same entity. Duplicate code is generally considered undesirable for a n ...
, improved
error reporting
In computing and computer programming
Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algori ...
, and more efficient execution, storage and incremental changes of filtering rules. Traditionally used , , and (for IPv4, IPv6, ARP and Ethernet bridging, respectively) are intended to be replaced with as a single unified implementation, providing firewall configuration on top of the
in-kernel virtual machine.
nftables also offers an improved userspace API that allows
atomic replacements of one or more firewall rules within a single
Netlink
Netlink is a socket family used for inter-process communication (IPC) between both the kernel and userspace processes, and between different userspace processes, in a way similar to the Unix domain sockets available on certain Unix-like operat ...
transaction. This speeds up firewall configuration changes for setups having large rulesets; it can also help in avoiding race conditions while the rule changes are being executed. nftables also includes compatibility features to ease transition from previous firewalls, command-line utilities to convert rules in the iptables format, and syntax-compatible versions of iptables commands that use the nftables backend.
References
External links
First release of nftables (2009-03-18)Pablo Neira Ayuso: [RFC] back on nf_tables (plus compatibility layer)nftables quick HOWTO* nftables sections i
ArchWikian
Gentoo Wiki*
*
nft_compat extended to support ebtables extensions(merged in Linux kernel 4.0)
Extended and enhanced manual for the nft command line tool
{{Linux kernel
Firewall software
Linux security software
Linux kernel features