History
Rusty Russell started the ''netfilter/iptables project'' in 1998; he had also authored the project's predecessor, ipchains. As the project grew, he founded the ''Netfilter Core Team'' (or simply ''coreteam'') in 1999. The software they produced (called ''netfilter'' hereafter) uses theUserspace utility programs
iptables
The kernel modules namedip_tables
, ip6_tables
, arp_tables
(the underscore is part of the name), and ebtables
comprise the legacy packet filtering portion of the Netfilter hook system. They provide a table-based system for defining firewall rules that can filter or transform packets. The tables can be administered through the user-space tools iptables
, ip6tables
, arptables
, and ebtables
. Notice that although both the kernel modules and userspace utilities have similar names, each of them is a different entity with different functionality.
Each table is actually its own hook, and each table was introduced to serve a specific purpose. As far as Netfilter is concerned, it runs a particular table in a specific order with respect to other tables. Any table can call itself and it also can execute its own rules, which enables possibilities for additional processing and iteration.
Rules are organized into chains, or in other words, "chains of rules". These chains are named with predefined titles, including INPUT
, OUTPUT
and FORWARD
. These chain titles help describe the origin in the Netfilter stack. Packet reception, for example, falls into PREROUTING
, while the INPUT
represents locally delivered data, and forwarded traffic falls into the FORWARD
chain. Locally generated output passes through the OUTPUT
chain, and packets to be sent out are in POSTROUTING
chain.
Netfilter modules not organized into tables (see below) are capable of checking for the origin to select their mode of operation.
; iptable_raw
module
: When loaded, registers a hook that will be called before any other Netfilter hook. It provides a table called ''raw'' that can be used to filter packets before they reach more memory-demanding operations such as Connection Tracking.
;iptable_mangle
module
: Registers a hook and ''mangle'' table to run after Connection Tracking (see below) (but still before any other table), so that modifications can be made to the packet. This enables additional modifications by rules that follow, such as NAT or further filtering.
; iptable_nat
module
: Registers two hooks: Destination Network Address Translation-based transformations ("DNAT") are applied before the filter hook, Source Network Address Translation-based transformations ("SNAT") are applied afterwards. The ''network address translation'' table (or "nat") that is made available to iptables is merely a "configuration database" for iptable_filter
module
: Registers the ''filter'' table, used for general-purpose filtering (firewalling).
; security_filter
module
: Used for Mandatory Access Control (MAC) networking rules, such as those enabled by the SECMARK
and CONNSECMARK
targets. (These so-called "targets" refer to Security-Enhanced Linux markers.) Mandatory Access Control is implemented by Linux Security Modules such as SELinux. The security table is called following the call of the filter table, allowing any Discretionary Access Control (DAC) rules in the filter table to take effect before any MAC rules. This table provides the following built-in chains: INPUT
(for packets coming into the computer itself), OUTPUT
(for altering locally-generated packets before routing), and FORWARD
(for altering packets being routed through the computer).
nftables
nftables is the new packet-filtering portion of Netfilter.nft
is the new userspace utility that replaces iptables
, ip6tables
, arptables
and ebtables
.
nftables kernel engine adds a simple iptables
are simplification of the Linux kernel ABI, reduction of code duplication, improved Packet defragmentation
Thenf_defrag_ipv4
module will defragment IPv4 packets before they reach Netfilter's connection tracking (nf_conntrack_ipv4
module). This is necessary for the in-kernel connection tracking and NAT helper modules (which are a form of "mini- ALGs") that only work reliably on entire packets, not necessarily on fragments.
The IPv6 defragmenter is not a module in its own right, but is integrated into the nf_conntrack_ipv6
module.
Connection tracking
One of the important features built on top of the Netfilter framework is connection tracking. Connection tracking allows the kernel to keep track of all logical network connections oriptables
can use this information to act as a stateful firewall.
The connection state however is completely independent of any upper-level state, such as TCP's or SCTP's state. Part of the reason for this is that when merely forwarding packets, i.e. no local delivery, the TCP engine may not necessarily be invoked at all. Even connectionless-mode transmissions such as UDP, conntrack
.
iptables
can make use of checking the connection's information such as states, statuses and more to make packet filtering rules more powerful and easier to manage. The most common states are:
; NEW
: trying to create a new connection
; ESTABLISHED
: part of an already-existing connection
; RELATED
: assigned to a packet that is initiating a new connection and which has been "expected"; the aforementioned mini-ALGs set up these expectations, for example, when the nf_conntrack_ftp
module sees an FTP "PASV
" command
; INVALID
: the packet was found to be invalid, e.g. it would not adhere to the TCP state diagram
; UNTRACKED
: a special state that can be assigned by the administrator to bypass connection tracking for a particular packet (see raw table, above).
A normal example would be that the first packet the conntrack subsystem sees will be classified "new", the reply would be classified "established" and an ICMP error would be "related". An ICMP error packet which did not match any known connection would be "invalid".
Connection tracking helpers
Through the use of plugin modules, connection tracking can be given knowledge of application-layer protocols and thus understand that two or more distinct connections are "related". For example, consider the FTP protocol. A control connection is established, but whenever data is transferred, a separate connection is established to transfer it. When thenf_conntrack_ftp
module is loaded, the first packet of an FTP data connection will be classified as "related" instead of "new", as it is logically part of an existing connection.
The helpers only inspect one packet at a time, so if vital information for connection tracking is split across two packets, either due to PASV
with standard segment sizes, so is not dealt with in Netfilter either.
Network address translation
Each connection has a set of ''original addresses'' and ''reply addresses'', which initially start out the same. NAT in Netfilter is implemented by simply changing the reply address, and where desired, port. When packets are received, their connection tuple will also be compared against the reply address pair (and ports). Being fragment-free is also a requirement for NAT. (If need be, IPv4 packets may be refragmented by the normal, non-Netfilter, IPv4 stack.)NAT helpers
Similar to connection tracking helpers, NAT helpers will do a packet inspection and substitute original addresses by reply addresses in the payload.Further Netfilter projects
Though not being kernel modules that make use of Netfilter code directly, the Netfilter project hosts a few more noteworthy software.conntrack-tools
conntrack-tools
is a set of user-space tools for Linux that allow system administrators to interact with the Connection Tracking entries and tables. The package includes the conntrackd
daemon and the command line interface conntrack
. The userspace daemon conntrackd
can be used to enable high availability cluster-based stateful firewalls and collect statistics of the stateful firewall use. The command line interface conntrack
provides a more flexible interface to the connection tracking system than the obsolete /proc/net/nf_conntrack
.
ipset
Unlike other extensions such as Connection Tracking,ipset
is more related to iptables
than it is to the core Netfilter code. ipset
does not make use of Netfilter hooks for instance, but actually provides an iptables
module to match and do minimal modifications (set/clear) to IP sets.
The user-space tool called ipset
is used to set up, maintain and inspect so called "IP sets" in the Linux kernel. An IP set usually contains a set of iptables
rules, but of course may come with a greater memory footprint. Different storage algorithms (for the data structures in memory) are provided in ipset
for the user to select an optimum solution.
Any entry in one set can be bound to another set, allowing for sophisticated matching operations. A set can only be removed (destroyed) if there are no iptables
rules or other sets referring to it.
SYN proxy
SYNPROXY
target makes handling of large SYN
requests to the SYNPROXY
target, connections are not registered within the connection tracking until they reach a validated final ACK
state, freeing up connection tracking from accounting large numbers of potentially invalid connections. This way, huge SYN
floods can be handled in an effective way.
On 3 November 2013, SYN
proxy functionality was merged into the Netfilter, with the release of version 3.12 of the Linux kernel mainline.
ulogd
ulogd
is a user-space daemon to receive and log packets and event notifications from the Netfilter subsystems. ip_tables
can deliver packets via the userspace queueing mechanism to it, and connection tracking can interact with ulogd
to exchange further information about packets or events (such as connection teardown, NAT setup).
Userspace libraries
Netfilter also provides a set of libraries havinglibnetfilter
as a prefix of their names, that can be used to perform different tasks from the userspace. These libraries are released under the GNU GPL version 2. Specifically, they are the following:
; libnetfilter_queue
: allows to perform userspace packet queueing in conjunction with iptables; based on libnfnetlink
; libnetfilter_conntrack
: allows manipulation of connection tracking entries from the userspace; based on libnfnetlink
; libnetfilter_log
: allows collection of log messages generated by iptables; based on libnfnetlink
; libnl-3-netfilter
: allows operations on queues, connection tracking and logs; part of the libnl
project
; libiptc
: allows changes to be performed to the iptables firewall rulesets; it is not based on any 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 oper ...
library, and its API is internally used by the iptables
utilities
; libipset
: allows operations on IP sets; based on libmnl
.
Netfilter workshops
The Netfilter project organizes an annual meeting for developers, which is used to discuss ongoing research and development efforts. The 2018 Netfilter workshop took place in Berlin, Germany, in June 2018.See also
* Berkeley Packet Filter * Geniatech v. McHardy (2018) law suite * IP Virtual Server (IPVS, part of LVS) * ipchains, the predecessor to iptables * ipfw *References
External links
*