NFT(8) NFT(8) (NAME) nft - nftables (SYNOPSIS) nft [ -nNscaeSupyjtT ] [ -I directory ] [ -f filename | -i | cmd ...] nft -h nft -v (DESCRIPTION) nft nftables . nf_tables `nf' Netfilter . (OPTIONS) . nft --help . : -h, --help . -v, --version . -V . : -f, --file filename filename. filename - stdin . (include) ( -I/--includepath). -D, --define name=value . -f . -i, --interactive readline. quit EOF ( CTRL-D ) . -I, --includepath directory directory (include). . -c, --check . -o, --optimize . -c . list ruleset : -a, --handle (handle) . -s, --stateless . -t, --terse (sets) . -S, --service etc/services/. -N, --reversedns IP DNS. . -u, --guid UID/GID etc/passwd/ etc/group/. -n, --numeric . -y, --numeric-priority (base chain) . -p, --numeric-protocol . -T, --numeric-time . : -e, --echo add insert replace nft monitor . -j, --json JSON. (schema) libnftables-json(5) . -d, --debug level (). scanner parser eval netlink mnl proto-ctx segtree all . , -d eval,mnl. (INPUT FILE FORMATS) (LEXICAL CONVENTIONS) . (\) . - (;) . (#) (comment) . . (a-z,A-Z) - (a-z,A-Z,0-9) (/) (\) (_) (.) . (") . (INCLUDE FILES) include filename include . -I/--includepath . `./' ( ) / (override) . -I/--includepath nft . -h/--help . (include) (,?,[]) . include . include "/etc/firewall/rules/" . C . (.) include . (SYMBOLIC VARIABLES) define variable = expr undefine variable redefine variable = expr $variable define . (expression) . (scope) . undefine redefine . . define int_if1 = eth0 define int_if2 = eth1 define int_ifs = { $int_if1, $int_if2 } redefine int_if2 = wlan0 undefine int_if2 filter input iif $int_ifs accept (ADDRESS FAMILIES) . (hooks) nftables . ip IPv4. ip6 IPv6. inet (IPv4/IPv6). arp ARP IPv4 ARP . bridge (Bridge) . netdev Netdev (ingress) (egress) . nftables . ip . IPV4/IPV6/INET (IPV4/IPV6/INET ADDRESS FAMILIES) IPv4/IPv6/Inet IPv4 IPv6 . . . IPv4/IPv6/Inet +--------------------+--------------------------------------+ | (Hook) | | +--------------------+--------------------------------------+ |prerouting | | | | | | | | | | | | | prerouting | | | | | | . | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | . | +--------------------+--------------------------------------+ |input | | | | | | | | | | | | | input | | | | | | . | +--------------------+--------------------------------------+ |forward | | | | | | | | | | | | | forward | | | | | | . | +--------------------+--------------------------------------+ |output | | | | | | | | | | | | | | | | output | | | | | | . | +--------------------+--------------------------------------+ |postrouting | | | | | | | | | | | | | postrouting | | | | | | . | +--------------------+--------------------------------------+ |ingress | | | | | | | | | | | | | | | | | | | . | | | | | | | | | | | | ( | | | | | | prerouting) | | | | | | | | | | | | | | | (policing) | | | . | | | Ingress | | | | | | Inet | | | ( | | | . | | | ). | +--------------------+--------------------------------------+ ARP (ARP ADDRESS FAMILY) ARP ARP . (mangle) ARP (clustering) . . ARP +--------------------+-----------------------------+ | (Hook) | | +--------------------+-----------------------------+ |input | | | | | | | | | | | | | | | | input | | | | | | . | +--------------------+-----------------------------+ |output | | | | | | | | | | | | | | | | output | | | | | | . | +--------------------+-----------------------------+ BRIDGE (BRIDGE ADDRESS FAMILY) bridge (bridge) . IPv4/IPv6/Inet . NETDEV (NETDEV ADDRESS FAMILY) Netdev (ingress) (egress) . ethertype ARP VLAN 802.1q VLAN 802.1ad (Q-in-Q) IPv4 IPv6 . . Netdev +--------------------+--------------------------------------+ | (Hook) | | +--------------------+--------------------------------------+ |ingress | | | | | | | | | | | | | | | | | | | . | | | | | | | | | ( tcpdump) | | | tc | | | ingress | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | . | +--------------------+--------------------------------------+ |egress | | | | | | | | | | | | | | | | | | | . | | | | | | | | | | | | tc egress | | | | | | | | | | | | | | | | | | | | | | | | . | +--------------------+--------------------------------------+ ( vxlan) netdev (decapsulated) (tunneled) . (overlay) . netfilter tc (ingress) (egress) () . NAT (mangling) . (redirect) netfilter netfilter . tc netfilter . netfilter . tc netfilter netfilter tc : tc netfilter netfilter . (RULESET) {list | flush} ruleset [family] ruleset . ruleset : list . flush . iptables . list flush . " (ADDRESS FAMILIES)" . list ruleset nft -f . iptables-save iptables-restore nft . (TABLES) {add | create} table [family] table [{ [comment comment ;] [flags flags ;] }] {delete | destroy | list | flush} table [family] table list tables [family] delete table [family] handle handle destroy table [family] handle handle (Tables) . . ip ip6 inet arp bridge netdev . inet (dummy) IPv4/IPv6 . meta expression nfproto (ipv4 ipv6) . ip . add create create . 4. (Table flags) +--------+---------------------------------+ |Flag | | +--------+---------------------------------+ |dormant | | | | | | | | | | ( | | | | | | / | | | unregistered | | | ). | +--------+---------------------------------+ |owner | | | | | | | | | | | | | . | +--------+---------------------------------+ |persist | | | | | | | | | | | | | . | +--------+---------------------------------+ owner . . persist . . # start nft in interactive mode nft --interactive # create a new table. create table inet mytable # add a new base chain: get input packets add chain inet mytable myin { type filter hook input priority filter; } # add a single counter to the chain add rule inet mytable myin counter # disable the table temporarily -- rules are not evaluated anymore add table inet mytable { flags dormant; } # make table active again: add table inet mytable add . delete . destroy . list . flush . (CHAINS) {add | create} chain [family] table chain [{ type type hook hook [DEVICE] priority priority ; [policy policy ;] [comment comment ;] }] {delete | destroy | list | flush} chain [family] table chain list chains [family] [table] delete chain [family] table handle handle destroy chain [family] table handle handle rename chain [family] table chain newname DEVICE := {device DEVICE_NAME | devices = { DEVICE_LIST }} DEVICE_LIST := DEVICE_NAME [, DEVICE_LIST] DEVICE_NAME := string | string* . : (base chains) (regular chains). (networking stack) . VERDICT STATEMENT . add . hook priority . create add . delete . . destroy . . rename . list . flush . type hook priority . 5. (Supported chain types) +-------+---------------+----------------+--------------------------------------------------+ |Type | Families | Hooks | | +-------+---------------+----------------+--------------------------------------------------+ |filter | all | all | | | | | | | | | | | | | | | | . | +-------+---------------+----------------+--------------------------------------------------+ |nat | ip, ip6, inet | prerouting, | | | | | input, output, | | | | | postrouting | (Native Address | | | | | Translation) | | | | | conntrack | | | | | . | | | | | | | | | | | | | | | | | | | | - | | | | | | | | | | conntrack | | | | | | | | | | ( | | | | | NAT). | +-------+---------------+----------------+--------------------------------------------------+ |route | ip, ip6, inet | output | | | | | | | | | | | | | | | | | | | | | (accept) | | | | | | | | | | IP | | | | | | | | | | (route lookup) | | | | | . | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (policy routing) | | | | | nftables | | | | | . | +-------+---------------+----------------+--------------------------------------------------+ ( nat forward route output) : o netdev filter ingress filter egress. DEVICE . o arp input output filter . o inet ingress ( 5.10 ) IPv4 IPv6 ingress netdev . inet prerouting input forward output postrouting ingress . device ingress egress . ingress egress device . devices . (*) (wildcards) DEVICE_NAME . . list hooks . priority hook ( ) . : . . nat -200 priority conntrack NAT . . ( ) . xtables . bridge . . 6. (Standard priority names, family and hook compatibility matrix) +---------+-------+----------------+-------------+ |Name | Value | Families | Hooks | +---------+-------+----------------+-------------+ |raw | -300 | ip, ip6, inet | all | +---------+-------+----------------+-------------+ |mangle | -150 | ip, ip6, inet | all | +---------+-------+----------------+-------------+ |dstnat | -100 | ip, ip6, inet | prerouting | +---------+-------+----------------+-------------+ |filter | 0 | ip, ip6, inet, | all | | | | arp, netdev | | +---------+-------+----------------+-------------+ |security | 50 | ip, ip6, inet | all | +---------+-------+----------------+-------------+ |srcnat | 100 | ip, ip6, inet | postrouting | +---------+-------+----------------+-------------+ 7. bridge (Standard priority names and hook compatibility for the bridge family) +-------+-------+-------------+ |Name | Value | Hooks | +-------+-------+-------------+ |dstnat | -300 | prerouting | +-------+-------+-------------+ |filter | -200 | all | +-------+-------+-------------+ |out | 100 | output | +-------+-------+-------------+ |srcnat | 300 | postrouting | +-------+-------+-------------+ ( ) mangle - 5 -155 . . policy () . accept ( ) drop . (RULES) {add | insert} rule [family] table chain [handle handle | index index] statement ... [comment comment] replace rule [family] table chain handle handle statement ... [comment comment] {delete | reset} rule [family] table chain handle handle destroy rule [family] table chain handle handle reset rules [family] [table [chain]] . ip . : (expressions) (statements). add insert handle () index ( ) . handle index . : . handle . comment (") . : bash \"enable ssh for servers\". add . . insert add . replace add . delete . destroy . reset counter quota. (output) ip. nft add rule filter output ip daddr 192.168.0.0/24 accept # 'ip filter' is assumed # same command, slightly more verbose nft add rule ip filter output ip daddr 192.168.0.0/24 accept inet. # nft -a list ruleset table inet filter { chain input { type filter hook input priority filter; policy accept; ct state established,related accept # handle 4 ip saddr 10.1.1.1 tcp dport ssh accept # handle 5 ... # delete the rule with handle 5 nft delete rule inet filter input handle 5 (OVERALL EVALUATION OF THE RULESET) (ruleset) . o (accept) ICMP sysctl net.ipv{4,6}.conf.*.forwarding net.ipv4.conf.*.rp_filter. . o nftables . . o (hooks) ( " (ADDRESS FAMILIES)" ) (base chain) . o ( jump goto) . . . . o (priorities) . . . o (verdict) accept ( ) . accept . . () drop . accept NAT . o drop ( ) . . drop accept . drop reject . drop ( ) accept (drop) . o accept/drop - ( ). drop ( drop reject) . o jump . . return . ( ) . o goto jump . o return (pop ) . ( goto ) ( ) . o jump/goto/return: o base {jump}-> regular-1 {jump}-> regular-2 regular-2 return jump regular-1 . regular-1 return jump base . o base {jump}-> regular-1 {goto}-> regular-2 regular-2 return jump base . o base {jump}-> regular-1 {jump}-> regular-2 {goto}-> regular-3 regular-3 return jump regular-1 . regular-1 return jump base . o base {jump}-> regular-1 {goto}-> regular-2 {goto}-> regular-3 regular-3 return jump base . o (: accept, drop, jump, goto, return continue) ( reject NAT) ( ). ... counter accept counter ... accept counter . comment . (SETS) nftables . (Anonymous sets) . . . . . nft add rule filter input ip saddr { 10.0.0.0/8, 192.168.0.0/16 } tcp dport { 22, 443 } accept (Named sets) . . @ . . nft add rule filter input ip saddr @allowed_hosts tcp dport @allowed_ports accept allowed_hosts allowed_ports . (syntax) nft . add set [family] table set { type type | typeof expression ; [flags flags ;] [timeout timeout ;] [gc-interval gc-interval ;] [elements = { element[, ...] } ;] [size size ;] [comment comment ;] [policy 'policy ;] [auto-merge ;] } {delete | destroy | list | flush | reset } set [family] table set list sets [family] [table] delete set [family] table handle handle {add | delete | destroy } element [family] table set { element[, ...] } . . . add . . delete . destroy . list . flush . reset (counter) (quota). Table 8. (Set specifications) +-------------------------+------------------------------------------+-----------------------------+ | | (Description) | (Type) | |(Keyword) | | | +-------------------------+------------------------------------------+-----------------------------+ |type | | string: ipv4_addr, | | | | ipv6_addr, ether_addr, | | | | inet_proto, inet_service, | | | | mark | +-------------------------+------------------------------------------+-----------------------------+ |typeof | | | | | | | | | | | | | | | | | | | +-------------------------+------------------------------------------+-----------------------------+ |flags | | string: constant, dynamic, | | | | interval, timeout. | | | | | | | | | | | | | | | | | | | | | | | | . | +-------------------------+------------------------------------------+-----------------------------+ |timeout | | | | | | | | | | | | | | . | | | | | | | ( | | | | ) | : d, h, m, s | | | | | +-------------------------+------------------------------------------+-----------------------------+ |gc-interval | | | | | | | | | (garbage collection) | | | | | . | | | timeout | | | | timeout | | | | | : d, h, m, s | +-------------------------+------------------------------------------+-----------------------------+ |elements | | | | | | | +-------------------------+------------------------------------------+-----------------------------+ |size | | | | | | | | | | ( | | | | ) | | | | | | | ( | | | | ) | | | | | | +-------------------------+------------------------------------------+-----------------------------+ |policy | | string: performance | | | | [], | | | | memory | +-------------------------+------------------------------------------+-----------------------------+ |auto-merge | | | | | | | | | / | | | | ( | | | | | | | | | | | | ) | | +-------------------------+------------------------------------------+-----------------------------+ gc-interval (timeout) . ( ) . . (garbage collector) . gc-interval . size . add update . size nft add element ( ) . policy . auto-merge nftables . : 1.2.3.1-1.2.3.4 1.2.3.2 . 1.2.3.5 1.2.3.1-1.2.3.5 . 1.2.3.2 1.2.3.5 . ( ). (bitmasks) " (BITMASK TYPE)" . (MAPS) add map [family] table map { type type | typeof expression [flags flags ;] [elements = { element[, ...] } ;] [size size ;] [comment comment ;] [policy 'policy ;] } {delete | destroy | list | flush | reset } map [family] table map list maps [family] [table] (Maps) . . add . delete . destroy . list . flush . reset (counter) (quota). Table 9. (Map specifications) +-------------------------+------------------------------------+--------------------------------+ | | | (Type) | |(Keyword) | (Description) | | +-------------------------+------------------------------------+--------------------------------+ |type | | string: ipv4_addr, ipv6_addr, | | | | ether_addr, inet_proto, | | | | inet_service, mark, counter, | | | | quota. | | | | (counter) | | | | (quota) | | | | | | | | | | | | | | | | | | | | | +-------------------------+------------------------------------+--------------------------------+ |typeof | | | | | | | | | / | | | | | | +-------------------------+------------------------------------+--------------------------------+ |flags | | | | | | | | | | | | | | | +-------------------------+------------------------------------+--------------------------------+ |elements | | | | | | | +-------------------------+------------------------------------+--------------------------------+ |size | | | | | | | | | | ( ) | +-------------------------+------------------------------------+--------------------------------+ |policy | | string: performance | | | | [], | | | | memory | +-------------------------+------------------------------------+--------------------------------+ / / . . nftables . / . (mutually exclusive) . Table 10. (Set and Map flags) +-----------------+--------------------------------------------+ | (Flag) | (Description) | +-----------------+--------------------------------------------+ |constant | | | | | | | | | | | +-----------------+--------------------------------------------+ |dynamic | | | | | | | | | | | | | add update delete | | | . | +-----------------+--------------------------------------------+ |interval | | | | | | | () | | | . | | | | | | dynamic | | | . | +-----------------+--------------------------------------------+ |timeout | | | | | | | ( | | | | | | ) | | | . | +-----------------+--------------------------------------------+ (ELEMENTS) {add | create | delete | destroy | get | reset } element [family] table set { ELEMENT[, ...] } ELEMENT := key_expression OPTIONS [: value_expression] OPTIONS := [timeout TIMESPEC] [expires TIMESPEC] [comment string] TIMESPEC := [numd][numh][numm][num[s]] . key_expression . value_expression . key_expression . create add . get / . . reset () (counter) (quota). Table 11. (Element options) +-------------------------+---------------------------------------------------------+ | (Option) | (Description) | +-------------------------+---------------------------------------------------------+ |timeout | | | | | | | / | | | timeout | +-------------------------+---------------------------------------------------------+ |expires | | | | | | | | | | | | | (ruleset replication) | +-------------------------+---------------------------------------------------------+ |comment | (comment) | | | | +-------------------------+---------------------------------------------------------+ (FLOWTABLES) {add | create} flowtable [family] table flowtable { hook hook priority priority ; devices = { DEVICE_LIST } ; } list flowtables [family] [table] {delete | destroy | list} flowtable [family] table flowtable delete flowtable [family] table handle handle DEVICE_LIST := DEVICE_NAME [, DEVICE_LIST] DEVICE_NAME := string | string* (Flowtables) . (tuple) / . (gateway) - - . ttl hoplimit . . ingress prerouting . (offload) flow forward . . ip ip6 inet . inet IPv4/IPv6 . ip . priority filter . filter + 5 . (wildcards) DEVICE_LIST . . list hooks . add . delete . destroy . list . (STATEFUL OBJECTS) {add | delete | destroy | list | reset} counter [family] table object {add | delete | destroy | list | reset} quota [family] table object {add | delete | destroy | list} limit [family] table object delete counter [family] table handle handle delete quota [family] table handle handle delete limit [family] table handle handle destroy counter [family] table handle handle destroy quota [family] table handle handle destroy limit [family] table handle handle list { counters | limits | quotas } [family] [table] reset { counters | quotas } [family] [table] (Stateful objects) . "type name" "counter name". add . delete . destroy . list . reset (List-and-reset). CT HELPER add ct helper [family] table name { type type protocol protocol ; [l3proto family ;] } delete ct helper [family] table name list ct helpers Ct helper (connection tracking helpers) ct helper set . type protocol l3proto inet ipv4 ipv6 ( ) . 12. conntrack helper +----------------+-----------------------+-----------------------+ | | | | | | | | +----------------+-----------------------+-----------------------+ |type | | | | | | | | | | | | | | ( | | | | "ftp") | +----------------+-----------------------+-----------------------+ |protocol | | | | | | ( ip) | | | | | +----------------+-----------------------+-----------------------+ |l3proto | | | | | | | | | | ( ip) | +----------------+-----------------------+-----------------------+ |comment | | | | | | | | | | | | | ct helper | | +----------------+-----------------------+-----------------------+ ftp. Unlike iptables, helper assignment needs to be performed after the conntrack lookup has completed, for example with the default 0 hook priority. table inet myhelpers { ct helper ftp-standard { type "ftp" protocol tcp } chain prerouting { type filter hook prerouting priority filter; tcp dport 21 ct helper set "ftp-standard" } } CT TIMEOUT add ct timeout [family] table name { protocol protocol ; policy = { state: value [, ...] } ; [l3proto family ;] } delete ct timeout [family] table name list ct timeouts Ct timeout (timeout) . Timeout ct timeout set . protocol policy l3proto . 13. conntrack timeout +----------------+-----------------------+-----------------------+ | | | | | | | | +----------------+-----------------------+-----------------------+ |protocol | | | | | | ( ip) | | | timeout | | +----------------+-----------------------+-----------------------+ |state | | | | | | ( | | | | "established") | +----------------+-----------------------+-----------------------+ |value | | | | | | | | | | | | | | | | | | | | | | | +----------------+-----------------------+-----------------------+ |l3proto | | | | | | | | | timeout | ( ip) | +----------------+-----------------------+-----------------------+ |comment | | | | | | | | | | | | | ct timeout | | +----------------+-----------------------+-----------------------+ tcp timeout : close close_wait established fin_wait last_ack retrans syn_recv syn_sent time_wait unack. sysctl -a |grep net.netfilter.nf_conntrack_tcp_timeout_ . ct timeout . tcp 53 . udp timeout replied unreplied. ct timeout. table ip filter { ct timeout customtimeout { protocol tcp; l3proto ip policy = { established: 2m, close: 20s } } chain output { type filter hook output priority filter; policy accept; ct timeout set "customtimeout" } } timeout . % conntrack -E It should display: [UPDATE] tcp 6 120 ESTABLISHED src=172.16.19.128 dst=172.16.19.1 sport=22 dport=41360 [UNREPLIED] src=172.16.19.1 dst=172.16.19.128 sport=41360 dport=22 CT EXPECTATION add ct expectation [family] table name { protocol protocol ; dport dport ; timeout timeout ; size size ; [l3proto family ;] } delete ct expectation [family] table name list ct expectations Ct expectation (connection expectations) . ct expectation set . protocol dport timeout size l3proto . 14. conntrack expectation +----------------+-----------------------+-----------------------+ | | | | | | | | +----------------+-----------------------+-----------------------+ |protocol | | | | | | ( ip) | | | expectation | | +----------------+-----------------------+-----------------------+ |dport | | | | | | | | | | | | | | | | | | | +----------------+-----------------------+-----------------------+ |timeout | | | | | | | | | | | | | | | | | expectation | | +----------------+-----------------------+-----------------------+ |size | | | | | | | | | | | | | expectation | | +----------------+-----------------------+-----------------------+ |l3proto | | | | | | | | | expectation | ( ip) | +----------------+-----------------------+-----------------------+ |comment | | | | | | | | | | | | | ct expectation | | +----------------+-----------------------+-----------------------+ ct expectation. table ip filter { ct expectation expect { protocol udp dport 9876 timeout 2m size 8 l3proto ip } chain input { type filter hook input priority filter; policy accept; ct expectation set "expect" } } COUNTER add counter [family] table name [{ [ packets packets bytes bytes ; ] [ comment comment ; }] delete counter [family] table name list counters 15. (Counter specifications) +----------------+-----------------------+-----------------+ | | | | | | | | +----------------+-----------------------+-----------------+ |packets | | | | | | | | | | | | | | | | | | ( | | | | ) | +----------------+-----------------------+-----------------+ |bytes | | | | | | | | | | | | | | | | | | ( | | | | ) | +----------------+-----------------------+-----------------+ |comment | | | | | | | | | | | | | | | +----------------+-----------------------+-----------------+ . nft add counter filter http nft add rule filter input tcp dport 80 counter name \"http\" (maps). nft add counter filter http nft add counter filter https nft add rule filter input counter name tcp dport map { 80 : \"http\", 443 : \"https\" } QUOTA add quota [family] table name { [over|until] bytes BYTE_UNIT [ used bytes BYTE_UNIT ] ; [ comment comment ; ] } BYTE_UNIT := bytes | kbytes | mbytes delete quota [family] table name list quotas 16. (Quota specifications) +----------------+--------------------------+--------------------------------+ | | | | | | | | +----------------+--------------------------+--------------------------------+ |quota | | | | | | | | | | | | | | | | | quota | ( ) | | | | : bytes | | | | kbytes mbytes. | | | | "over" | | | | "until" | | | | | | | | | | | | | | | | | +----------------+--------------------------+--------------------------------+ |used | | | | | | | | | | | | | | | | | | ( ) | | | | : bytes | | | | kbytes mbytes | +----------------+--------------------------+--------------------------------+ |comment | | | | | | | | | | | | | quota | | +----------------+--------------------------+--------------------------------+ . nft add quota filter user123 { over 20 mbytes } nft add rule filter input ip saddr 192.168.10.123 quota name \"user123\" (maps). nft add quota filter user123 { over 20 mbytes } nft add quota filter user124 { over 20 mbytes } nft add rule filter input quota name ip saddr map { 192.168.10.123 : \"user123\", 192.168.10.124 : \"user124\" } (EXPRESSIONS) (ruleset). ( / match) . NAT (packet marking) . (data type) . DESCRIBE (DESCRIBE COMMAND) describe expression | data type describe . nft . describe. $ nft describe tcp flags payload expression, datatype tcp_flag (TCP flag) (basetype bitmask, integer), 8 bits predefined symbolic constants: fin 0x01 syn 0x02 rst 0x04 psh 0x08 ack 0x10 urg 0x20 ecn 0x40 cwr 0x80 (DATA TYPES) . . (string). . describe nft : $ nft describe ct_state datatype ct_state (conntrack state) (basetype bitmask, integer), 32 bits pre-defined symbolic constants (in hexadecimal): invalid 0x00000001 new ... IPv4 IPv4 . ( set map) . . (INTEGER TYPE) +-------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +-------------+--------------------------+--------------------+--------------+ | | integer | | - | | | | | | |(Integer) | | | | +-------------+--------------------------+--------------------+--------------+ (integer) . (decimal) (octal) . . (BITMASK TYPE) +-------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +-------------+--------------------------+--------------------+--------------+ | | bitmask | | integer | | | | | | |(Bitmask) | | | | +-------------+--------------------------+--------------------+--------------+ (bitmask) . bit[,bit]... bit ( 0x1 ct state new ). ( ). expression value / mask expression and mask == value . tcp flags syn,ack / syn,ack,fin,rst tcp flags and (syn|ack|fin|rst) == syn|ack . expression bit[,bit]... expression {bit[,bit]...} (named set) . . (mutually exclusive) ( ). : * tcp flags syn,ack SYN ACK SYN ACK . . tcp flags { syn, ack } SYN ACK . . * ct state established,related ct state { established, related } ct state . nft describe . (STRING TYPE) +-------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +-------------+--------------------------+--------------------+--------------+ | | string | | - | |(String) | | | | +-------------+--------------------------+--------------------+--------------+ (string) . (a-zA-Z) / - _ . . (") . (String specification). # Interface name filter input iifname eth0 # Weird interface name filter input iifname "(eth0)" (INTERFACE TYPE TYPE) +-------------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +-------------------+--------------------------+--------------------+--------------+ | | iface_type | | integer | | | | | | | | | | | |(Interface type) | | | | +-------------------+--------------------------+--------------------+--------------+ (interface type type) meta iiftype/oiftype . ARPHRD_* . . : +-------------------------+-----------------+ | | | +-------------------------+-----------------+ |ether | 1 | +-------------------------+-----------------+ |ppp | 512 | +-------------------------+-----------------+ |ipip | 768 | +-------------------------+-----------------+ |ipip6 | 769 | +-------------------------+-----------------+ |loopback | 772 | +-------------------------+-----------------+ |sit | 776 | +-------------------------+-----------------+ |ipgre | 778 | +-------------------------+-----------------+ (LINK LAYER ADDRESS TYPE) +----------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +----------------+--------------------------+--------------------+--------------+ | | lladdr | | integer | | | | | | | | | | | |(Link layer | | | | |address) | | | | +----------------+--------------------------+--------------------+--------------+ (link layer address) . (:) . (Link layer address specification). # Ethernet destination MAC address filter input ether daddr 20:c9:d0:43:12:d9 IPV4 (IPV4 ADDRESS TYPE) +-------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +-------------+--------------------------+--------------------+--------------+ | | ipv4_addr | | integer | |IPv4 | | | | +-------------+--------------------------+--------------------+--------------+ IPv4 IPv4 . (dotted decimal) (host name) . (resolver) . IPv4 (IPv4 address specification). # dotted decimal notation filter output ip daddr 127.0.0.1 # host name filter output ip daddr localhost IPV6 (IPV6 ADDRESS TYPE) +-------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +-------------+--------------------------+--------------------+--------------+ | | ipv6_addr | | integer | |IPv6 | | | | +-------------+--------------------------+--------------------+--------------+ IPv6 IPv6 . (halfwords) . ("[]") . IPv6 (IPv6 address specification). # abbreviated loopback address filter output ip6 daddr ::1 IPv6 (IPv6 address specification with bracket notation). # without [] the port number (22) would be parsed as part of the # ipv6 address ip6 nat prerouting tcp dport 2222 dnat to [1ce::d0]:22 (BOOLEAN TYPE) +-------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +-------------+--------------------------+--------------------+--------------+ | | boolean | | integer | |(Boolean) | | | | +-------------+--------------------------+--------------------+--------------+ (boolean) (userspace) . ( ) ( ) . . : +-------------------------+-----------------+ | | | +-------------------------+-----------------+ |exists | 1 | +-------------------------+-----------------+ |missing | 0 | +-------------------------+-----------------+ . +----------------+----------------------------+ | | | +----------------+----------------------------+ |fib | | | | . | +----------------+----------------------------+ |exthdr | | | | | | | IPv6. | +----------------+----------------------------+ |tcp option | | | | | | | TCP. | +----------------+----------------------------+ (Boolean specification). # match if route exists filter input fib daddr . iif check exists # match only non-fragmented packets in IPv6 traffic filter input exthdr frag missing # match if TCP timestamp option is present filter input tcp option timestamp exists ICMP (ICMP TYPE TYPE) +---------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +---------------+--------------------------+--------------------+--------------+ | ICMP | icmp_type | | integer | +---------------+--------------------------+--------------------+--------------+ ICMP (type) ICMP . . ICMP : +-------------------------+-----------------+ | | | +-------------------------+-----------------+ |echo-reply | 0 | +-------------------------+-----------------+ |destination-unreachable | 3 | +-------------------------+-----------------+ |source-quench | 4 | +-------------------------+-----------------+ |redirect | 5 | +-------------------------+-----------------+ |echo-request | 8 | +-------------------------+-----------------+ |router-advertisement | 9 | +-------------------------+-----------------+ |router-solicitation | 10 | +-------------------------+-----------------+ |time-exceeded | 11 | +-------------------------+-----------------+ |parameter-problem | 12 | +-------------------------+-----------------+ |timestamp-request | 13 | +-------------------------+-----------------+ |timestamp-reply | 14 | +-------------------------+-----------------+ |info-request | 15 | +-------------------------+-----------------+ |info-reply | 16 | +-------------------------+-----------------+ |address-mask-request | 17 | +-------------------------+-----------------+ |address-mask-reply | 18 | +-------------------------+-----------------+ ICMP (ICMP Type specification). # match ping packets filter output icmp type { echo-request, echo-reply } ICMP (ICMP CODE TYPE) +------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +------------+--------------------------+--------------------+--------------+ | ICMP | icmp_code | | integer | +------------+--------------------------+--------------------+--------------+ ICMP (code) ICMP . ICMPV6 (ICMPV6 TYPE TYPE) +-----------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +-----------------+--------------------------+--------------------+--------------+ | ICMPv6 | icmpv6_type | | integer | +-----------------+--------------------------+--------------------+--------------+ ICMPv6 (type) ICMPv6 . . ICMPv6 : +-------------------------+-----------------+ | | | +-------------------------+-----------------+ |destination-unreachable | 1 | +-------------------------+-----------------+ |packet-too-big | 2 | +-------------------------+-----------------+ |time-exceeded | 3 | +-------------------------+-----------------+ |parameter-problem | 4 | +-------------------------+-----------------+ |echo-request | 128 | +-------------------------+-----------------+ |echo-reply | 129 | +-------------------------+-----------------+ |mld-listener-query | 130 | +-------------------------+-----------------+ |mld-listener-report | 131 | +-------------------------+-----------------+ |mld-listener-done | 132 | +-------------------------+-----------------+ |mld-listener-reduction | 132 | +-------------------------+-----------------+ |nd-router-solicit | 133 | +-------------------------+-----------------+ |nd-router-advert | 134 | +-------------------------+-----------------+ |nd-neighbor-solicit | 135 | +-------------------------+-----------------+ |nd-neighbor-advert | 136 | +-------------------------+-----------------+ |nd-redirect | 137 | +-------------------------+-----------------+ |router-renumbering | 138 | +-------------------------+-----------------+ |ind-neighbor-solicit | 141 | +-------------------------+-----------------+ |ind-neighbor-advert | 142 | +-------------------------+-----------------+ |mld2-listener-report | 143 | +-------------------------+-----------------+ ICMPv6 (ICMPv6 Type specification). # match ICMPv6 ping packets filter output icmpv6 type { echo-request, echo-reply } ICMPV6 (ICMPV6 CODE TYPE) +--------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +--------------+--------------------------+--------------------+--------------+ | ICMPv6 | icmpv6_code | | integer | +--------------+--------------------------+--------------------+--------------+ ICMPv6 (code) ICMPv6 . (CONNTRACK TYPES) . ct +----------------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +----------------------+--------------------------+--------------------+--------------+ | | ct_state | | bitmask | | | | | | | | | | | |(conntrack state) | | | | +----------------------+--------------------------+--------------------+--------------+ | | ct_dir | | integer | | | | | | | | | | | |(conntrack direction) | | | | +----------------------+--------------------------+--------------------+--------------+ | | ct_status | | bitmask | | | | | | | | | | | |(conntrack status) | | | | +----------------------+--------------------------+--------------------+--------------+ | | ct_event | | bitmask | | | | | | | | | | | | | | | | |(conntrack event | | | | |bits) | | | | +----------------------+--------------------------+--------------------+--------------+ | | ct_label | | bitmask | | | | | | | | | | | |(conntrack label) | | | | +----------------------+--------------------------+--------------------+--------------+ : . (ct_state) +-------------------------+-----------------+ | | | +-------------------------+-----------------+ |invalid | 1 | +-------------------------+-----------------+ |established | 2 | +-------------------------+-----------------+ |related | 4 | +-------------------------+-----------------+ |new | 8 | +-------------------------+-----------------+ |untracked | 64 | +-------------------------+-----------------+ . (ct_dir) +-------------------------+-----------------+ | | | +-------------------------+-----------------+ |original | 0 | +-------------------------+-----------------+ |reply | 1 | +-------------------------+-----------------+ . (ct_status) +-------------------------+-----------------+--------------------------------+ | | | | +-------------------------+-----------------+--------------------------------+ |expected | 1 | | | | | | | | | conntrack helper | | | | | | | | | +-------------------------+-----------------+--------------------------------+ |seen-reply | 2 | | | | | (conntrack) | | | | | | | | | | | | | +-------------------------+-----------------+--------------------------------+ |assured | 4 | | | | | | | | | (hash table) | | | | conntrack | | | | | +-------------------------+-----------------+--------------------------------+ |confirmed | 8 | | | | | | | | | | +-------------------------+-----------------+--------------------------------+ |snat | 16 | | | | | | | | | | | | | | +-------------------------+-----------------+--------------------------------+ |dnat | 32 | | | | | | | | | | | | | | +-------------------------+-----------------+--------------------------------+ |seq-adjust | 64 | | | | | | | | | tcp | | | | conntrack helper | | | | synproxy | +-------------------------+-----------------+--------------------------------+ |snat-done | 128 | | | | | | | | | | | | | snat/masquerade | | | | | +-------------------------+-----------------+--------------------------------+ |dnat-done | 256 | | | | | | | | | dnat/redirect | | | | | | | | | +-------------------------+-----------------+--------------------------------+ |dying | 512 | | | | | | | | | | +-------------------------+-----------------+--------------------------------+ |fixed-timeout | 1024 | | | | | | | | | | | | | | | | | | | | | | +-------------------------+-----------------+--------------------------------+ |helper | 8192 | | | | | conntrack helper | | | | | +-------------------------+-----------------+--------------------------------+ |offload | 16384 | | | | | | | | | (flow table) | | | | | | | | | +-------------------------+-----------------+--------------------------------+ |hw-offload | 32768 | | | | | | | | | | | | | | +-------------------------+-----------------+--------------------------------+ . (ct_event) +-------------------------+-----------------+ | | | +-------------------------+-----------------+ |new | 1 | +-------------------------+-----------------+ |related | 2 | +-------------------------+-----------------+ |destroy | 4 | +-------------------------+-----------------+ |reply | 8 | +-------------------------+-----------------+ |assured | 16 | +-------------------------+-----------------+ |protoinfo | 32 | +-------------------------+-----------------+ |helper | 64 | +-------------------------+-----------------+ |mark | 128 | +-------------------------+-----------------+ |seqadj | 256 | +-------------------------+-----------------+ |secmark | 512 | +-------------------------+-----------------+ |label | 1024 | +-------------------------+-----------------+ (ct_label) /etc/connlabel.conf . DCCP (DCCP PKTTYPE TYPE) +-------------+--------------------------+--------------------+--------------+ | | | | | | | | | | +-------------+--------------------------+--------------------+--------------+ | | dccp_pkttype | | integer | | | | | | |DCCP | | | | +-------------+--------------------------+--------------------+--------------+ DCCP DCCP RFC4340 . - . dccp iptables INVALID . nftables 10-15. . DCCP +-------------------------+-----------------+ | | | +-------------------------+-----------------+ |request | 0 | +-------------------------+-----------------+ |response | 1 | +-------------------------+-----------------+ |data | 2 | +-------------------------+-----------------+ |ack | 3 | +-------------------------+-----------------+ |dataack | 4 | +-------------------------+-----------------+ |closereq | 5 | +-------------------------+-----------------+ |close | 6 | +-------------------------+-----------------+ |reset | 7 | +-------------------------+-----------------+ |sync | 8 | +-------------------------+-----------------+ |syncack | 9 | +-------------------------+-----------------+ (PRIMARY EXPRESSIONS) (primary expression) (payload) (stateful) . (META EXPRESSIONS) meta {length | nfproto | l4proto | protocol | priority} [meta] {mark | iif | iifname | iiftype | oif | oifname | oiftype | skuid | skgid | nftrace | rtclassid | ibrname | obrname | pkttype | cpu | iifgroup | oifgroup | cgroup | random | ipsec | iifkind | oifkind | time | hour | day } . : (qualified) (unqualified). meta . meta l4proto IPv4 IPv6 . IPv6 IPv6 . meta iif oif iifname oifname . iif oif (interface index) iifname oifname . -- : filter input meta iif "foo" "foo" . "foo" "bar" . . tun/tap dialup ( ppp) iifname oifname . . iptables (wildcard) iifname oifname (*) . iptables nftables - . (\) . . (Meta expression types) +----------------+--------------------------------+-----------------------+ | | | | | | | | +----------------+--------------------------------+-----------------------+ |length | | integer (32-bit) | | | | | +----------------+--------------------------------+-----------------------+ |nfproto | | integer (32 bit) | | | | | | | | | | | | | | | inet | | | | | | | | | | +----------------+--------------------------------+-----------------------+ |l4proto | | integer (8 bit) | | | | | | | | | | | ipv6 | | | | | | | | | | +----------------+--------------------------------+-----------------------+ |protocol | | ether_type | | | EtherType | | +----------------+--------------------------------+-----------------------+ |priority | | tc_handle | | | TC | | +----------------+--------------------------------+-----------------------+ |mark | | mark | | | (Packet mark) | | +----------------+--------------------------------+-----------------------+ |iif | | iface_index | | | | | +----------------+--------------------------------+-----------------------+ |iifname | | ifname | | | | | +----------------+--------------------------------+-----------------------+ |iiftype | | iface_type | | | | | +----------------+--------------------------------+-----------------------+ |oif | | iface_index | | | | | +----------------+--------------------------------+-----------------------+ |oifname | | ifname | | | | | +----------------+--------------------------------+-----------------------+ |oiftype | | iface_type | | | | | | | | | +----------------+--------------------------------+-----------------------+ |sdif | | iface_index | | | | | | | Slave | | +----------------+--------------------------------+-----------------------+ |sdifname | | ifname | | | Slave | | +----------------+--------------------------------+-----------------------+ |skuid | | uid | | | (UID) | | | | | | | | | | +----------------+--------------------------------+-----------------------+ |skgid | | gid | | | (GID) | | | | | | +----------------+--------------------------------+-----------------------+ |rtclassid | | realm | | | | | | | (Routing realm) | | +----------------+--------------------------------+-----------------------+ |ibrname | | ifname | | | (Bridge) | | +----------------+--------------------------------+-----------------------+ |obrname | | ifname | | | (Bridge) | | +----------------+--------------------------------+-----------------------+ |pkttype | | pkt_type | +----------------+--------------------------------+-----------------------+ |cpu | | integer (32 bit) | | | | | | | | | | | | | | | | | +----------------+--------------------------------+-----------------------+ |iifgroup | | devgroup | | | | | | | | | +----------------+--------------------------------+-----------------------+ |oifgroup | | devgroup | | | | | | | | | +----------------+--------------------------------+-----------------------+ |cgroup | | integer (32 bit) | | | net_cls.classid | | | | | | | | | | | | | | | | | | | | | | | | cgroupv2 | | | | | | | | net_cls | | | | | | | | | | | | ( | | | | cgroupv2 | | | | socket | | | | cgroupv2 | | | | ) | | +----------------+--------------------------------+-----------------------+ |random | | integer (32 bit) | | | | | +----------------+--------------------------------+-----------------------+ |ipsec | (true) | boolean (1 bit) | | | ipsec | | | | | | | | | | +----------------+--------------------------------+-----------------------+ |iifkind | | | | | | | +----------------+--------------------------------+-----------------------+ |oifkind | | | | | | | +----------------+--------------------------------+-----------------------+ |time | | Integer (32 bit) or | | | | string | | | | | +----------------+--------------------------------+-----------------------+ |day | | Integer (8 bit) or | | | | string | +----------------+--------------------------------+-----------------------+ |hour | | | | | | | | | | | | | | HH:MM | | | | HH:MM:SS. | | | | | | | | | | | | | | | | 24:00 | | | | | | | | | | | | | | | | | | | | 23:59:60 | | | | | | | | | | | | . | +----------------+--------------------------------+-----------------------+ . (Meta expression specific types) +--------------+--------------------------------+ | | | +--------------+--------------------------------+ |iface_index | | | | ( | | | ). | | | | | | | | | | | | | | | | | | | | | . | +--------------+--------------------------------+ |ifname | | | | ( | | | ). | | | | | | | | | . | +--------------+--------------------------------+ |uid | | | | ( | | | ). | | | | | | | | | | | | | | | | | | . | +--------------+--------------------------------+ |gid | | | | ( | | | ). | | | | | | | | | | | | | | | | | | . | +--------------+--------------------------------+ |realm | | | | | | | (Routing Realm - | | | ). | | | | | | | | | | | | | | | | | | | | | /etc/iproute2/rt_realms | | | . | +--------------+--------------------------------+ |devgroup_type | | | | ( | | | ). | | | | | | | | | | | | | | | | | | | | | /etc/iproute2/group | | | . | +--------------+--------------------------------+ |pkt_type | : host | | | ( | | | | | | ) | | | broadcast ( | | | ) multicast | | | ( ) | | | other ( | | | | | | ). | +--------------+--------------------------------+ |ifkind | | | | ( | | | ). | | | | | | | | | TYPES ip-link(8) | | | . | +--------------+--------------------------------+ |time | | | | | | | | | | ISO. | | | : "2019-06-06 | | | 17:00". | | | | | | | | | | | | | | | | | | | | | . | | | | | | | | | | | | . | | | | | | | | | : | | | "2019-06-06" "2019-06-06 | | | 00:00" "2019-06-06 | | | 00:00:00". | | | | | | | | | | | | | | | | | | "2019-06-06 | | | 10:00"-"2019-06-10 14:00" | | | | | | . | | | | | | | | | | | | | | | | | | | | | (UNIX | | | timestamp) | | | | | | . | +--------------+--------------------------------+ |day | | | | ("Monday" | | | "Tuesday" ) | | | | | | 0 | | | 6. | | | | | | | | | | | | | | | | | | | | | | | | | | | ( | | | "Mon" "Monday" | | | | | | ). | | | | | | | | | | | | 0 | | | | | | (Sunday) | | | 6 | | | (Saturday) | | | . | | | | | | | | | | | | | | | | | | | | | | | | "Monday"-"Wednesday" | | | | | | . | +--------------+--------------------------------+ |hour | | | | | | | | | | | | | . | | | | | | | | | | | | | | | . | | | | | | 17:00 17:00:00 | | | | | | . | | | | | | | | | | | | | | | | | | | | | "17:00"-"19:00" | | | | | | . | +--------------+--------------------------------+ (Using meta expressions). # filter output meta oif eth0 filter forward meta iifkind { "tun", "veth" } # filter output oif eth0 # ipsec raw prerouting meta ipsec exists accept # 03:00 14:00 raw prerouting meta hour "03:00"-"14:00" counter accept SOCKET (SOCKET EXPRESSION) socket {transparent | mark | wildcard} socket cgroupv2 level NUM socket TCP/UDP . ( ) . cgroupv2 (ancestor) cgroupv2 a/b 1 cgroup a 2 cgroup b . . (Available socket attributes) +------------+---------------------------+-----------------+ | | | | +------------+---------------------------+-----------------+ |transparent | | boolean (1 bit) | | | | | | | | | | | IP_TRANSPARENT | | | | | | | | . | | | | | | | | | | | | 0 1 . | | +------------+---------------------------+-----------------+ |mark | | mark | | | | | | | (SOL_SOCKET, SO_MARK). | | +------------+---------------------------+-----------------+ |wildcard | | boolean (1 bit) | | | | | | | | | | | | | | | wildcard | | | | | | | | | | | | ( 0.0.0.0 | | | | ::0). | | +------------+---------------------------+-----------------+ |cgroupv2 | 2 cgroup | cgroupv2 | | | | | | | | | | | ( | | | | /sys/fs/cgroup) | | +------------+---------------------------+-----------------+ socket (Using socket expression). # (transparent). "socket wildcard 0" # ( # ). table inet x { chain y { type filter hook prerouting priority mangle; policy accept; socket transparent 1 socket wildcard 0 mark set 0x00000001 accept } } # 15 table inet x { chain y { type filter hook prerouting priority mangle; policy accept; socket mark 0x0000000f nftrace set 1 } } # table inet x { chain y { type filter hook prerouting priority mangle; policy accept; tcp dport 8080 mark set socket mark } } # cgroupv2 "user.slice" 1 table inet x { chain y { type filter hook input priority filter; policy accept; socket cgroupv2 level 1 "user.slice" counter } } OSF (OSF EXPRESSION) osf [ttl {loose | skip}] {name | version} osf (fingerprinting) . ( Window Size MSS DF ) SYN . . osf (Available osf attributes) +----------+-----------------------------------+-----------+ | | | | +----------+-----------------------------------+-----------+ |ttl | TTL | string | | | | | | | | | | | . | | +----------+-----------------------------------+-----------+ |version | | | | | | | | | . | | +----------+-----------------------------------+-----------+ |name | | string | | | | | | | . | | | | | | | | | | | | pf.os | | | | . "unknown" | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | . | | +----------+-----------------------------------+-----------+ ttl (Available ttl values). TTL IP TTL . (LAN) . * loose: TTL IP TTL . (globally-routable) . * skip: TTL . osf (Using osf expression). # "Linux" TTL . table inet x { chain y { type filter hook input priority filter; policy accept; osf ttl skip name "Linux" } } FIB (FIB EXPRESSIONS) fib FIB_TUPLE FIB_RESULT FIB_TUPLE := { saddr | daddr} [ . { iif | oif } . mark ] FIB_RESULT := { oif | oifname | check | type } fib (FIB - Forwarding Information Base) . fib fib . saddr daddr (mutually exclusive) . mark iif oif FIB_TUPLE . iif oif . fib . oif ( saddr) ( daddr) . 0 . oifname oif . ppp . . type (unicast) (multicast) . nft describe fib_addrtype . . FIB_TUPLE (FIB_TUPLE keywords) +----------+----------------------------+ | | | +----------+----------------------------+ |daddr | | | | | | | : | | | fib | | | | | | | | | | | | . | +----------+----------------------------+ |saddr | | | | | | | | | | : | | | fib | | | | | | | | | | | | . | +----------+----------------------------+ |mark | | | | | | | | | | (nfmark) | | | | | | fib. | +----------+----------------------------+ |iif | | | | fib | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | . | +----------+----------------------------+ |oif | | | | fib | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | . | | | | | | | | | | | | type | | | | | | | | | . | +----------+----------------------------+ . FIB_RESULT (FIB_RESULT keywords) +----------------+-----------------------+---------------------+ | | | | | | | | +----------------+-----------------------+---------------------+ |oif | | iface_index | | | | | | | | | +----------------+-----------------------+---------------------+ |check | | boolean | | | | | | | | | +----------------+-----------------------+---------------------+ |oifname | | ifname | | | | | | | | | +----------------+-----------------------+---------------------+ |type | | fib_addrtype | | | | ( | | | | | | | | | | | | nft describe | | | | fib_addrtype | | | | ) | +----------------+-----------------------+---------------------+ oif oifname prerouting input forward . type prerouting input forward output postrouting . type iif FIB_TUPLE prerouting input forward. oif FIB_TUPLE forward output postrouting . fib (Using fib expressions). # (drop) filter prerouting fib saddr . iif oif missing drop 'saddr . iif' * * fib . / . (strict reverse path) ( ). 'saddr oif' fib . . # IP filter prerouting fib daddr . iif type != { local, broadcast, multicast } drop fib . unicast 'unicast' . 'iif' 'local' unicast 'unicast' . # 'blackhole' ( 0xdead ip rule ) filter prerouting meta mark set 0xdead fib daddr . mark type vmap { blackhole : drop, prohibit : jump prohibited, unreachable : drop } (ROUTING EXPRESSIONS) rt [ip | ip6] {classid | nexthop | mtu | ipsec} (routing expression) . . (Routing expression types) +----------------+--------------------------+---------------------+ | | | | | | | | +----------------+--------------------------+---------------------+ |classid | | realm | | | | | | | (Routing realm) | | +----------------+--------------------------+---------------------+ |nexthop | | ipv4_addr/ipv6_addr | | | | | | | (Routing nexthop) | | +----------------+--------------------------+---------------------+ |mtu | | integer (16 bit) | | | | | | | (MSS) | | | | TCP | | | | | | | | | | +----------------+--------------------------+---------------------+ |ipsec | | boolean | | | | | | | | | | | | | | | ipsec | | +----------------+--------------------------+---------------------+ . (Routing expression specific types) +----------+-----------------------------+ | | | +----------+-----------------------------+ |realm | | | | | | | (Routing Realm - | | | ). | | | | | | | | | | | | | | | | | | | | | | | | /etc/iproute2/rt_realms | | | . | +----------+-----------------------------+ (Using routing expressions). # rt IP filter output rt classid 10 # rt IP ip filter output rt nexthop 192.168.0.1 ip6 filter output rt nexthop fd00::1 inet filter output rt ip nexthop 192.168.0.1 inet filter output rt ip6 nexthop fd00::1 # ipsec / filter output rt ipsec exists IPSEC (IPSEC EXPRESSIONS) ipsec {in | out} [ spnum NUM ] {reqid | spi} ipsec {in | out} [ spnum NUM ] {ip | ip6} {saddr | daddr} ipsec ipsec . in out . in prerouting input forward . out forward output postrouting . spnum (state) 0 . . Ipsec (Ipsec expression types) +----------------+-----------------------+---------------------+ | | | | | | | | +----------------+-----------------------+---------------------+ |reqid | | integer (32 bit) | | | | | | | (Request ID) | | +----------------+-----------------------+---------------------+ |spi | | integer (32 bit) | | | | | | | | | | | (Security Parameter | | | | Index) | | +----------------+-----------------------+---------------------+ |saddr | | ipv4_addr/ipv6_addr | | | | | | | | | +----------------+-----------------------+---------------------+ |daddr | | ipv4_addr/ipv6_addr | | | | | | | | | +----------------+-----------------------+---------------------+ : xfrm_interface output IPsec - postrouting . NUMGEN (NUMGEN EXPRESSION) numgen {inc | random} mod NUM [ offset NUM ] . inc random : inc (increment). random . mod (: modulus) . offset . numgen (load-balancing) : numgen (Using numgen expression). # (round-robin) 192.168.10.100 192.168.20.200: add rule nat prerouting dnat to numgen inc mod 2 map \ { 0 : 192.168.10.100, 1 : 192.168.20.200 } # : add rule nat prerouting dnat to numgen random mod 10 map \ { 0-2 : 192.168.10.100, 3-9 : 192.168.20.200 } (HASH EXPRESSIONS) jhash {ip saddr | ip6 daddr | tcp dport | udp sport | ether saddr} [. ...] mod NUM [ seed NUM ] [ offset NUM ] symhash mod NUM [ offset NUM ] () . jhash Jenkins Hash symhash (Symmetric Hash). jhash (concatenation) . mod (: modulus) . seed (seed) . offset . jhash symhash (load- balancing) : (Using hash expressions). # ip ip: add rule nat prerouting dnat to jhash ip saddr mod 2 map \ { 0 : 192.168.10.100, 1 : 192.168.20.200 } # ip: add rule nat prerouting dnat to symhash mod 2 map \ { 0 : 192.168.10.100, 1 : 192.168.20.200 } (PAYLOAD EXPRESSIONS) (payload) . (ETHERNET HEADER EXPRESSION) ether {daddr | saddr | type} Table 37. (Ethernet header expression types) +-------------------------+-----------------------+------------+ | | | | +-------------------------+-----------------------+------------+ |daddr | MAC | ether_addr | | | | | +-------------------------+-----------------------+------------+ |saddr | MAC | ether_addr | | | | | +-------------------------+-----------------------+------------+ |type | EtherType | ether_type | +-------------------------+-----------------------+------------+ VLAN (VLAN HEADER EXPRESSION) vlan {id | dei | pcp | type} vlan vlan . ip ip6 inet vlan reorder_hdr off . reorder_hdr on vlan . ip-link(8) . vlan meta iif meta iifname . Table 38. VLAN (VLAN header expression) +-------------------------+-----------------------+------------------+ | | | | +-------------------------+-----------------------+------------------+ |id | VLAN | integer (12 bit) | | | (VID) | | +-------------------------+-----------------------+------------------+ |dei | | integer (1 bit) | | | | | | | | | | | (Drop | | | | Eligible Indicator) | | +-------------------------+-----------------------+------------------+ |pcp | | integer (3 bit) | | | | | | | (Priority code point) | | +-------------------------+-----------------------+------------------+ |type | EtherType | ether_type | +-------------------------+-----------------------+------------------+ ARP (ARP HEADER EXPRESSION) arp {htype | ptype | hlen | plen | operation | saddr { ip | ether } | daddr { ip | ether } Table 39. ARP (ARP header expression) +-------------------------+--------------------------------+------------------+ | | | | +-------------------------+--------------------------------+------------------+ |htype | | integer (16 bit) | | | | | | | ARP | | +-------------------------+--------------------------------+------------------+ |ptype | EtherType | ether_type | +-------------------------+--------------------------------+------------------+ |hlen | | integer (8 bit) | | | | | +-------------------------+--------------------------------+------------------+ |plen | | integer (8 bit) | | | | | +-------------------------+--------------------------------+------------------+ |operation | | arp_op | +-------------------------+--------------------------------+------------------+ |saddr ether | | ether_addr | | | | | | | | | +-------------------------+--------------------------------+------------------+ |daddr ether | | ether_addr | | | | | +-------------------------+--------------------------------+------------------+ |saddr ip | IPv4 | ipv4_addr | | | | | +-------------------------+--------------------------------+------------------+ |daddr ip | IPv4 | ipv4_addr | | | | | +-------------------------+--------------------------------+------------------+ IPV4 (IPV4 HEADER EXPRESSION) ip {version | hdrlength | dscp | ecn | length | id | frag-off | ttl | protocol | checksum | saddr | daddr } Table 40. IPv4 (IPv4 header expression) +-------------------------+-----------------------------+------------------+ | | | | +-------------------------+-----------------------------+------------------+ |version | IP | integer (4 bit) | | | () | | +-------------------------+-----------------------------+------------------+ |hdrlength | IP | integer (4 bit) | | | | FIXME scaling | | | | | +-------------------------+-----------------------------+------------------+ |dscp | | dscp | | | | | | | | | | | (Differentiated Services | | | | Code Point) | | +-------------------------+-----------------------------+------------------+ |ecn | | ecn | | | | | | | | | | | (Explicit Congestion | | | | Notification) | | +-------------------------+-----------------------------+------------------+ |length | | integer (16 bit) | | | | | +-------------------------+-----------------------------+------------------+ |id | IP | integer (16 bit) | +-------------------------+-----------------------------+------------------+ |frag-off | | integer (16 bit) | | | (Fragment offset) | | +-------------------------+-----------------------------+------------------+ |ttl | (TTL) | integer (8 bit) | +-------------------------+-----------------------------+------------------+ |protocol | | inet_proto | | | | | | | | | +-------------------------+-----------------------------+------------------+ |checksum | | integer (16 bit) | | | IP | | +-------------------------+-----------------------------+------------------+ |saddr | | ipv4_addr | | | | | +-------------------------+-----------------------------+------------------+ |daddr | | ipv4_addr | | | | | +-------------------------+-----------------------------+------------------+ ip length : MTU . GRO/GSO ( ip-link(8) gro_ipv4_max_size gso_ipv4_max_size ) ip length (jumbo packets) . meta length IP . ICMP (ICMP HEADER EXPRESSION) icmp {type | code | checksum | id | sequence | gateway | mtu} ICMP . inet bridge netdev IPv4 . ICMP IPv6 meta protocol ip6 . Table 41. ICMP (ICMP header expression) +-------------------------+------------------------------------+------------------+ | | | | +-------------------------+------------------------------------+------------------+ |type | ICMP | icmp_type | +-------------------------+------------------------------------+------------------+ |code | ICMP | integer (8 bit) | +-------------------------+------------------------------------+------------------+ |checksum | | integer (16 bit) | | | ICMP | | +-------------------------+------------------------------------+------------------+ |id | | integer (16 bit) | | | / | | | | | | +-------------------------+------------------------------------+------------------+ |sequence | | integer (16 bit) | | | / | | | | | | +-------------------------+------------------------------------+------------------+ |gateway | | integer (32 bit) | | | | | | | | | +-------------------------+------------------------------------+------------------+ |mtu | MTU | integer (16 bit) | | | MTU | | +-------------------------+------------------------------------+------------------+ IGMP (IGMP HEADER EXPRESSION) igmp {type | mrt | checksum | group} IGMP . inet bridge netdev IPv4 . IGMP IPv6 meta protocol ip6 . Table 42. IGMP (IGMP header expression) +-------------------------+-----------------------+------------------+ | | | | +-------------------------+-----------------------+------------------+ |type | | igmp_type | | | IGMP | | +-------------------------+-----------------------+------------------+ |mrt | | integer (8 bit) | | | | | | | | | | | IGMP | | +-------------------------+-----------------------+------------------+ |checksum | | integer (16 bit) | | | | | | | IGMP | | +-------------------------+-----------------------+------------------+ |group | | integer (32 bit) | | | | | +-------------------------+-----------------------+------------------+ IPV6 (IPV6 HEADER EXPRESSION) ip6 {version | dscp | ecn | flowlabel | length | nexthdr | hoplimit | saddr | daddr} IPv6 . ip6 nexthdr ip6 nexthdr tcp IPv6 (extension header) . . meta l4proto . Table 43. IPv6 (IPv6 header expression) +-------------------------+-----------------------------+------------------+ | | | | +-------------------------+-----------------------------+------------------+ |version | IP | integer (4 bit) | | | () | | +-------------------------+-----------------------------+------------------+ |dscp | | dscp | | | | | | | | | | | (Differentiated Services | | | | Code Point) | | +-------------------------+-----------------------------+------------------+ |ecn | | ecn | | | | | | | | | | | (Explicit Congestion | | | | Notification) | | +-------------------------+-----------------------------+------------------+ |flowlabel | | integer (20 bit) | | | (Flow | | | | label) | | +-------------------------+-----------------------------+------------------+ |length | | integer (16 bit) | | | (Payload | | | | length) | | +-------------------------+-----------------------------+------------------+ |nexthdr | | inet_proto | | | | | | | (Nexthdr protocol) | | +-------------------------+-----------------------------+------------------+ |hoplimit | | integer (8 bit) | | | (Hop limit) | | +-------------------------+-----------------------------+------------------+ |saddr | | ipv6_addr | | | | | +-------------------------+-----------------------------+------------------+ |daddr | | ipv6_addr | | | | | +-------------------------+-----------------------------+------------------+ ip6 length : MTU . GRO/GSO ( ip-link(8) gro_max_size gso_max_size ) ip6 length (jumbo packets) . meta length IPv6 . ip6. # ip6 nexthdr ipv6-frag ICMPV6 (ICMPV6 HEADER EXPRESSION) icmpv6 {type | code | checksum | parameter-problem | packet-too-big | id | sequence | max-delay | taddr | daddr} ICMPv6 . inet bridge netdev IPv6 . ICMPv6 IPv4 meta protocol ip . Table 44. ICMPv6 (ICMPv6 header expression) +-------------------------+---------------------------------------+------------------+ | | | | +-------------------------+---------------------------------------+------------------+ |type | ICMPv6 | icmpv6_type | +-------------------------+---------------------------------------+------------------+ |code | ICMPv6 | integer (8 bit) | +-------------------------+---------------------------------------+------------------+ |checksum | | integer (16 bit) | | | ICMPv6 | | +-------------------------+---------------------------------------+------------------+ |parameter-problem | | integer (32 bit) | | | | | +-------------------------+---------------------------------------+------------------+ |packet-too-big | MTU | integer (32 bit) | | | (oversized | | | | MTU) | | +-------------------------+---------------------------------------+------------------+ |id | | integer (16 bit) | | | / | | | | | | +-------------------------+---------------------------------------+------------------+ |sequence | | integer (16 bit) | | | / | | | | | | +-------------------------+---------------------------------------+------------------+ |max-delay | | integer (16 bit) | | | | | | | MLD | | +-------------------------+---------------------------------------+------------------+ |taddr | | ipv6_addr | | | / | | | | | | | | MLD | | +-------------------------+---------------------------------------+------------------+ |daddr | | ipv6_addr | | | | | +-------------------------+---------------------------------------+------------------+ TCP (TCP HEADER EXPRESSION) tcp {sport | dport | sequence | ackseq | doff | reserved | flags | window | checksum | urgptr} Table 45. TCP (TCP header expression) +-------------------------+--------------------------+------------------+ | | | | +-------------------------+--------------------------+------------------+ |sport | | inet_service | | | | | +-------------------------+--------------------------+------------------+ |dport | | inet_service | | | | | +-------------------------+--------------------------+------------------+ |sequence | | integer (32 bit) | | | | | +-------------------------+--------------------------+------------------+ |ackseq | | integer (32 bit) | | | | | | | | | | | (Acknowledgement number) | | +-------------------------+--------------------------+------------------+ |doff | | integer (4 bit) | | | (Data | FIXME scaling | | | offset) | | +-------------------------+--------------------------+------------------+ |reserved | | integer (4 bit) | | | | | +-------------------------+--------------------------+------------------+ |flags | | tcp_flag | | | TCP | | +-------------------------+--------------------------+------------------+ |window | | integer (16 bit) | | | (Window) | | +-------------------------+--------------------------+------------------+ |checksum | | integer (16 bit) | +-------------------------+--------------------------+------------------+ |urgptr | | integer (16 bit) | | | (Urgent | | | | pointer) | | +-------------------------+--------------------------+------------------+ udp {sport | dport | length | checksum} Table 46. UDP (UDP header expression) +-------------------------+-----------------------+------------------+ | | | | +-------------------------+-----------------------+------------------+ |sport | | inet_service | | | | | +-------------------------+-----------------------+------------------+ |dport | | inet_service | | | | | +-------------------------+-----------------------+------------------+ |length | | integer (16 bit) | | | | | +-------------------------+-----------------------+------------------+ |checksum | | integer (16 bit) | +-------------------------+-----------------------+------------------+ UDP-LITE (UDP-LITE HEADER EXPRESSION) udplite {sport | dport | checksum} Table 47. UDP-Lite (UDP-Lite header expression) +-------------------------+-----------------------+------------------+ | | | | +-------------------------+-----------------------+------------------+ |sport | | inet_service | | | | | +-------------------------+-----------------------+------------------+ |dport | | inet_service | | | | | +-------------------------+-----------------------+------------------+ |checksum | | integer (16 bit) | +-------------------------+-----------------------+------------------+ SCTP (SCTP HEADER EXPRESSION) sctp {sport | dport | vtag | checksum} sctp chunk CHUNK [ FIELD ] CHUNK := data | init | init-ack | sack | heartbeat | heartbeat-ack | abort | shutdown | shutdown-ack | error | cookie-echo | cookie-ack | ecne | cwr | shutdown-complete | asconf-ack | forward-tsn | asconf FIELD := COMMON_FIELD | DATA_FIELD | INIT_FIELD | INIT_ACK_FIELD | SACK_FIELD | SHUTDOWN_FIELD | ECNE_FIELD | CWR_FIELD | ASCONF_ACK_FIELD | FORWARD_TSN_FIELD | ASCONF_FIELD COMMON_FIELD := type | flags | length DATA_FIELD := tsn | stream | ssn | ppid INIT_FIELD := init-tag | a-rwnd | num-outbound-streams | num-inbound-streams | initial-tsn INIT_ACK_FIELD := INIT_FIELD SACK_FIELD := cum-tsn-ack | a-rwnd | num-gap-ack-blocks | num-dup-tsns SHUTDOWN_FIELD := cum-tsn-ack ECNE_FIELD := lowest-tsn CWR_FIELD := lowest-tsn ASCONF_ACK_FIELD := seqno FORWARD_TSN_FIELD := new-cum-tsn ASCONF_FIELD := seqno Table 48. SCTP (SCTP header expression) +-------------------------+--------------------------------+--------------------------------+ | | | | +-------------------------+--------------------------------+--------------------------------+ |sport | | inet_service | +-------------------------+--------------------------------+--------------------------------+ |dport | | inet_service | +-------------------------+--------------------------------+--------------------------------+ |vtag | | integer (32 bit) | | | | | | | (Verification Tag) | | +-------------------------+--------------------------------+--------------------------------+ |checksum | | integer (32 bit) | +-------------------------+--------------------------------+--------------------------------+ |chunk | chunk | FIELD | | | | | | | | | | | | | +-------------------------+--------------------------------+--------------------------------+ Table 49. chunk SCTP (SCTP chunk fields) +---------------------+------------------+-----------------+-----------------------------------+ | | | Chunk | | | | | | | +---------------------+------------------+-----------------+-----------------------------------+ |type | 8 | all | | | | | | | | | | | chunk | | | | | | +---------------------+------------------+-----------------+-----------------------------------+ |flags | 8 | all | | | | | | chunk | | | | | | | | | | | +---------------------+------------------+-----------------+-----------------------------------+ |length | 16 | all | chunk | | | | | | | | | | padding | +---------------------+------------------+-----------------+-----------------------------------+ |tsn | 32 | data | | | | | | (Transmission | | | | | Sequence Number) | +---------------------+------------------+-----------------+-----------------------------------+ |stream | 16 | data | | | | | | (Stream identifier) | +---------------------+------------------+-----------------+-----------------------------------+ |ssn | 16 | data | | | | | | (Stream sequence | | | | | number) | +---------------------+------------------+-----------------+-----------------------------------+ |ppid | 32 | data | | | | | | | | | | | (Payload protocol | | | | | identifier) | +---------------------+------------------+-----------------+-----------------------------------+ |init-tag | 32 | init, init-ack | (Initiate | | | | | tag) | +---------------------+------------------+-----------------+-----------------------------------+ |a-rwnd | 32 | init, init-ack, | | | | | sack | | | | | | | | | | | | | | | | (Advertised receiver window | | | | | credit) | +---------------------+------------------+-----------------+-----------------------------------+ |num-outbound-streams | 16 | init, init-ack | | | | | | | | | | | | +---------------------+------------------+-----------------+-----------------------------------+ |num-inbound-streams | 16 | init, init-ack | | | | | | | | | | | | +---------------------+------------------+-----------------+-----------------------------------+ |initial-tsn | 32 | init, init-ack | | | | | | | | | | | (Initial transmit | | | | | sequence number) | +---------------------+------------------+-----------------+-----------------------------------+ |cum-tsn-ack | 32 | sack, shutdown | | | | | | | | | | | | | | | | | | | | | (Cumulative TSN acknowledged) | +---------------------+------------------+-----------------+-----------------------------------+ |num-gap-ack-blocks | 16 | sack | | | | | | Gap Ack | | | | | | +---------------------+------------------+-----------------+-----------------------------------+ |num-dup-tsns | 16 | sack | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------------------+------------------+-----------------+-----------------------------------+ |lowest-tsn | 32 | ecne, cwr | | | | | | | | | | | | +---------------------+------------------+-----------------+-----------------------------------+ |seqno | 32 | asconf-ack, | | | | | asconf | (Sequence number) | +---------------------+------------------+-----------------+-----------------------------------+ |new-cum-tsn | 32 | forward-tsn | | | | | | | | | | | | +---------------------+------------------+-----------------+-----------------------------------+ DCCP (DCCP HEADER EXPRESSION) dccp {sport | dport | type} Table 50. DCCP (DCCP header expression) +-------------------------+-----------------------+--------------+ | | | | +-------------------------+-----------------------+--------------+ |sport | | inet_service | | | | | +-------------------------+-----------------------+--------------+ |dport | | inet_service | | | | | +-------------------------+-----------------------+--------------+ |type | | dccp_pkttype | | | | | +-------------------------+-----------------------+--------------+ (AUTHENTICATION HEADER EXPRESSION) ah {nexthdr | hdrlength | reserved | spi | sequence} Table 51. AH (AH header expression) +-------------------------+-----------------------+------------------+ | | | | +-------------------------+-----------------------+------------------+ |nexthdr | | inet_proto | | | | | | | | | +-------------------------+-----------------------+------------------+ |hdrlength | | integer (8 bit) | | | AH | | +-------------------------+-----------------------+------------------+ |reserved | | integer (16 bit) | | | | | +-------------------------+-----------------------+------------------+ |spi | | integer (32 bit) | | | | | | | | | | | (Security Parameter | | | | Index) | | +-------------------------+-----------------------+------------------+ |sequence | | integer (32 bit) | | | | | +-------------------------+-----------------------+------------------+ (ENCRYPTED SECURITY PAYLOAD HEADER EXPRESSION) esp {spi | sequence} Table 52. ESP (ESP header expression) +-------------------------+-----------------------+------------------+ | | | | +-------------------------+-----------------------+------------------+ |spi | | integer (32 bit) | | | | | | | | | | | (Security Parameter | | | | Index) | | +-------------------------+-----------------------+------------------+ |sequence | | integer (32 bit) | | | | | +-------------------------+-----------------------+------------------+ IPCOMP (IPCOMP HEADER EXPRESSION) comp {nexthdr | flags | cpi} Table 53. IPComp (IPComp header expression) +-------------------------+--------------------------------+------------------+ | | | | +-------------------------+--------------------------------+------------------+ |nexthdr | | inet_proto | | | | | +-------------------------+--------------------------------+------------------+ |flags | | bitmask | +-------------------------+--------------------------------+------------------+ |cpi | | integer (16 bit) | | | | | | | | | | | (compression Parameter Index) | | +-------------------------+--------------------------------+------------------+ GRE (GRE HEADER EXPRESSION) gre {flags | version | protocol} gre ip {version | hdrlength | dscp | ecn | length | id | frag-off | ttl | protocol | checksum | saddr | daddr } gre ip6 {version | dscp | ecn | flowlabel | length | nexthdr | hoplimit | saddr | daddr} gre gre . IPv4 IPv6 gre . Table 54. GRE (GRE header expression) +-------------------------+--------------------------------+------------------+ | | | | +-------------------------+--------------------------------+------------------+ |flags | | integer (5 bit) | | | checksum routing key | | | | sequence strict source | | | | route | | +-------------------------+--------------------------------+------------------+ |version | | integer (3 bit) | | | gre 0 | | | | GRE | | | | 1 | | | | PPTP | | +-------------------------+--------------------------------+------------------+ |protocol | EtherType | integer (16 bit) | | | | | | | | | +-------------------------+--------------------------------+------------------+ IPv4 gre. netdev filter ingress gre ip daddr 9.9.9.9 counter GENEVE (GENEVE HEADER EXPRESSION) geneve {vni | flags} geneve ether {daddr | saddr | type} geneve vlan {id | dei | pcp | type} geneve ip {version | hdrlength | dscp | ecn | length | id | frag-off | ttl | protocol | checksum | saddr | daddr } geneve ip6 {version | dscp | ecn | flowlabel | length | nexthdr | hoplimit | saddr | daddr} geneve tcp {sport | dport | sequence | ackseq | doff | reserved | flags | window | checksum | urgptr} geneve udp {sport | dport | length | checksum} geneve geneve . geneve udp . udp ( 6081 IANA). Table 55. GENEVE (GENEVE header expression) +-------------------------+--------------------------------+------------------+ | | | | +-------------------------+--------------------------------+------------------+ |protocol | EtherType | integer (16 bit) | | | | | | | | | +-------------------------+--------------------------------+------------------+ |vni | | integer (24 bit) | | | (Virtual | | | | Network ID - VNI) | | +-------------------------+--------------------------------+------------------+ TCP geneve. netdev filter ingress udp dport 4789 geneve tcp dport 80 counter GRETAP (GRETAP HEADER EXPRESSION) gretap {vni | flags} gretap ether {daddr | saddr | type} gretap vlan {id | dei | pcp | type} gretap ip {version | hdrlength | dscp | ecn | length | id | frag-off | ttl | protocol | checksum | saddr | daddr } gretap ip6 {version | dscp | ecn | flowlabel | length | nexthdr | hoplimit | saddr | daddr} gretap tcp {sport | dport | sequence | ackseq | doff | reserved | flags | window | checksum | urgptr} gretap udp {sport | dport | length | checksum} gretap gre . gre gre . TCP gretap. netdev filter ingress gretap tcp dport 80 counter VXLAN (VXLAN HEADER EXPRESSION) vxlan {vni | flags} vxlan ether {daddr | saddr | type} vxlan vlan {id | dei | pcp | type} vxlan ip {version | hdrlength | dscp | ecn | length | id | frag-off | ttl | protocol | checksum | saddr | daddr } vxlan ip6 {version | dscp | ecn | flowlabel | length | nexthdr | hoplimit | saddr | daddr} vxlan tcp {sport | dport | sequence | ackseq | doff | reserved | flags | window | checksum | urgptr} vxlan udp {sport | dport | length | checksum} vxlan vxlan . vxlan udp . udp ( 4789 IANA). Table 56. VXLAN (VXLAN header expression) +-------------------------+-----------------------+------------------+ | | | | +-------------------------+-----------------------+------------------+ |flags | | integer (8 bit) | | | vxlan | | +-------------------------+-----------------------+------------------+ |vni | | integer (24 bit) | | | | | | | | | | | (Virtual Network ID - | | | | VNI) | | +-------------------------+-----------------------+------------------+ TCP vxlan. netdev filter ingress udp dport 4789 vxlan tcp dport 80 counter (RAW PAYLOAD EXPRESSION) @base,offset,length (Raw payload) length offset . 0 -- C (topmost bit) 0x80 . . nft . 5 meta l4proto 5 . Table 57. (Supported payload protocol bases) +--------------------+----------------------------+ | (Base) | | +--------------------+----------------------------+ |ll | | | | (Link | | | layer) | | | | | | | +--------------------+----------------------------+ |nh | | | | (Network header) | | | | | | IPv4 IPv6 | +--------------------+----------------------------+ |th | | | | | | | (Transport Header) | | | | | | TCP | +--------------------+----------------------------+ |ih | | | | / | | | (Inner Header / | | | Payload) | | | | | | | | | L4 | +--------------------+----------------------------+ UDP TCP. inet filter input meta l4proto {tcp, udp} @th,16,16 { 53, 80 } inet filter input meta l4proto {tcp, udp} th dport { 53, 80 } . . SPI ESP . arp . input meta iifname enp2s0 arp ptype 0x0800 arp htype 1 arp hlen 6 arp plen 4 @nh,192,32 0xc0a88f10 @nh,144,48 set 0x112233445566 accept (EXTENSION HEADER EXPRESSIONS) IPv6 TCP IPv4 . nftables () IPv6 TCP IPv4 . hbh {nexthdr | hdrlength} frag {nexthdr | frag-off | more-fragments | id} rt {nexthdr | hdrlength | type | seg-left} dst {nexthdr | hdrlength} mh {nexthdr | hdrlength | checksum | type} srh {flags | tag | sid | seg-left} tcp option {eol | nop | maxseg | window | sack-perm | sack | sack0 | sack1 | sack2 | sack3 | timestamp | mptcp } tcp_option_field ip option { lsrr | ra | rr | ssrr } ip_option_field : exthdr {hbh | frag | rt | dst | mh} tcp option {eol | nop | maxseg | window | sack-perm | sack | sack0 | sack1 | sack2 | sack3 | timestamp | mptcp } ip option { lsrr | ra | rr | ssrr } dccp option dccp_option_type Table 58. IPv6 (IPv6 extension headers) +-------------------------+---------------------------------+ | | | +-------------------------+---------------------------------+ |hbh | | | | (Hop by Hop) | +-------------------------+---------------------------------+ |rt | | | | | | | (Routing Header) | +-------------------------+---------------------------------+ |frag | | | | | | | (Fragmentation header) | +-------------------------+---------------------------------+ |dst | | | | (dst options) | +-------------------------+---------------------------------+ |mh | | | | / | | | (Mobility Header) | +-------------------------+---------------------------------+ |srh | | | | | | | (Segment Routing | | | Header) | +-------------------------+---------------------------------+ Table 59. TCP (TCP Options) +-------------------------+--------------------------------+-----------------------+ | | | | | | | TCP | +-------------------------+--------------------------------+-----------------------+ |eol | | - | | | (End | | | | of option list) | | +-------------------------+--------------------------------+-----------------------+ |nop | | - | | | | | | | TCP Nop | | +-------------------------+--------------------------------+-----------------------+ |maxseg | | length, size | | | | | | | TCP (TCP | | | | Maximum Segment Size) | | +-------------------------+--------------------------------+-----------------------+ |window | | length, count | | | TCP (TCP | | | | Window Scaling) | | +-------------------------+--------------------------------+-----------------------+ |sack-perm | | length | | | | | | | TCP (TCP | | | | SACK permitted) | | +-------------------------+--------------------------------+-----------------------+ |sack | | length, left, right | | | | | | | TCP | | | | ( | | | | ) | | +-------------------------+--------------------------------+-----------------------+ |sack0 | | length, left, right | | | | | | | TCP | | | | ( ) | | +-------------------------+--------------------------------+-----------------------+ |sack1 | | length, left, right | | | | | | | TCP | | | | ( ) | | +-------------------------+--------------------------------+-----------------------+ |sack2 | | length, left, right | | | | | | | TCP | | | | ( ) | | +-------------------------+--------------------------------+-----------------------+ |sack3 | | length, left, right | | | | | | | TCP | | | | ( ) | | +-------------------------+--------------------------------+-----------------------+ |timestamp | | length, tsval, tsecr | | | TCP (TCP | | | | Timestamps) | | +-------------------------+--------------------------------+-----------------------+ |mptcp | TCP | subtype | | | | | | | (Multipath TCP) | | +-------------------------+--------------------------------+-----------------------+ nft describe tcp option keyword [ fieldname ] . TCP : tcp option tcp option @number,offset,length Table 60. IP (IP Options) +-------------------------+--------------------------+-----------------------+ | | | | | | | IP | +-------------------------+--------------------------+-----------------------+ |lsrr | | length, ptr, addr | | | | | | | (Loose | | | | Source Route) | | +-------------------------+--------------------------+-----------------------+ |ra | | length, value | | | | | | | (Router Alert) | | +-------------------------+--------------------------+-----------------------+ |rr | | length, ptr, addr | | | (Record Route) | | +-------------------------+--------------------------+-----------------------+ |ssrr | | length, ptr, addr | | | | | | | (Strict | | | | Source Route) | | +-------------------------+--------------------------+-----------------------+ TCP (finding TCP options). filter input tcp option sack-perm exists counter TCP (matching TCP options). filter input tcp option maxseg size lt 536 IPv6 (matching IPv6 exthdr). ip6 filter input frag more-fragments 1 counter IP (finding IP option). filter input ip option lsrr exists counter DCCP (finding DCCP option). filter input dccp option 40 exists counter (CONNTRACK EXPRESSIONS) . (conntrack) . conntrack conntrack . packets bytes avgpkt . (original) (reply) . zone zone zone . ct {state | direction | status | mark | expiration | helper | label | count | id} ct [original | reply] {l3proto | protocol | bytes | packets | avgpkt | zone} ct {original | reply} {proto-src | proto-dst} ct {original | reply} {ip | ip6} {saddr | daddr} conntrack CONNTRACK TYPES . Table 61. (Conntrack expressions) +-------------------------+-----------------------------+---------------------+ | | | | +-------------------------+-----------------------------+---------------------+ |state | | ct_state | | | | | +-------------------------+-----------------------------+---------------------+ |direction | | ct_dir | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |status | | ct_status | | | | | +-------------------------+-----------------------------+---------------------+ |mark | (mark) | mark | | | | | +-------------------------+-----------------------------+---------------------+ |expiration | | time | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |helper | | string | | | (Helper) | | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |label | | ct_label | | | | | | | | | | | | | | | | | | | | | | | connlabel.conf | | | | include | | | | | | | | nftables | | +-------------------------+-----------------------------+---------------------+ |l3proto | | nf_proto | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |saddr | | ipv4_addr/ipv6_addr | | | | | | | | | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |daddr | | ipv4_addr/ipv6_addr | | | | | | | | | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |protocol | | inet_proto | | | | | | | | | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |proto-src | | integer (16 bit) | | | | | | | | | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |proto-dst | | integer (16 bit) | | | | | | | | | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |packets | | integer (64 bit) | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |bytes | | integer (64 bit) | | | | | | | | | | | | | | | | | | | packets | | | | | | +-------------------------+-----------------------------+---------------------+ |avgpkt | | integer (64 bit) | | | | | | | | | | | | | | | | | | | packets | | | | | | +-------------------------+-----------------------------+---------------------+ |zone | | integer (16 bit) | | | | | | | (conntrack | | | | zone) | | +-------------------------+-----------------------------+---------------------+ |count | | integer (32 bit) | | | | | | | | | +-------------------------+-----------------------------+---------------------+ |id | | ct_id | | | | | +-------------------------+-----------------------------+---------------------+ (restrict the number of parallel connections to a server). nft add set filter ssh_flood '{ type ipv4_addr; flags dynamic; }' nft add rule filter input ct state new tcp dport 22 add @ssh_flood '{ ip saddr ct count over 2 }' reject (STATEMENTS) . ( ) . . . . (VERDICT STATEMENTS) . {accept | drop | continue | return} {jump | goto} CHAIN CHAIN := chain_name | { statement ... } accept drop -- . " (OVERALL EVALUATION OF THE RULESET)" . accept . (hook) ( ) . . accept forward forward ( ) postrouting (drop ). drop . . drop . jump CHAIN (call stack) CHAIN . CHAIN return . CHAIN ( ) . goto CHAIN jump . return (pop ) . ( goto ) ( ) . continue . . CHAIN (anonymous chain) (ad-hoc) . . : redirect dnat snat masquerade accept . reject synproxy drop . (side effects). : # process packets from eth0 and the internal network in from_lan # chain, drop all packets from eth0 with different source addresses. filter input iif eth0 ip saddr 192.168.0.0/24 jump from_lan filter input iif eth0 drop # jump and goto statements support anonymous chain creation filter input iif eth0 jump { ip saddr 192.168.0.0/24 drop ; udp dport domain drop; } (PAYLOAD STATEMENT) payload_expression set value . DSCP (diffserv) ip (flow labels) ipv6 . : # redirect tcp:http from 192.160.0.0/16 to local machine for routing instead of bridging # assumes 00:11:22:33:44:55 is local MAC address. bridge input meta iif eth0 ip saddr 192.168.0.0/16 tcp dport 80 meta pkttype set host ether daddr set 00:11:22:33:44:55 DSCP IPv4: ip forward ip dscp set 42 (EXTENSION HEADER STATEMENT) extension_header_expression set value . (TCP Maximum Segment Size TCP MSS) TCPMSS iptables . TCP MSS: tcp flags syn tcp option maxseg size set 1360 # set a size based on route information: tcp flags syn tcp option maxseg size set rt mtu tcp reset . tcp: tcp flags syn reset tcp option sack-perm (LOG STATEMENT) log [prefix quoted_string] [level syslog-level] [flags log-flags] log group nflog_group [prefix quoted_string] [queue-threshold value] [snaplen size] log level audit log . ( ) ( dmesg(1) syslog ) . ( nflog_group ) nfnetlink_log netlink . Netfilter ulogd(8) libnetfilter_log . ( level audit ) auditd audit . ( prefix flags) . . Table 62. log (log statement options) +----------------+--------------------------------+-----------------------------------+ | | | | | | | | +----------------+--------------------------------+-----------------------------------+ |prefix | | | | | | | | | | (quoted string) | +----------------+--------------------------------+-----------------------------------+ |level | | : emerg, alert, crit, | | | | err, warn | | | Syslog | [], notice, | | | | info, debug, audit | +----------------+--------------------------------+-----------------------------------+ |group | NFLOG | | | | | | | | | ( ) | | | | | +----------------+--------------------------------+-----------------------------------+ |snaplen | | | | | | | | | | ( ) | | | | | | | netlink | | +----------------+--------------------------------+-----------------------------------+ |queue-threshold | | | | | | | | | | ( ) | | | | | | | | | | | | | | | | | | | | | | | | | +----------------+--------------------------------+-----------------------------------+ Table 63. (log-flags) +-------------+-----------------------------+ | | | +-------------+-----------------------------+ |tcp sequence | | | | | | | TCP. | +-------------+-----------------------------+ |tcp options | | | | | | | | | | TCP. | +-------------+-----------------------------+ |ip options | | | | | | | | | | IP/IPv6. | +-------------+-----------------------------+ |skuid | | | | | | | (userid) | | | | | | | | | | | | . | +-------------+-----------------------------+ |ether | | | | | | | MAC . | +-------------+-----------------------------+ |all | | | | | | | | | | | | | | | | . | +-------------+-----------------------------+ log: # log the UID which generated the packet and ip options ip filter output log flags skuid flags ip options # log the tcp sequence numbers and tcp options from the TCP packet ip filter output log flags tcp sequence,options # enable all supported log flags ip6 filter output log flags all (REJECT STATEMENT) reject [ with REJECT_WITH ] REJECT_WITH := icmp icmp_reject_code | icmpv6 icmpv6_reject_code | icmpx icmpx_reject_code | tcp reset reject drop . ( " (OVERALL EVALUATION OF THE RULESET)" " (VERDICT STATEMENTS)" ). prerouting input forward output . Table 64. ICMP (Keywords may be used to reject when specifying the ICMP code) +-----------------+-----------------+ | | | | | | +-----------------+-----------------+ |net-unreachable | 0 | +-----------------+-----------------+ |host-unreachable | 1 | +-----------------+-----------------+ |prot-unreachable | 2 | +-----------------+-----------------+ |port-unreachable | 3 | +-----------------+-----------------+ |frag-needed | 4 | +-----------------+-----------------+ |net-prohibited | 9 | +-----------------+-----------------+ |host-prohibited | 10 | +-----------------+-----------------+ |admin-prohibited | 13 | +-----------------+-----------------+ Table 65. ICMPv6 (keywords may be used to reject when specifying the ICMPv6 code) +-----------------+-----------------+ | | | | | | +-----------------+-----------------+ |no-route | 0 | +-----------------+-----------------+ |admin-prohibited | 1 | +-----------------+-----------------+ |addr-unreachable | 3 | +-----------------+-----------------+ |port-unreachable | 4 | +-----------------+-----------------+ |policy-fail | 5 | +-----------------+-----------------+ |reject-route | 6 | +-----------------+-----------------+ ICMPvX ICMP ICMPv6 inet . Table 66. ICMPvX (keywords may be used when specifying the ICMPvX code) +-----------------+-----------------+ | | | | | | +-----------------+-----------------+ |no-route | 0 | +-----------------+-----------------+ |port-unreachable | 1 | +-----------------+-----------------+ |host-unreachable | 2 | +-----------------+-----------------+ |admin-prohibited | 3 | +-----------------+-----------------+ ICMP port-unreachable . bridge reject input prerouting . (COUNTER STATEMENT) . counter packets number bytes number counter { packets number | bytes number } (CONNTRACK STATEMENT) conntrack (conntrack mark) (conntrack labels) . ct {mark | event | label | zone} set value ct . (zone id) prerouting output ( ) raw (-300) . iptables (helper) raw helper conntrack -200 . Table 67. Conntrack (Conntrack statement types) +----------------+-----------------------+-----------------------------------+ | | | | | | | | +----------------+-----------------------+-----------------------------------+ |event | | | | | | ( | | | conntrack | ) | +----------------+-----------------------+-----------------------------------+ |helper | | | | | ct | | | | | (quoted string) | | | | | | | | | | | | | +----------------+-----------------------+-----------------------------------+ |mark | | mark | | | | | | | | | | | (Connection tracking | | | | mark) | | +----------------+-----------------------+-----------------------------------+ |label | | label | | | | | | | | | | | (Connection tracking | | | | label) | | +----------------+-----------------------+-----------------------------------+ |zone | | ( | | | conntrack | ) | +----------------+-----------------------+-----------------------------------+ nfmark conntrack: ct mark set meta mark : table inet raw { chain prerouting { type filter hook prerouting priority raw; ct zone set iif map { "eth1" : 1, "veth1" : 2 } } chain output { type filter hook output priority raw; ct zone set oif map { "eth1" : 1, "veth1" : 2 } } } ctnetlink: ct event set new,related,destroy (NOTRACK STATEMENT) notrack . notrack conntrack . prerouting output -300 (raw) . SYNPROXY (SYNPROXY STATEMENT) . (META STATEMENT) . : priority mark pkttype nftrace. meta {mark | priority | pkttype | nftrace | broute} set value . Table 68. (Meta statement types) +----------------+------------------------------+-----------------+ | | | | | | | | +----------------+------------------------------+-----------------+ |priority | | tc_handle | | | TC | | +----------------+------------------------------+-----------------+ |mark | | mark | | | (Packet mark) | | +----------------+------------------------------+-----------------+ |pkttype | | pkt_type | +----------------+------------------------------+-----------------+ |nftrace | / | 0, 1 | | | | | | | | | | | | | | | | | | | . | | | | | | | | | | | | | | | | | | | | monitor trace | | | | | | | | | | +----------------+------------------------------+-----------------+ |broute | / | 0, 1 | | | broute. | | | | | | | | | | | | (bridging) | | | | | | | | | | +----------------+------------------------------+-----------------+ (LIMIT STATEMENT) limit rate [over] packet_number / TIME_UNIT [burst packet_number packets] limit rate [over] byte_number BYTE_UNIT / TIME_UNIT [burst byte_number BYTE_UNIT] TIME_UNIT := second | minute | hour | day BYTE_UNIT := bytes | kbytes | mbytes (token bucket filter) . . log . over . burst (jitter tolerance) . limit burst . burst . limit burst . Table 69. limit (limit statement values) +----------------+-----------------------+-----------------+ | | | | +----------------+-----------------------+-----------------+ |packet_number | | | | | | | | | | | | | | | | | | ( | | | | ) | +----------------+-----------------------+-----------------+ |byte_number | | | | | | | | | | | | | | | | | | ( | | | | ) | +----------------+-----------------------+-----------------+ NAT (NAT STATEMENTS) snat [[ip | ip6] [ prefix ] to] TARGET_SPEC [FLAGS] dnat [[ip | ip6] [ prefix ] to] TARGET_SPEC [FLAGS] masquerade [to :PORT_SPEC] [FLAGS] redirect [to :PORT_SPEC] [FLAGS] TARGET_SPEC := ADDR_SPEC | [ADDR_SPEC] :PORT_SPEC ADDR_SPEC := address | address - address PORT_SPEC := port | port - port FLAGS := FLAG [, FLAGS] FLAG := persistent | random | fully-random nat nat . snat masquerade / . snat postrouting input masquerade postrouting . dnat redirect prerouting output / . nat . (mangle) . masquerade snat IP . (gateways) IP () . redirect dnat . (transparent proxy) (application-layer gateway) . TARGET_SPEC . . inet ( .) dnat snat ip ip6 . . nat prerouting postrouting netfilter . prefix n n . NAT . address dnat IPv4 ( 127.0.0.0/8) sysctl "net.ipv4.conf.*.route_localnet" . "martians" . . NAT (NAT statement values) +----------------+-----------------------------+---------------------+ | | | | +----------------+-----------------------------+---------------------+ |address | | ipv4_addr, | | | | ipv6_addr, e.g. | | | | abcd::1234, or you | | | / | can use a mapping, | | | | e.g. meta mark map | | | | { 10 : 192.168.1.2, | | | . | 20 : 192.168.1.3 } | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | . | | +----------------+-----------------------------+---------------------+ |port | | | | | | | | | | ( | | | / | ) | | | | | | | | | | | . | | +----------------+-----------------------------+---------------------+ . NAT (NAT statement flags) +-------------+-----------------------------------------+ | | | +-------------+-----------------------------------------+ |persistent | | | | / | | | | | | | | | . | +-------------+-----------------------------------------+ |random | . | | | | | | fully-random . | | | | | | | | | | | | | | | MD5 | | | | | | (seeded) | | | | | | | | | | | | . | +-------------+-----------------------------------------+ |fully-random | | | | | | | | | | | | | | | | | | | | | | . | +-------------+-----------------------------------------+ NAT. # / add table nat add chain nat prerouting { type nat hook prerouting priority dstnat; } add chain nat postrouting { type nat hook postrouting priority srcnat; } # eth0 1.2.3.4 add rule nat postrouting oif eth0 snat to 1.2.3.4 # eth0 192.168.1.120 add rule nat prerouting iif eth0 dnat to 192.168.1.120 # eth0 # add rule nat postrouting oif eth0 masquerade # TCP 22 2222 add rule nat prerouting tcp dport 22 redirect to :2222 # inet: # ip dnat: add rule inet nat prerouting dnat ip to 10.0.2.99 # ip6 dnat: add rule inet nat prerouting dnat ip6 to fe80::dead # ipv4 ipv6 masquerade : add rule inet nat postrouting meta oif ppp0 masquerade NAT. # 10.141.11.4 192.168.2.4 # 10.141.11.5 192.168.2.5 . add rule nat postrouting snat ip prefix to ip saddr map { 10.141.11.0/24 : 192.168.2.0/24 } # : add rule nat postrouting dnat to ip saddr . tcp dport map { 192.168.1.2 . 80 : 10.141.10.2-10.141.10.5 . 8888-8999 } # NAT : # # [ nat dnat ip addr_min reg 1 addr_max reg 10 proto_min reg 9 proto_max reg 11 ] # # : # IP () () IP () () # . (inclusive) . # : table ip nat { map ipportmap { typeof ip saddr : interval ip daddr . tcp dport flags interval elements = { 192.168.1.2 : 10.141.10.1-10.141.10.3 . 8888-8999, 192.168.2.0/24 : 10.141.11.5-10.141.11.20 . 8888-8999 } } chain prerouting { type nat hook prerouting priority dstnat; policy accept; ip protocol tcp dnat ip to ip saddr map @ipportmap } } @ipportmap . . . "interval" typeof . nftables - . ": ipv4_addr . inet_service" . ( ) . TPROXY (TPROXY STATEMENT) Tproxy . . Tproxy . tproxy to address:port tproxy to {address | :port} ip/ip6 . IP . tproxy {ip | ip6} to address[:port] tproxy to :port inet . ip/ip6 . address . port . . . tproxy (tproxy attributes) +----------+----------------------------+ | | | +----------+----------------------------+ |address | IP | | | | | | | | | | | | IP_TRANSPARENT | | | (bind) | | | . | +----------+----------------------------+ |port | | | | | | | | | | | | | IP_TRANSPARENT | | | (bind) | | | . | +----------+----------------------------+ tproxy. table ip x { chain y { type filter hook prerouting priority mangle; policy accept; tcp dport ntp tproxy to 1.1.1.1 accept udp dport ssh tproxy to :2222 accept } } table ip6 x { chain y { type filter hook prerouting priority mangle; policy accept; tcp dport ntp tproxy to [dead::beef] accept udp dport ssh tproxy to :2222 accept } } table inet x { chain y { type filter hook prerouting priority mangle; policy accept; tcp dport 321 tproxy to :22 accept tcp dport 99 tproxy ip to 1.1.1.1:999 accept udp dport 155 tproxy ip6 to [dead::beef]:smux accept } } tproxy (non-terminal) . (mark) (policy routing) . tproxy (logging) . table inet x { chain y { type filter hook prerouting priority mangle; policy accept; udp dport 9999 goto { tproxy to :1234 log prefix "packet tproxied: " meta mark set 1 accept log prefix "no socket on port 1234 or not transparent?: " drop } } } (forward) . . . ip rule add fwmark 1 lookup 100 ip route add local 0.0.0.0/0 dev lo table 100 TPROXY iptables (terminal) . tproxy (verdict) . SYNPROXY (SYNPROXY STATEMENT) TCP (TCP three-way-handshake) netfilter (backend) . (connection tracking) (sequence numbers) . synproxy [mss mss_value] [wscale wscale_value] [SYNPROXY_FLAGS] . synproxy (synproxy statement attributes) +----------+------------------------------+ | | | +----------+------------------------------+ |mss | | | | | | | (Maximum | | | segment size) | | | | | | | | | . | | | | | | | | | | | | | | | | | | . | +----------+------------------------------+ |wscale | | | | (Window | | | scale) | | | | | | | | | . | | | | | | | | | | | | | | | | | | . | +----------+------------------------------+ . synproxy (synproxy statement flags) +----------+-----------------------------------+ | | | +----------+-----------------------------------+ |sack-perm | | | | | | | (selective | | | acknowledgement) | | | | | | | | | ( | | | | | | | | | ). | +----------+-----------------------------------+ |timestamp | | | | | | | (timestamp) | | | | | | ( | | | | | | | | | | | | | | | | | | | | | | | | | | | ). | +----------+-----------------------------------+ synproxy. tcp tcpdump -pni eth0 -c 1 'tcp[tcpflags] == (tcp-syn|tcp-ack) && port 80' & telnet 192.0.2.42 80 18:57:24.693307 IP 192.0.2.42.80 > 192.0.2.43.48757: Flags [S.], seq 360414582, ack 788841994, win 14480, options [mss 1460,sackOK, TS val 1409056151 ecr 9690221, nop,wscale 9], length 0 tcp_loose conntrack INVALID . echo 0 > /proc/sys/net/netfilter/nf_conntrack_tcp_loose (untracked) SYN. table ip x { chain y { type filter hook prerouting priority raw; policy accept; tcp flags syn notrack } } UNTRACKED ( SYN) INVALID ( 3WHS ACK) SYNPROXY. SYN syncookies SYN+ACK ( 3WHS ACK) ESTABLISHED . 3WHS ( SYN+FIN SYN+ACK). SYNPROXY . table ip x { chain z { type filter hook input priority filter; policy accept; ct state invalid, untracked synproxy mss 1460 wscale 9 timestamp sack-perm ct state invalid drop } } (FLOW STATEMENT) flow (bypass) . flowtable (offload) . flow add @flowtable (QUEUE STATEMENT) nfnetlink_queue (userspace) . . . drop accept . accept queue. libnetfilter_queue . queue [flags QUEUE_FLAGS] [to queue_number] queue [flags QUEUE_FLAGS] [to queue_number_from - queue_number_to] queue [flags QUEUE_FLAGS] [to QUEUE_EXPRESSION ] QUEUE_FLAGS := QUEUE_FLAG [, QUEUE_FLAGS] QUEUE_FLAG := bypass | fanout QUEUE_EXPRESSION := numgen | hash | symhash | MAP STATEMENT QUEUE_EXPRESSION hash numgen . map ip . . queue (queue statement values) +------------------+-----------------------+------------------+ | | | | +------------------+-----------------------+------------------+ |queue_number | | unsigned integer | | | | (16 bit) | | | | | | | | | | | | | | | | | | | 0 . | | +------------------+-----------------------+------------------+ |queue_number_from | | unsigned integer | | | | (16 bit) | | | | | | | | | | | | | | | | | | | fanout | | | | | | | | . | | +------------------+-----------------------+------------------+ |queue_number_to | | unsigned integer | | | | (16 bit) | | | | | | | | | | | | | | | | | | | fanout | | | | | | | | . | | +------------------+-----------------------+------------------+ . queue (queue statement flags) +----------+-----------------------------+ | | | +----------+-----------------------------+ |bypass | | | | | | | | | | | | | | | | | | | | | | ( | | | ) | | | | | | | | | | | | | | | . | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | libnetfilter_queue | | | | | | . | +----------+-----------------------------+ |fanout | | | | | | | | | | . | +----------+-----------------------------+ (DUP STATEMENT) dup . dup to device dup to address device device . Dup (Dup statement values) +----------------+-----------------------+---------------------+ | | | | +----------------+-----------------------+---------------------+ |address | | ipv4_addr, | | | | ipv6_addr, e.g. | | | | abcd::1234, or you | | | | can use a mapping, | | | | e.g. ip saddr map { | | | | 192.168.1.2 : | | | | 10.1.1.1 } | | | | | | | (gateway) | | | | | | | | | | | | . | | +----------------+-----------------------+---------------------+ |device | | string | | | | | | | | | | | | | | | | | | | device | | | | | | | | . | | +----------------+-----------------------+---------------------+ dup. # ip 10.2.3.4 eth0 ip filter forward dup to 10.2.3.4 device "eth0" # netdev ingress dup to "eth0" dup to "eth0" # dup to ip daddr map { 192.168.7.1 : "eth0", 192.168.7.2 : "eth1" } (FWD STATEMENT) fwd . ingress egress netdev . dup . (next hop) . MAC . ttl IP . fib ( - forwarding information base) . fwd to device fwd [ip | ip6] to address device device fwd. # netdev ingress fwd to "eth0" # 192.168.200.1 eth0 netdev ingress ether saddr set fwd ip to 192.168.200.1 device "eth0" (SET STATEMENT) set (set) . setname dynamic timeout . set (stateful object) dynamic . (timeout) timeout set . ( ) ( ). set (dynamic blacklists) . (maps) . add update () : . {add | update} @setname { expression [timeout timeout] [comment string] } . # "filter" "ip". # . # # . nft add set ip filter blackhole \ "{ type ipv4_addr; flags dynamic; timeout 1m; size 65536; }" # saddr. # blackhole nft add set ip filter flood \ "{ type ipv4_addr; flags dynamic; timeout 10s; size 128000; }" # . nft add rule ip filter input meta iifname "internal" accept # ip . nft add rule ip filter input ip saddr @blackhole counter drop # ip tcp # ip . nft add rule ip filter input tcp flags syn tcp dport ssh \ add @flood { ip saddr limit rate over 10/second } \ add @blackhole { ip saddr } \ drop # . nft list set ip filter flood nft list set ip filter blackhole # blackhole. nft add element filter blackhole { 10.2.3.4, 10.23.1.42 } (MAP STATEMENT) map . expression map { MAP_ELEMENTS } MAP_ELEMENTS := MAP_ELEMENT [, MAP_ELEMENTS] MAP_ELEMENT := key : value key expression . map. # DNAT TCP dport: # 80 192.168.1.100 # 8888 192.168.1.101 nft add rule ip nat prerouting dnat tcp dport map { 80 : 192.168.1.100, 8888 : 192.168.1.101 } # SNAT : # 192.168.1.0/24 10.0.0.1 # 192.168.2.0/24 10.0.0.2 nft add rule ip nat postrouting snat to ip saddr map { 192.168.1.0/24 : 10.0.0.1, 192.168.2.0/24 : 10.0.0.2 } (VMAP STATEMENT) (vmap) map (verdicts) . expression vmap { VMAP_ELEMENTS } VMAP_ELEMENTS := VMAP_ELEMENT [, VMAP_ELEMENTS] VMAP_ELEMENT := key : verdict vmap. # : nft add rule ip filter input ip protocol vmap { tcp : jump tcp-chain, udp : jump udp-chain , icmp : jump icmp-chain } XT (XT STATEMENT) xt xtables . (fallback) . xt TYPE NAME TYPE := match | target | watcher ( ) iptables-nft . : nftables . (ADDITIONAL COMMANDS) nft . (LIST HOOKS) nf_conntrack . list hooks [family] list hooks netdev [ device DEVICE_NAME ] list hooks . netdev . nft . : netfilter ip ip6. % nft list hooks inet family ip { hook prerouting { -0000000400 ipv4_conntrack_defrag [nf_defrag_ipv4] -0000000200 ipv4_conntrack_in [nf_conntrack] -0000000100 nf_nat_ipv4_pre_routing [nf_nat] } hook input { 0000000000 chain inet filter input [nf_tables] +0000000100 nf_nat_ipv4_local_in [nf_nat] [..] nat conntrack ipv4 (packet defragmentation) . priority identifier [module_name] . priority . . . nftables priority . . nftables . . module name . modinfo module name . CONFIG_NETFILTER_NETLINK_HOOK (builtin) . nfnetlink_hook . (MONITOR) monitor Netlink nf_tables . meta nftrace . nft JSON nft (stdout) . monitor [new | destroy] MONITOR_OBJECT monitor trace MONITOR_OBJECT := tables | chains | sets | rules | elements | ruleset MONITOR_OBJECT . new destroy . nftrace . ^C . nft. % nft monitor JSON. % nft -j monitor destroy rules nft. % nft monitor chains nft. % nft monitor ruleset 10.0.0.1. % nft add rule filter input ip saddr 10.0.0.1 meta nftrace set 1 % nft monitor trace (ERROR REPORTING) nft () (^) . (~) . nft . . :1:19-22: Error: Interface does not exist filter output oif eth0 ^^^^ . :1:28-36: Error: Right hand side of relational expression (==) must be constant filter output tcp dport == tcp dport ~~ ^^^^^^^^^ . :0:0-23: Error: Could not process rule: Operation not permitted filter output oif wlan0 ^^^^^^^^^^^^^^^^^^^^^^^ (EXIT STATUS) nft . Netlink . (SEE ALSO) libnftables(3), libnftables-json(5), iptables(8), ip6tables(8), arptables(8), ebtables(8), ip(8), tc(8) : https://wiki.nftables.org (AUTHORS) nftables Patrick McHardy Pablo Neira Ayuso Netfilter . (COPYRIGHT) (C) 2008-2014 Patrick McHardy (C) 2013-2018 Pablo Neira Ayuso nftables (GNU General Public License) / . - . (CC BY-SA 4.0) : http://creativecommons.org/licenses/by-sa/4.0. 09/01/2026 NFT(8)