![Lead Image © alphaspirit, 123RF.com Lead Image © alphaspirit, 123RF.com](/var/ezflow_site/storage/images/archive/2020/55/linux-nftables-packet-filter/po-25713-123rf-alphaspirit_123rf-mann_mit_lupe_untersucht_ein_notebook__resized.png/170621-1-eng-US/PO-25713-123RF-alphaspirit_123RF-Mann_mit_Lupe_untersucht_ein_Notebook__resized.png_medium.png)
Lead Image © alphaspirit, 123RF.com
Linux nftables packet filter
Screened
The Linux kernel already contains a variety of packet filters, starting with ipfwadm
and followed by ipchains
and iptables
. Kernel 3.13 saw the introduction of nftables [1], which uses the nft
tool to create and manage rules. With the help of its own virtual machine, nftables ensures that rulesets are converted into bytecode, which is then loaded into the kernel. Not only does it improve performance, but it also allows administrators to enable new rules dynamically without having to reload the entire ruleset.
Parts of the old Netfilter framework use nftables, removing the need to develop new hooks, which are nothing more than certain points in the network stack of the Linux kernel at which a packet is inspected and, in the case of a match, one or more actions executed. For this purpose, tables that store chains exist at these hook points. The chains in turn contain the rules.
The way in which the individual packets are now checked against the rules is another new feature of nftables. The classification is now far more sophisticated and elegant than it was in the days of iptables. For example, address families now allow you to process different packages with a single rule. If you wanted to examine IPv4 and IPv6 packets in the past, you not only needed different rules, you even had to load them into the kernel with different tools: iptables
and ip6tables
.
The simple nftables inet
table type includes both IPv4 and IPv6. Now, you can also merge different statements with nftables. With iptables, writing a packet to the log first and then performing another action, such as dropping the packet, was a very roundabout approach that required two rules:
iptables -A INPUT -p tcp --dport 23 -j LOG iptables -A INPUT -p tcp --dport 23 -j DROP
With nftables, this is reduced to a single
...Buy this article as PDF
(incl. VAT)