Ubuntu Manpage: nft - Administration tool of the nftables framework for packet filtering and (2024)

Provided by: nftables_0.8.2-1_amd64 Ubuntu Manpage: nft - Administration tool of the nftables framework for packet filtering and (1)

NAME

 nft - Administration tool of the nftables framework for packet filtering and classification

SYNOPSIS

 nft [ -nNscae ] [ -I directory ] [ -f filename | -i | cmd ...] nft -h nft -v

DESCRIPTION

 nft is the command line tool used to set up, maintain and inspect packet filtering and classification rules in the Linux kernel, in the nftables framework. The Linux kernel subsystem is known as nf_tables, and 'nf' stands for Netfilter.

OPTIONS

 For a full summary of options, run nft --help. -h, --help Show help message and all options. -v, --version Show version. -n, --numeric Show data numerically. When used once (the default behaviour), skip lookup of addresses to symbolic names. Use twice to also show Internet services (port numbers) numerically. Use three times to also show protocols and UIDs/GIDs numerically. -N, --reversedns Translate IP addresses to names. Usually requires network traffic for DNS lookup. -s, --stateless Omit stateful information of rules and stateful objects. -c, --check Check commands validity without actually applying the changes. -a, --handle Show rule handles in output. -e, --echo When inserting items into the ruleset using add, insert or replace commands, print notifications just like nft monitor. -I, --includepath directory Add the directory directory to the list of directories to be searched for included files. This option may be specified multiple times. -f, --file filename Read input from filename. nft scripts must start #!/usr/sbin/nft -f -i, --interactive Read input from an interactive readline CLI.

INPUT FILE FORMAT

 LEXICAL CONVENTIONS Input is parsed line-wise. When the last character of a line, just before the newline character, is a non-quoted backslash (\), the next line is treated as a continuation. Multiple commands on the same line can be separated using a semicolon (;). A hash sign (#) begins a comment. All following characters on the same line are ignored. Identifiers begin with an alphabetic character (a-z,A-Z), followed zero or more alphanumeric characters (a-z,A-Z,0-9) and the characters slash (/), backslash (\), underscore (_) and dot (.). Identifiers using different characters or clashing with a keyword need to be enclosed in double quotes ("). INCLUDE FILES include filename Other files can be included by using the include statement. The directories to be searched for include files can be specified using the -I/--includepath option. You can override this behaviour either by prepending ./ to your path to force inclusion of files located in the current working directory (ie. relative path) or / for file location expressed as an absolute path. If -I/--includepath is not specified, then nft relies on the default directory that is specified at compile time. You can retrieve this default directory via -h/--help option. Include statements support the usual shell wildcard symbols (*,?,[]). Having no matches for an include statement is not an error, if wildcard symbols are used in the include statement. This allows having potentially empty include directories for statements like include "/etc/firewall/rules/*". The wildcard matches are loaded in alphabetical order. Files beginning with dot (.) are not matched by include statements. SYMBOLIC VARIABLES define variable expr $variable Symbolic variables can be defined using the define statement. Variable references are expressions and can be used initialize other variables. The scope of a definition is the current block and all blocks contained within. Using symbolic variables define int_if1 = eth0 define int_if2 = eth1 define int_ifs = { $int_if1, $int_if2 } filter input iif $int_ifs accept

ADDRESS FAMILIES

 Address families determine the type of packets which are processed. For each address family the kernel contains so called hooks at specific stages of the packet processing paths, which invoke nftables if rules for these hooks exist. ip IPv4 address family. ip6 IPv6 address family. inet Internet (IPv4/IPv6) address family. arp ARP address family, handling IPv4 ARP packets. bridge Bridge address family, handling packets which traverse a bridge device. netdev Netdev address family, handling packets from ingress. All nftables objects exist in address family specific namespaces, therefore all identifiers include an address family. If an identifier is specified without an address family, the ip family is used by default. IPV4/IPV6/INET ADDRESS FAMILIES The IPv4/IPv6/Inet address families handle IPv4, IPv6 or both types of packets. They contain five hooks at different packet processing stages in the network stack. IPv4/IPv6/Inet address family hooks ┌────────────┬──────────────────────────────────┐ │Hook │ Description │ ├────────────┼──────────────────────────────────┤ │prerouting │ All packets entering the system │ │ │ are processed by the prerouting │ │ │ hook. It is invoked before the │ │ │ routing process and is used for │ │ │ early filtering or changing │ │ │ packet attributes that affect │ │ │ routing. │ ├────────────┼──────────────────────────────────┤ │input │ Packets delivered to the local │ │ │ system are processed by the │ │ │ input hook. │ ├────────────┼──────────────────────────────────┤ │forward │ Packets forwarded to a different │ │ │ host are processed by the │ │ │ forward hook. │ ├────────────┼──────────────────────────────────┤ │output │ Packets sent by local processes │ │ │ are processed by the output │ │ │ hook. │ ├────────────┼──────────────────────────────────┤ │postrouting │ All packets leaving the system │ │ │ are processed by the postrouting │ │ │ hook. │ └────────────┴──────────────────────────────────┘ ARP ADDRESS FAMILY The ARP address family handles ARP packets received and sent by the system. It is commonly used to mangle ARP packets for clustering. ARP address family hooks ┌───────┬──────────────────────────────────┐ │Hook │ Description │ ├───────┼──────────────────────────────────┤ │input │ Packets delivered to the local │ │ │ system are processed by the │ │ │ input hook. │ ├───────┼──────────────────────────────────┤ │output │ Packets send by the local system │ │ │ are processed by the output │ │ │ hook. │ └───────┴──────────────────────────────────┘ BRIDGE ADDRESS FAMILY The bridge address family handles ethernet packets traversing bridge devices. The list of supported hooks is identical to IPv4/IPv6/Inet address families above. NETDEV ADDRESS FAMILY The Netdev address family handles packets from ingress. Netdev address family hooks ┌────────┬──────────────────────────────────┐ │Hook │ Description │ ├────────┼──────────────────────────────────┤ │ingress │ All packets entering the system │ │ │ are processed by this hook. It │ │ │ is invoked before layer 3 │ │ │ protocol handlers and it can be │ │ │ used for early filtering and │ │ │ policing. │ └────────┴──────────────────────────────────┘

RULESET

 {list | flush} ruleset [family] {export} [ruleset] {format} The ruleset keyword is used to identify the whole set of tables, chains, etc. currently in place in kernel. The following ruleset commands exist: list Print the ruleset in human-readable format. flush Clear the whole ruleset. Note that unlike iptables, this will remove all tables and whatever they contain, effectively leading to an empty ruleset - no packet filtering will happen anymore, so the kernel accepts any valid packet it receives. export Print the ruleset in machine readable format. The mandatory format parameter may be either xml or json. It is possible to limit list and flush to a specific address family only. For a list of valid family names, see ADDRESS FAMILIES above. Note that contrary to what one might assume, the output generated by export is not parseable by nft -f. Instead, the output of list command serves well for that purpose.

TABLES

 {add | delete | list | flush} table [family] table Tables are containers for chains, sets and stateful objects. They are identified by their address family and their name. The address family must be one of ip, ip6, inet, arp, bridge, netdev. The inet address family is a dummy family which is used to create hybrid IPv4/IPv6 tables. The meta expression nfproto keyword can be used to test which family (ipv4 or ipv6) context the packet is being processed in. When no address family is specified, ip is used by default. add Add a new table for the given family with the given name. delete Delete the specified table. list List all chains and rules of the specified table. flush Flush all chains and rules of the specified table.

CHAINS

 {add | create} chain [family] table chain [ { type type hook hook [device device] priority priority ; [policy policy ;] } ] {delete | list | flush} chain [family] table chain rename chain [family] table chain newname Chains are containers for rules. They exist in two kinds, base chains and regular chains. A base chain is an entry point for packets from the networking stack, a regular chain may be used as jump target and is used for better rule organization. add Add a new chain in the specified table. When a hook and priority value are specified, the chain is created as a base chain and hooked up to the networking stack. create Similar to the add command, but returns an error if the chain already exists. delete Delete the specified chain. The chain must not contain any rules or be used as jump target. rename Rename the specified chain. list List all rules of the specified chain. flush Flush all rules of the specified chain. For base chains, type, hook and priority parameters are mandatory. Supported chain types ┌───────┬──────────┬─────────────────────┬─────────────────────┐ │Type │ Families │ Hooks │ Description │ ├───────┼──────────┼─────────────────────┼─────────────────────┤ │filter │ all │ all │ Standard chain type │ │ │ │ │ to use in doubt. │ ├───────┼──────────┼─────────────────────┼─────────────────────┤ │nat │ ip, ip6 │ prerouting, input, │ Chains of this type │ │ │ │ output, postrouting │ perform Network │ │ │ │ │ Address Translation │ │ │ │ │ based on conntrack │ │ │ │ │ entries. Only the │ │ │ │ │ first packet of a │ │ │ │ │ connection actually │ │ │ │ │ traverses this │ │ │ │ │ chain - its rules │ │ │ │ │ usually define │ │ │ │ │ details of the │ │ │ │ │ created conntrack │ │ │ │ │ entry (NAT │ │ │ │ │ statements for │ │ │ │ │ instance). │ ├───────┼──────────┼─────────────────────┼─────────────────────┤ │route │ ip, ip6 │ output │ If a packet has │ │ │ │ │ traversed a chain │ │ │ │ │ of this type and is │ │ │ │ │ about to be │ │ │ │ │ accepted, a new │ │ │ │ │ route lookup is │ │ │ │ │ performed if │ │ │ │ │ relevant parts of │ │ │ │ │ the IP header have │ │ │ │ │ changed. This │ │ │ │ │ allows to e.g. │ │ │ │ │ implement policy │ │ │ │ │ routing selectors │ │ │ │ │ in nftables. │ └───────┴──────────┴─────────────────────┴─────────────────────┘ Apart from the special cases illustrated above (e.g. nat type not supporting forward hook or route type only supporting output hook), there are two further quirks worth noticing: • netdev family supports merely a single combination, namely filter type and ingress hook. Base chains in this family also require the device parameter to be present since they exist per incoming interface only. • arp family supports only input and output hooks, both in chains of type filter. The priority parameter accepts a signed integer value which specifies the order in which chains with same hook value are traversed. The ordering is ascending, i.e. lower priority values have precedence over higher ones. Base chains also allow to set the chain's policy, i.e. what happens to packets not explicitly accepted or refused in contained rules. Supported policy values are accept (which is the default) or drop.

RULES

 [add | insert] rule [family] table chain [position position] statement... replace rule [family] table chain handle handle statement... delete rule [family] table chain handle handle Rules are constructed from two kinds of components according to a set of grammatical rules: expressions and statements. add Add a new rule described by the list of statements. The rule is appended to the given chain unless a position is specified, in which case the rule is appended to the rule given by the position. insert Similar to the add command, but the rule is prepended to the beginning of the chain or before the rule at the given position. replace Similar to the add command, but the rule replaces the specified rule. delete Delete the specified rule.

SETS

 add set [family] table set { type type ; [flags flags ;] [timeout timeout ;] [gc-interval gc-interval ;] [elements = { element[,...] } ;] [size size ;] [policy policy ;] [auto- merge auto-merge ;] } {delete | list | flush} set [family] table set {add | delete} element [family] table set { element[,...] } Sets are elements containers of an user-defined data type, they are uniquely identified by an user-defined name and attached to tables. add Add a new set in the specified table. delete Delete the specified set. list Display the elements in the specified set. flush Remove all elements from the specified set. add element Comma-separated list of elements to add into the specified set. delete element Comma-separated list of elements to delete from the specified set. Set specifications ┌────────────┬──────────────────────────┬──────────────────────────┐ │Keyword │ Description │ Type │ ├────────────┼──────────────────────────┼──────────────────────────┤ │type │ data type of set │ string: ipv4_addr, │ │ │ elements │ ipv6_addr, ether_addr, │ │ │ │ inet_proto, │ │ │ │ inet_service, mark │ ├────────────┼──────────────────────────┼──────────────────────────┤ │flags │ set flags │ string: constant, │ │ │ │ interval, timeout │ ├────────────┼──────────────────────────┼──────────────────────────┤ │timeout │ time an element stays in │ string, decimal followed │ │ │ the set │ by unit. Units are: d, │ │ │ │ h, m, s │ ├────────────┼──────────────────────────┼──────────────────────────┤ │gc-interval │ garbage collection │ string, decimal followed │ │ │ interval, only available │ by unit. Units are: d, │ │ │ when timeout or flag │ h, m, s │ │ │ timeout are active │ │ ├────────────┼──────────────────────────┼──────────────────────────┤ │elements │ elements contained by │ set data type │ │ │ the set │ │ ├────────────┼──────────────────────────┼──────────────────────────┤ │size │ maximun number of │ unsigned integer (64 │ │ │ elements in the set │ bit) │ ├────────────┼──────────────────────────┼──────────────────────────┤ │policy │ set policy │ string: performance │ │ │ │ [default], memory │ ├────────────┼──────────────────────────┼──────────────────────────┤ │auto-merge │ automatic merge of │ │ │ │ adjacent/overlapping set │ │ │ │ elements (only for │ │ │ │ interval sets) │ │ └────────────┴──────────────────────────┴──────────────────────────┘

MAPS

 add map [family] table map { type type [flags flags ;] [elements = { element[,...] } ;] [size size ;] [policy policy ;] } {delete | list | flush} map [family] table map {add | delete} element [family] table map { elements = { element[,...] } ; } Maps store data based on some specific key used as input, they are uniquely identified by an user-defined name and attached to tables. add Add a new map in the specified table. delete Delete the specified map. list Display the elements in the specified map. flush Remove all elements from the specified map. add element Comma-separated list of elements to add into the specified map. delete element Comma-separated list of element keys to delete from the specified map. Map specifications ┌─────────┬──────────────────────────┬──────────────────────────┐ │Keyword │ Description │ Type │ ├─────────┼──────────────────────────┼──────────────────────────┤ │type │ data type of map │ string ':' string: │ │ │ elements │ ipv4_addr, ipv6_addr, │ │ │ │ ether_addr, inet_proto, │ │ │ │ inet_service, mark, │ │ │ │ counter, quota. Counter │ │ │ │ and quota can't be used │ │ │ │ as keys │ ├─────────┼──────────────────────────┼──────────────────────────┤ │flags │ map flags │ string: constant, │ │ │ │ interval │ ├─────────┼──────────────────────────┼──────────────────────────┤ │elements │ elements contained by │ map data type │ │ │ the map │ │ ├─────────┼──────────────────────────┼──────────────────────────┤ │size │ maximun number of │ unsigned integer (64 │ │ │ elements in the map │ bit) │ ├─────────┼──────────────────────────┼──────────────────────────┤ │policy │ map policy │ string: performance │ │ │ │ [default], memory │ └─────────┴──────────────────────────┴──────────────────────────┘

STATEFUL OBJECTS

 {add | delete | list | reset} type [family] table object Stateful objects are attached to tables and are identified by an unique name. They group stateful information from rules, to reference them in rules the keywords "type name" are used e.g. "counter name". add Add a new stateful object in the specified table. delete Delete the specified object. list Display stateful information the object holds. reset List-and-reset stateful object. CT ct helper helper { type type protocol protocol ; [l3proto family ;] } Ct helper is used to define connection tracking helpers that can then be used in combination with the "ct helper set" statement. type and protocol are mandatory, l3proto is derived from the table family by default, i.e. in the inet table the kernel will try to load both the ipv4 and ipv6 helper backends, if they are supported by the kernel. conntrack helper specifications ┌─────────┬──────────────────────────┬──────────────────────────┐ │Keyword │ Description │ Type │ ├─────────┼──────────────────────────┼──────────────────────────┤ │type │ name of helper type │ quoted string (e.g. │ │ │ │ "ftp") │ ├─────────┼──────────────────────────┼──────────────────────────┤ │protocol │ layer 4 protocol of the │ string (e.g. tcp) │ │ │ helper │ │ ├─────────┼──────────────────────────┼──────────────────────────┤ │l3proto │ layer 3 protocol of the │ address family (e.g. ip) │ │ │ helper │ │ └─────────┴──────────────────────────┴──────────────────────────┘ defining and assigning ftp helper 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 0; tcp dport 21 ct helper set "ftp-standard" } } COUNTER counter [packets bytes] Counter specifications ┌────────┬──────────────────────────┬──────────────────────────┐ │Keyword │ Description │ Type │ ├────────┼──────────────────────────┼──────────────────────────┤ │packets │ initial count of packets │ unsigned integer (64 │ │ │ │ bit) │ ├────────┼──────────────────────────┼──────────────────────────┤ │bytes │ initial count of bytes │ unsigned integer (64 │ │ │ │ bit) │ └────────┴──────────────────────────┴──────────────────────────┘ QUOTA quota [over | until] [used] Quota specifications ┌────────┬──────────────────────────┬──────────────────────────┐ │Keyword │ Description │ Type │ ├────────┼──────────────────────────┼──────────────────────────┤ │quota │ quota limit, used as the │ Two arguments, unsigned │ │ │ quota name │ interger (64 bit) and │ │ │ │ string: bytes, kbytes, │ │ │ │ mbytes. "over" and │ │ │ │ "until" go before these │ │ │ │ arguments │ ├────────┼──────────────────────────┼──────────────────────────┤ │used │ initial value of used │ Two arguments, unsigned │ │ │ quota │ interger (64 bit) and │ │ │ │ string: bytes, kbytes, │ │ │ │ mbytes │ └────────┴──────────────────────────┴──────────────────────────┘

EXPRESSIONS

 Expressions represent values, either constants like network addresses, port numbers etc. or data gathered from the packet during ruleset evaluation. Expressions can be combined using binary, logical, relational and other types of expressions to form complex or relational (match) expressions. They are also used as arguments to certain types of operations, like NAT, packet marking etc. Each expression has a data type, which determines the size, parsing and representation of symbolic values and type compatibility with other expressions. DESCRIBE COMMAND describe expression The describe command shows information about the type of an expression and its data type. The describe command $ nft describe tcp flags payload expression, datatype tcp_flag (TCP flag) (basetype bitmask, integer), 8 bits pre-defined symbolic constants: fin 0x01 syn 0x02 rst 0x04 psh 0x08 ack 0x10 urg 0x20 ecn 0x40 cwr 0x80

DATA TYPES

 Data types determine the size, parsing and representation of symbolic values and type compatibility of expressions. A number of global data types exist, in addition some expression types define further data types specific to the expression type. Most data types have a fixed size, some however may have a dynamic size, f.i. the string type. Types may be derived from lower order types, f.i. the IPv4 address type is derived from the integer type, meaning an IPv4 address can also be specified as an integer value. In certain contexts (set and map definitions) it is necessary to explicitly specify a data type. Each type has a name which is used for this. INTEGER TYPE ┌────────┬─────────┬──────────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├────────┼─────────┼──────────┼───────────┤ │Integer │ integer │ variable │ - │ └────────┴─────────┴──────────┴───────────┘ The integer type is used for numeric values. It may be specified as decimal, hexadecimal or octal number. The integer type doesn't have a fixed size, its size is determined by the expression for which it is used. BITMASK TYPE ┌────────┬─────────┬──────────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├────────┼─────────┼──────────┼───────────┤ │Bitmask │ bitmask │ variable │ integer │ └────────┴─────────┴──────────┴───────────┘ The bitmask type (bitmask) is used for bitmasks. STRING TYPE ┌───────┬─────────┬──────────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├───────┼─────────┼──────────┼───────────┤ │String │ string │ variable │ - │ └───────┴─────────┴──────────┴───────────┘ The string type is used to for character strings. A string begins with an alphabetic character (a-zA-Z) followed by zero or more alphanumeric characters or the characters /, -, _ and .. In addition anything enclosed in double quotes (") is recognized as a string. String specification # Interface name filter input iifname eth0 # Weird interface name filter input iifname "(eth0)" LINK LAYER ADDRESS TYPE ┌───────────────────┬─────────┬──────────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├───────────────────┼─────────┼──────────┼───────────┤ │Link layer address │ lladdr │ variable │ integer │ └───────────────────┴─────────┴──────────┴───────────┘ The link layer address type is used for link layer addresses. Link layer addresses are specified as a variable amount of groups of two hexadecimal digits separated using colons (:). Link layer address specification # Ethernet destination MAC address filter input ether daddr 20:c9:d0:43:12:d9 IPV4 ADDRESS TYPE ┌─────────────┬───────────┬────────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├─────────────┼───────────┼────────┼───────────┤ │IPv4 address │ ipv4_addr │ 32 bit │ integer │ └─────────────┴───────────┴────────┴───────────┘ The IPv4 address type is used for IPv4 addresses. Addresses are specified in either dotted decimal, dotted hexadecimal, dotted octal, decimal, hexadecimal, octal notation or as a host name. A host name will be resolved using the standard system resolver. IPv4 address specification # dotted decimal notation filter output ip daddr 127.0.0.1 # host name filter output ip daddr localhost IPV6 ADDRESS TYPE ┌─────────────┬───────────┬─────────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├─────────────┼───────────┼─────────┼───────────┤ │IPv6 address │ ipv6_addr │ 128 bit │ integer │ └─────────────┴───────────┴─────────┴───────────┘ The IPv6 address type is used for IPv6 addresses. FIXME IPv6 address specification # abbreviated loopback address filter output ip6 daddr ::1 BOOLEAN TYPE ┌────────┬─────────┬───────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├────────┼─────────┼───────┼───────────┤ │Boolean │ boolean │ 1 bit │ integer │ └────────┴─────────┴───────┴───────────┘ The boolean type is a syntactical helper type in user space. It's use is in the right- hand side of a (typically implicit) relational expression to change the expression on the left-hand side into a boolean check (usually for existence). The following keywords will automatically resolve into a boolean type with given value: ┌────────┬───────┐ │Keyword │ Value │ ├────────┼───────┤ │exists │ 1 │ ├────────┼───────┤ │missing │ 0 │ └────────┴───────┘ Boolean specification The following expressions support a boolean comparison: ┌───────────┬──────────────────────────────────┐ │Expression │ Behaviour │ ├───────────┼──────────────────────────────────┤ │fib │ Check route existence. │ ├───────────┼──────────────────────────────────┤ │exthdr │ Check IPv6 extension header │ │ │ existence. │ ├───────────┼──────────────────────────────────┤ │tcp option │ Check TCP option header │ │ │ existence. │ └───────────┴──────────────────────────────────┘ # match if route exists filter input fib daddr . iif oif 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 TYPE TYPE ┌──────────┬───────────┬───────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├──────────┼───────────┼───────┼───────────┤ │ICMP Type │ icmp_type │ 8 bit │ integer │ └──────────┴───────────┴───────┴───────────┘ The ICMP Type type is used to conveniently specify the ICMP header's type field. The following keywords may be used when specifying the ICMP type: ┌────────────────────────┬───────┐ │Keyword │ Value │ ├────────────────────────┼───────┤ │echo-reply │ 0 │ ├────────────────────────┼───────┤ │destination-unreachable │ 3 │ ├────────────────────────┼───────┤ │source-quench │ 4 │ ├────────────────────────┼───────┤ │redirect │ 5 │ ├────────────────────────┼───────┤ │echo-request │ 8 │ ├────────────────────────┼───────┤ │router-advertisem*nt │ 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 Type specification # match ping packets filter output icmp type { echo-request, echo-reply } ICMP CODE TYPE ┌──────────┬───────────┬───────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├──────────┼───────────┼───────┼───────────┤ │ICMP Code │ icmp_code │ 8 bit │ integer │ └──────────┴───────────┴───────┴───────────┘ The ICMP Code type is used to conveniently specify the ICMP header's code field. The following keywords may be used when specifying the ICMP code: ┌─────────────────┬───────┐ │Keyword │ Value │ ├─────────────────┼───────┤ │net-unreachable │ 0 │ ├─────────────────┼───────┤ │host-unreachable │ 1 │ ├─────────────────┼───────┤ │prot-unreachable │ 2 │ ├─────────────────┼───────┤ │port-unreachable │ 3 │ ├─────────────────┼───────┤ │net-prohibited │ 9 │ ├─────────────────┼───────┤ │host-prohibited │ 10 │ ├─────────────────┼───────┤ │admin-prohibited │ 13 │ └─────────────────┴───────┘ ICMPV6 TYPE TYPE ┌────────────┬─────────────┬───────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├────────────┼─────────────┼───────┼───────────┤ │ICMPv6 Type │ icmpv6_type │ 8 bit │ integer │ └────────────┴─────────────┴───────┴───────────┘ The ICMPv6 Type type is used to conveniently specify the ICMPv6 header's type field. The following keywords may be used when specifying the ICMPv6 type: ┌────────────────────────┬───────┐ │Keyword │ Value │ ├────────────────────────┼───────┤ │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 Type specification # match ICMPv6 ping packets filter output icmpv6 type { echo-request, echo-reply } ICMPV6 CODE TYPE ┌────────────┬─────────────┬───────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├────────────┼─────────────┼───────┼───────────┤ │ICMPv6 Code │ icmpv6_code │ 8 bit │ integer │ └────────────┴─────────────┴───────┴───────────┘ The ICMPv6 Code type is used to conveniently specify the ICMPv6 header's code field. The following keywords may be used when specifying the ICMPv6 code: ┌─────────────────┬───────┐ │Keyword │ Value │ ├─────────────────┼───────┤ │no-route │ 0 │ ├─────────────────┼───────┤ │admin-prohibited │ 1 │ ├─────────────────┼───────┤ │addr-unreachable │ 3 │ ├─────────────────┼───────┤ │port-unreachable │ 4 │ ├─────────────────┼───────┤ │policy-fail │ 5 │ ├─────────────────┼───────┤ │reject-route │ 6 │ └─────────────────┴───────┘ ICMPVX CODE TYPE ┌────────────┬────────────┬───────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├────────────┼────────────┼───────┼───────────┤ │ICMPvX Code │ icmpx_code │ 8 bit │ integer │ └────────────┴────────────┴───────┴───────────┘ The ICMPvX Code type abstraction is a set of values which overlap between ICMP and ICMPv6 Code types to be used from the inet family. The following keywords may be used when specifying the ICMPvX code: ┌─────────────────┬───────┐ │Keyword │ Value │ ├─────────────────┼───────┤ │no-route │ 0 │ ├─────────────────┼───────┤ │port-unreachable │ 1 │ ├─────────────────┼───────┤ │host-unreachable │ 2 │ ├─────────────────┼───────┤ │admin-prohibited │ 3 │ └─────────────────┴───────┘ CONNTRACK TYPES This is an overview of types used in ct expression and statement: ┌────────────────────┬───────────┬─────────┬───────────┐ │Name │ Keyword │ Size │ Base type │ ├────────────────────┼───────────┼─────────┼───────────┤ │conntrack state │ ct_state │ 4 byte │ bitmask │ ├────────────────────┼───────────┼─────────┼───────────┤ │conntrack direction │ ct_dir │ 8 bit │ integer │ ├────────────────────┼───────────┼─────────┼───────────┤ │conntrack status │ ct_status │ 4 byte │ bitmask │ ├────────────────────┼───────────┼─────────┼───────────┤ │conntrack event │ ct_event │ 4 byte │ bitmask │ │bits │ │ │ │ ├────────────────────┼───────────┼─────────┼───────────┤ │conntrack label │ ct_label │ 128 bit │ bitmask │ └────────────────────┴───────────┴─────────┴───────────┘ For each of the types above, keywords are available for convenience: conntrack state (ct_state) ┌────────────┬───────┐ │Keyword │ Value │ ├────────────┼───────┤ │invalid │ 1 │ ├────────────┼───────┤ │established │ 2 │ ├────────────┼───────┤ │related │ 4 │ ├────────────┼───────┤ │new │ 8 │ ├────────────┼───────┤ │untracked │ 64 │ └────────────┴───────┘ conntrack direction (ct_dir) ┌─────────┬───────┐ │Keyword │ Value │ ├─────────┼───────┤ │original │ 0 │ ├─────────┼───────┤ │reply │ 1 │ └─────────┴───────┘ conntrack status (ct_status) ┌───────────┬───────┐ │Keyword │ Value │ ├───────────┼───────┤ │expected │ 1 │ ├───────────┼───────┤ │seen-reply │ 2 │ ├───────────┼───────┤ │assured │ 4 │ ├───────────┼───────┤ │confirmed │ 8 │ ├───────────┼───────┤ │snat │ 16 │ ├───────────┼───────┤ │dnat │ 32 │ ├───────────┼───────┤ │dying │ 512 │ └───────────┴───────┘ conntrack event bits (ct_event) ┌──────────┬───────┐ │Keyword │ Value │ ├──────────┼───────┤ │new │ 1 │ ├──────────┼───────┤ │related │ 2 │ ├──────────┼───────┤ │destroy │ 4 │ ├──────────┼───────┤ │reply │ 8 │ ├──────────┼───────┤ │assured │ 16 │ ├──────────┼───────┤ │protoinfo │ 32 │ ├──────────┼───────┤ │helper │ 64 │ ├──────────┼───────┤ │mark │ 128 │ ├──────────┼───────┤ │seqadj │ 256 │ ├──────────┼───────┤ │secmark │ 512 │ ├──────────┼───────┤ │label │ 1024 │ └──────────┴───────┘ Possible keywords for conntrack label type (ct_label) are read at runtime from /etc/connlabel.conf.

PRIMARY EXPRESSIONS

 The lowest order expression is a primary expression, representing either a constant or a single datum from a packet's payload, meta data or a stateful module. META EXPRESSIONS meta {length | nfproto | l4proto | protocol | priority} [meta] {mark | iif | iifname | iiftype | oif | oifname | oiftype | skuid | skgid | nftrace | rtclassid | ibriport | obriport | pkttype | cpu | iifgroup | oifgroup | cgroup | random | secpath} A meta expression refers to meta data associated with a packet. There are two types of meta expressions: unqualified and qualified meta expressions. Qualified meta expressions require the meta keyword before the meta key, unqualified meta expressions can be specified by using the meta key directly or as qualified meta expressions. Meta expression types ┌──────────┬──────────────────────────┬───────────────────┐ │Keyword │ Description │ Type │ ├──────────┼──────────────────────────┼───────────────────┤ │length │ Length of the packet in │ integer (32 bit) │ │ │ bytes │ │ ├──────────┼──────────────────────────┼───────────────────┤ │nfproto │ real hook protocol │ integer (32 bit) │ │ │ family, useful only in │ │ │ │ inet table │ │ ├──────────┼──────────────────────────┼───────────────────┤ │protocol │ Ethertype protocol value │ ether_type │ ├──────────┼──────────────────────────┼───────────────────┤ │priority │ TC packet priority │ tc_handle │ ├──────────┼──────────────────────────┼───────────────────┤ │mark │ Packet mark │ mark │ ├──────────┼──────────────────────────┼───────────────────┤ │iif │ Input interface index │ iface_index │ ├──────────┼──────────────────────────┼───────────────────┤ │iifname │ Input interface name │ string │ ├──────────┼──────────────────────────┼───────────────────┤ │iiftype │ Input interface type │ iface_type │ ├──────────┼──────────────────────────┼───────────────────┤ │oif │ Output interface index │ iface_index │ ├──────────┼──────────────────────────┼───────────────────┤ │oifname │ Output interface name │ string │ ├──────────┼──────────────────────────┼───────────────────┤ │oiftype │ Output interface │ iface_type │ │ │ hardware type │ │ ├──────────┼──────────────────────────┼───────────────────┤ │skuid │ UID associated with │ uid │ │ │ originating socket │ │ ├──────────┼──────────────────────────┼───────────────────┤ │skgid │ GID associated with │ gid │ │ │ originating socket │ │ ├──────────┼──────────────────────────┼───────────────────┤ │rtclassid │ Routing realm │ realm │ ├──────────┼──────────────────────────┼───────────────────┤ │ibriport │ Input bridge interface │ string │ │ │ name │ │ ├──────────┼──────────────────────────┼───────────────────┤ │obriport │ Output bridge interface │ string │ │ │ name │ │ ├──────────┼──────────────────────────┼───────────────────┤ │pkttype │ packet type │ pkt_type │ ├──────────┼──────────────────────────┼───────────────────┤ │cpu │ cpu number processing │ integer (32 bits) │ │ │ the packet │ │ ├──────────┼──────────────────────────┼───────────────────┤ │iifgroup │ incoming device group │ devgroup │ ├──────────┼──────────────────────────┼───────────────────┤ │oifgroup │ outgoing device group │ devgroup │ ├──────────┼──────────────────────────┼───────────────────┤ │cgroup │ control group id │ integer (32 bits) │ ├──────────┼──────────────────────────┼───────────────────┤ │random │ pseudo-random number │ integer (32 bits) │ ├──────────┼──────────────────────────┼───────────────────┤ │secpath │ boolean │ boolean (1 bit) │ └──────────┴──────────────────────────┴───────────────────┘ Meta expression specific types ┌──────────────┬──────────────────────────────────┐ │Type │ Description │ ├──────────────┼──────────────────────────────────┤ │iface_index │ Interface index (32 bit number). │ │ │ Can be specified numerically or │ │ │ as name of an existing │ │ │ interface. │ ├──────────────┼──────────────────────────────────┤ │ifname │ Interface name (16 byte string). │ │ │ Does not have to exist. │ ├──────────────┼──────────────────────────────────┤ │iface_type │ Interface type (16 bit number). │ ├──────────────┼──────────────────────────────────┤ │uid │ User ID (32 bit number). Can be │ │ │ specified numerically or as user │ │ │ name. │ ├──────────────┼──────────────────────────────────┤ │gid │ Group ID (32 bit number). Can be │ │ │ specified numerically or as │ │ │ group name. │ ├──────────────┼──────────────────────────────────┤ │realm │ Routing Realm (32 bit number). │ │ │ Can be specified numerically or │ │ │ as symbolic name defined in │ │ │ /etc/iproute2/rt_realms. │ ├──────────────┼──────────────────────────────────┤ │devgroup_type │ Device group (32 bit number). │ │ │ Can be specified numerically or │ │ │ as symbolic name defined in │ │ │ /etc/iproute2/group. │ ├──────────────┼──────────────────────────────────┤ │pkt_type │ Packet type: Unicast (addressed │ │ │ to local host), Broadcast (to │ │ │ all), Multicast (to group). │ └──────────────┴──────────────────────────────────┘ Using meta expressions # qualified meta expression filter output meta oif eth0 # unqualified meta expression filter output oif eth0 # packed was subject to ipsec processing raw prerouting meta secpath exists accept FIB EXPRESSIONS fib {saddr | daddr | {mark | iif | oif}} {oif | oifname | type} A fib expression queries the fib (forwarding information base) to obtain information such as the output interface index a particular address would use. The input is a tuple of elements that is used as input to the fib lookup functions. fib expression specific types ┌────────┬────────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├────────┼────────────────────────┼──────────────────┤ │oif │ Output interface index │ integer (32 bit) │ ├────────┼────────────────────────┼──────────────────┤ │oifname │ Output interface name │ string │ ├────────┼────────────────────────┼──────────────────┤ │type │ Address type │ fib_addrtype │ └────────┴────────────────────────┴──────────────────┘ Using fib expressions # drop packets without a reverse path filter prerouting fib saddr . iif oif missing drop # drop packets to address not configured on ininterface filter prerouting fib daddr . iif type != { local, broadcast, multicast } drop # perform lookup in a specific 'blackhole' table (0xdead, needs ip appropriate ip rule) filter prerouting meta mark set 0xdead fib daddr . mark type vmap { blackhole : drop, prohibit : jump prohibited, unreachable : drop } ROUTING EXPRESSIONS rt {classid | nexthop} A routing expression refers to routing data associated with a packet. Routing expression types ┌────────┬──────────────────────────┬─────────────────────┐ │Keyword │ Description │ Type │ ├────────┼──────────────────────────┼─────────────────────┤ │classid │ Routing realm │ realm │ ├────────┼──────────────────────────┼─────────────────────┤ │nexthop │ Routing nexthop │ ipv4_addr/ipv6_addr │ ├────────┼──────────────────────────┼─────────────────────┤ │mtu │ TCP maximum segment size │ integer (16 bit) │ │ │ of route │ │ └────────┴──────────────────────────┴─────────────────────┘ Routing expression specific types ┌──────┬──────────────────────────────────┐ │Type │ Description │ ├──────┼──────────────────────────────────┤ │realm │ Routing Realm (32 bit number). │ │ │ Can be specified numerically or │ │ │ as symbolic name defined in │ │ │ /etc/iproute2/rt_realms. │ └──────┴──────────────────────────────────┘ Using routing expressions # IP family independent rt expression filter output rt classid 10 # IP family dependent rt expressions 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

PAYLOAD EXPRESSIONS

 Payload expressions refer to data from the packet's payload. ETHERNET HEADER EXPRESSION ether [ethernet header field] Ethernet header expression types ┌────────┬─────────────────────────┬────────────┐ │Keyword │ Description │ Type │ ├────────┼─────────────────────────┼────────────┤ │daddr │ Destination MAC address │ ether_addr │ ├────────┼─────────────────────────┼────────────┤ │saddr │ Source MAC address │ ether_addr │ ├────────┼─────────────────────────┼────────────┤ │type │ EtherType │ ether_type │ └────────┴─────────────────────────┴────────────┘ VLAN HEADER EXPRESSION vlan [VLAN header field] VLAN header expression ┌────────┬──────────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├────────┼──────────────────────────┼──────────────────┤ │id │ VLAN ID (VID) │ integer (12 bit) │ ├────────┼──────────────────────────┼──────────────────┤ │cfi │ Canonical Format │ integer (1 bit) │ │ │ Indicator │ │ ├────────┼──────────────────────────┼──────────────────┤ │pcp │ Priority code point │ integer (3 bit) │ ├────────┼──────────────────────────┼──────────────────┤ │type │ EtherType │ ether_type │ └────────┴──────────────────────────┴──────────────────┘ ARP HEADER EXPRESSION arp [ARP header field] ARP header expression ┌──────────┬──────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├──────────┼──────────────────────┼──────────────────┤ │htype │ ARP hardware type │ integer (16 bit) │ ├──────────┼──────────────────────┼──────────────────┤ │ptype │ EtherType │ ether_type │ ├──────────┼──────────────────────┼──────────────────┤ │hlen │ Hardware address len │ integer (8 bit) │ ├──────────┼──────────────────────┼──────────────────┤ │plen │ Protocol address len │ integer (8 bit) │ ├──────────┼──────────────────────┼──────────────────┤ │operation │ Operation │ arp_op │ └──────────┴──────────────────────┴──────────────────┘ IPV4 HEADER EXPRESSION ip [IPv4 header field] IPv4 header expression ┌──────────┬──────────────────────────┬──────────────────────────┐ │Keyword │ Description │ Type │ ├──────────┼──────────────────────────┼──────────────────────────┤ │version │ IP header version (4) │ integer (4 bit) │ ├──────────┼──────────────────────────┼──────────────────────────┤ │hdrlength │ IP header length │ integer (4 bit) FIXME │ │ │ including options │ scaling │ ├──────────┼──────────────────────────┼──────────────────────────┤ │dscp │ Differentiated Services │ dscp │ │ │ Code Point │ │ ├──────────┼──────────────────────────┼──────────────────────────┤ │ecn │ Explicit Congestion │ ecn │ │ │ Notification │ │ ├──────────┼──────────────────────────┼──────────────────────────┤ │length │ Total packet length │ integer (16 bit) │ ├──────────┼──────────────────────────┼──────────────────────────┤ │id │ IP ID │ integer (16 bit) │ ├──────────┼──────────────────────────┼──────────────────────────┤ │frag-off │ Fragment offset │ integer (16 bit) │ ├──────────┼──────────────────────────┼──────────────────────────┤ │ttl │ Time to live │ integer (8 bit) │ ├──────────┼──────────────────────────┼──────────────────────────┤ │protocol │ Upper layer protocol │ inet_proto │ ├──────────┼──────────────────────────┼──────────────────────────┤ │checksum │ IP header checksum │ integer (16 bit) │ ├──────────┼──────────────────────────┼──────────────────────────┤ │saddr │ Source address │ ipv4_addr │ ├──────────┼──────────────────────────┼──────────────────────────┤ │daddr │ Destination address │ ipv4_addr │ └──────────┴──────────────────────────┴──────────────────────────┘ ICMP HEADER EXPRESSION icmp [ICMP header field] ICMP header expression ┌─────────┬──────────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├─────────┼──────────────────────────┼──────────────────┤ │type │ ICMP type field │ icmp_type │ ├─────────┼──────────────────────────┼──────────────────┤ │code │ ICMP code field │ integer (8 bit) │ ├─────────┼──────────────────────────┼──────────────────┤ │checksum │ ICMP checksum field │ integer (16 bit) │ ├─────────┼──────────────────────────┼──────────────────┤ │id │ ID of echo │ integer (16 bit) │ │ │ request/response │ │ ├─────────┼──────────────────────────┼──────────────────┤ │sequence │ sequence number of echo │ integer (16 bit) │ │ │ request/response │ │ ├─────────┼──────────────────────────┼──────────────────┤ │gateway │ gateway of redirects │ integer (32 bit) │ ├─────────┼──────────────────────────┼──────────────────┤ │mtu │ MTU of path MTU │ integer (16 bit) │ │ │ discovery │ │ └─────────┴──────────────────────────┴──────────────────┘ IPV6 HEADER EXPRESSION ip6 [IPv6 header field] IPv6 header expression ┌──────────┬──────────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├──────────┼──────────────────────────┼──────────────────┤ │version │ IP header version (6) │ integer (4 bit) │ ├──────────┼──────────────────────────┼──────────────────┤ │dscp │ Differentiated Services │ dscp │ │ │ Code Point │ │ ├──────────┼──────────────────────────┼──────────────────┤ │ecn │ Explicit Congestion │ ecn │ │ │ Notification │ │ ├──────────┼──────────────────────────┼──────────────────┤ │flowlabel │ Flow label │ integer (20 bit) │ ├──────────┼──────────────────────────┼──────────────────┤ │length │ Payload length │ integer (16 bit) │ ├──────────┼──────────────────────────┼──────────────────┤ │nexthdr │ Nexthdr protocol │ inet_proto │ ├──────────┼──────────────────────────┼──────────────────┤ │hoplimit │ Hop limit │ integer (8 bit) │ ├──────────┼──────────────────────────┼──────────────────┤ │saddr │ Source address │ ipv6_addr │ ├──────────┼──────────────────────────┼──────────────────┤ │daddr │ Destination address │ ipv6_addr │ └──────────┴──────────────────────────┴──────────────────┘ ICMPV6 HEADER EXPRESSION icmpv6 [ICMPv6 header field] ICMPv6 header expression ┌──────────────────┬──────────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├──────────────────┼──────────────────────────┼──────────────────┤ │type │ ICMPv6 type field │ icmpv6_type │ ├──────────────────┼──────────────────────────┼──────────────────┤ │code │ ICMPv6 code field │ integer (8 bit) │ ├──────────────────┼──────────────────────────┼──────────────────┤ │checksum │ ICMPv6 checksum field │ integer (16 bit) │ ├──────────────────┼──────────────────────────┼──────────────────┤ │parameter-problem │ pointer to problem │ integer (32 bit) │ ├──────────────────┼──────────────────────────┼──────────────────┤ │packet-too-big │ oversized MTU │ integer (32 bit) │ ├──────────────────┼──────────────────────────┼──────────────────┤ │id │ ID of echo │ integer (16 bit) │ │ │ request/response │ │ ├──────────────────┼──────────────────────────┼──────────────────┤ │sequence │ sequence number of echo │ integer (16 bit) │ │ │ request/response │ │ ├──────────────────┼──────────────────────────┼──────────────────┤ │max-delay │ maximum response delay │ integer (16 bit) │ │ │ of MLD queries │ │ └──────────────────┴──────────────────────────┴──────────────────┘ TCP HEADER EXPRESSION tcp [TCP header field] TCP header expression ┌─────────┬────────────────────────┬──────────────────────────┐ │Keyword │ Description │ Type │ ├─────────┼────────────────────────┼──────────────────────────┤ │sport │ Source port │ inet_service │ ├─────────┼────────────────────────┼──────────────────────────┤ │dport │ Destination port │ inet_service │ ├─────────┼────────────────────────┼──────────────────────────┤ │sequence │ Sequence number │ integer (32 bit) │ ├─────────┼────────────────────────┼──────────────────────────┤ │ackseq │ Acknowledgement number │ integer (32 bit) │ ├─────────┼────────────────────────┼──────────────────────────┤ │doff │ Data offset │ integer (4 bit) FIXME │ │ │ │ scaling │ ├─────────┼────────────────────────┼──────────────────────────┤ │reserved │ Reserved area │ integer (4 bit) │ ├─────────┼────────────────────────┼──────────────────────────┤ │flags │ TCP flags │ tcp_flag │ ├─────────┼────────────────────────┼──────────────────────────┤ │window │ Window │ integer (16 bit) │ ├─────────┼────────────────────────┼──────────────────────────┤ │checksum │ Checksum │ integer (16 bit) │ ├─────────┼────────────────────────┼──────────────────────────┤ │urgptr │ Urgent pointer │ integer (16 bit) │ └─────────┴────────────────────────┴──────────────────────────┘ UDP HEADER EXPRESSION udp [UDP header field] UDP header expression ┌─────────┬─────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├─────────┼─────────────────────┼──────────────────┤ │sport │ Source port │ inet_service │ ├─────────┼─────────────────────┼──────────────────┤ │dport │ Destination port │ inet_service │ ├─────────┼─────────────────────┼──────────────────┤ │length │ Total packet length │ integer (16 bit) │ ├─────────┼─────────────────────┼──────────────────┤ │checksum │ Checksum │ integer (16 bit) │ └─────────┴─────────────────────┴──────────────────┘ UDP-LITE HEADER EXPRESSION udplite [UDP-Lite header field] UDP-Lite header expression ┌─────────┬──────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├─────────┼──────────────────┼──────────────────┤ │sport │ Source port │ inet_service │ ├─────────┼──────────────────┼──────────────────┤ │dport │ Destination port │ inet_service │ ├─────────┼──────────────────┼──────────────────┤ │checksum │ Checksum │ integer (16 bit) │ └─────────┴──────────────────┴──────────────────┘ SCTP HEADER EXPRESSION sctp [SCTP header field] SCTP header expression ┌─────────┬──────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├─────────┼──────────────────┼──────────────────┤ │sport │ Source port │ inet_service │ ├─────────┼──────────────────┼──────────────────┤ │dport │ Destination port │ inet_service │ ├─────────┼──────────────────┼──────────────────┤ │vtag │ Verfication Tag │ integer (32 bit) │ ├─────────┼──────────────────┼──────────────────┤ │checksum │ Checksum │ integer (32 bit) │ └─────────┴──────────────────┴──────────────────┘ DCCP HEADER EXPRESSION dccp [DCCP header field] DCCP header expression ┌────────┬──────────────────┬──────────────┐ │Keyword │ Description │ Type │ ├────────┼──────────────────┼──────────────┤ │sport │ Source port │ inet_service │ ├────────┼──────────────────┼──────────────┤ │dport │ Destination port │ inet_service │ └────────┴──────────────────┴──────────────┘ AUTHENTICATION HEADER EXPRESSION ah [AH header field] AH header expression ┌──────────┬──────────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├──────────┼──────────────────────────┼──────────────────┤ │nexthdr │ Next header protocol │ inet_proto │ ├──────────┼──────────────────────────┼──────────────────┤ │hdrlength │ AH Header length │ integer (8 bit) │ ├──────────┼──────────────────────────┼──────────────────┤ │reserved │ Reserved area │ integer (16 bit) │ ├──────────┼──────────────────────────┼──────────────────┤ │spi │ Security Parameter Index │ integer (32 bit) │ ├──────────┼──────────────────────────┼──────────────────┤ │sequence │ Sequence number │ integer (32 bit) │ └──────────┴──────────────────────────┴──────────────────┘ ENCRYPTED SECURITY PAYLOAD HEADER EXPRESSION esp [ESP header field] ESP header expression ┌─────────┬──────────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├─────────┼──────────────────────────┼──────────────────┤ │spi │ Security Parameter Index │ integer (32 bit) │ ├─────────┼──────────────────────────┼──────────────────┤ │sequence │ Sequence number │ integer (32 bit) │ └─────────┴──────────────────────────┴──────────────────┘ IPCOMP HEADER EXPRESSION comp [IPComp header field] IPComp header expression ┌────────┬──────────────────────────┬──────────────────┐ │Keyword │ Description │ Type │ ├────────┼──────────────────────────┼──────────────────┤ │nexthdr │ Next header protocol │ inet_proto │ ├────────┼──────────────────────────┼──────────────────┤ │flags │ Flags │ bitmask │ ├────────┼──────────────────────────┼──────────────────┤ │cpi │ Compression Parameter │ integer (16 bit) │ │ │ Index │ │ └────────┴──────────────────────────┴──────────────────┘ EXTENSION HEADER EXPRESSIONS Extension header expressions refer to data from variable-sized protocol headers, such as IPv6 extension headers and TCPs options. nftables currently supports matching (finding) a given ipv6 extension header or TCP option. hbh {nexthdr | hdrlength} frag {nexthdr | frag-off | more-fragments | id} rt {nexthdr | hdrlength | type | seg-left} dst {nexthdr | hdrlength} mh {nexthdr | hdrlength | checksum | type} tcp option {eol | noop | maxseg | window | sack-permitted | sack | sack0 | sack1 | sack2 | sack3 | timestamp} tcp_option_field The following syntaxes are valid only in a relational expression with boolean type on right-hand side for checking header existence only: exthdr {hbh | frag | rt | dst | mh} tcp option {eol | noop | maxseg | window | sack-permitted | sack | sack0 | sack1 | sack2 | sack3 | timestamp} IPv6 extension headers ┌────────┬──────────────────────┐ │Keyword │ Description │ ├────────┼──────────────────────┤ │hbh │ Hop by Hop │ ├────────┼──────────────────────┤ │rt │ Routing Header │ ├────────┼──────────────────────┤ │frag │ Fragmentation header │ ├────────┼──────────────────────┤ │dst │ dst options │ ├────────┼──────────────────────┤ │mh │ Mobility Header │ └────────┴──────────────────────┘ TCP Options ┌───────────────┬──────────────────────────┬──────────────────────────┐ │Keyword │ Description │ TCP option fields │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │eol │ End of option list │ kind │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │noop │ 1 Byte TCP No-op options │ kind │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │maxseg │ TCP Maximum Segment Size │ kind, length, size │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │window │ TCP Window Scaling │ kind, length, count │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │sack-permitted │ TCP SACK permitted │ kind, length │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │sack │ TCP Selective │ kind, length, left, │ │ │ Acknowledgement (alias │ right │ │ │ of block 0) │ │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │sack0 │ TCP Selective │ kind, length, left, │ │ │ Acknowledgement (block │ right │ │ │ 0) │ │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │sack1 │ TCP Selective │ kind, length, left, │ │ │ Acknowledgement (block │ right │ │ │ 1) │ │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │sack2 │ TCP Selective │ kind, length, left, │ │ │ Acknowledgement (block │ right │ │ │ 2) │ │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │sack3 │ TCP Selective │ kind, length, left, │ │ │ Acknowledgement (block │ right │ │ │ 3) │ │ ├───────────────┼──────────────────────────┼──────────────────────────┤ │timestamp │ TCP Timestamps │ kind, length, tsval, │ │ │ │ tsecr │ └───────────────┴──────────────────────────┴──────────────────────────┘ finding TCP options filter input tcp option sack-permitted kind 1 counter matching IPv6 exthdr ip6 filter input frag more-fragments 1 counter CONNTRACK EXPRESSIONS Conntrack expressions refer to meta data of the connection tracking entry associated with a packet. There are three types of conntrack expressions. Some conntrack expressions require the flow direction before the conntrack key, others must be used directly because they are direction agnostic. The packets, bytes and avgpkt keywords can be used with or without a direction. If the direction is omitted, the sum of the original and the reply direction is returned. The same is true for the zone, if a direction is given, the zone is only matched if the zone id is tied to the given direction. ct {state | direction | status | mark | expiration | helper | label | l3proto | protocol | bytes | packets | avgpkt | zone} ct {original | reply} {l3proto | protocol | proto-src | proto-dst | bytes | packets | avgpkt | zone} ct {original | reply} {ip | ip6} {saddr | daddr} Conntrack expressions ┌───────────┬──────────────────────────┬─────────────────────┐ │Keyword │ Description │ Type │ ├───────────┼──────────────────────────┼─────────────────────┤ │state │ State of the connection │ ct_state │ ├───────────┼──────────────────────────┼─────────────────────┤ │direction │ Direction of the packet │ ct_dir │ │ │ relative to the │ │ │ │ connection │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │status │ Status of the connection │ ct_status │ ├───────────┼──────────────────────────┼─────────────────────┤ │mark │ Connection mark │ mark │ ├───────────┼──────────────────────────┼─────────────────────┤ │expiration │ Connection expiration │ time │ │ │ time │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │helper │ Helper associated with │ string │ │ │ the connection │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │label │ Connection tracking │ ct_label │ │ │ label bit or symbolic │ │ │ │ name defined in │ │ │ │ connlabel.conf in the │ │ │ │ nftables include path │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │l3proto │ Layer 3 protocol of the │ nf_proto │ │ │ connection │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │saddr │ Source address of the │ ipv4_addr/ipv6_addr │ │ │ connection for the given │ │ │ │ direction │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │daddr │ Destination address of │ ipv4_addr/ipv6_addr │ │ │ the connection for the │ │ │ │ given direction │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │protocol │ Layer 4 protocol of the │ inet_proto │ │ │ connection for the given │ │ │ │ direction │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │proto-src │ Layer 4 protocol source │ integer (16 bit) │ │ │ for the given direction │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │proto-dst │ Layer 4 protocol │ integer (16 bit) │ │ │ destination for the │ │ │ │ given direction │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │packets │ packet count seen in the │ integer (64 bit) │ │ │ given direction or sum │ │ │ │ of original and reply │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │bytes │ bytecount seen, see │ integer (64 bit) │ │ │ description for packets │ │ │ │ keyword │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │avgpkt │ average bytes per │ integer (64 bit) │ │ │ packet, see description │ │ │ │ for packets keyword │ │ ├───────────┼──────────────────────────┼─────────────────────┤ │zone │ conntrack zone │ integer (16 bit) │ └───────────┴──────────────────────────┴─────────────────────┘ A description of conntrack-specific types listed above can be found sub-section CONNTRACK TYPES above.

STATEMENTS

 Statements represent actions to be performed. They can alter control flow (return, jump to a different chain, accept or drop the packet) or can perform actions, such as logging, rejecting a packet, etc. Statements exist in two kinds. Terminal statements unconditionally terminate evaluation of the current rule, non-terminal statements either only conditionally or never terminate evaluation of the current rule, in other words, they are passive from the ruleset evaluation perspective. There can be an arbitrary amount of non-terminal statements in a rule, but only a single terminal statement as the final statement. VERDICT STATEMENT The verdict statement alters control flow in the ruleset and issues policy decisions for packets. {accept | drop | queue | continue | return} {jump | goto} chain accept Terminate ruleset evaluation and accept the packet. drop Terminate ruleset evaluation and drop the packet. queue Terminate ruleset evaluation and queue the packet to userspace. continue Continue ruleset evaluation with the next rule. FIXME return Return from the current chain and continue evaluation at the next rule in the last chain. If issued in a base chain, it is equivalent to accept. jump chain Continue evaluation at the first rule in chain. The current position in the ruleset is pushed to a call stack and evaluation will continue there when the new chain is entirely evaluated of a return verdict is issued. goto chain Similar to jump, but the current position is not pushed to the call stack, meaning that after the new chain evaluation will continue at the last chain instead of the one containing the goto statement. Verdict statements # 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 PAYLOAD STATEMENT The payload statement alters packet content. It can be used for example to set ip DSCP (differv) header field or ipv6 flow labels. route some packets instead of bridging # 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 unicast ether daddr set 00:11:22:33:44:55 Set IPv4 DSCP header field ip forward ip dscp set 42 EXTENSION HEADER STATEMENT The extension header statement alters packet content in variable-sized headers. This can currently be used to alter the TCP Maximum segment size of packets, similar to TCPMSS. change 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 LOG STATEMENT log [prefix quoted_string] [level syslog-level] [flags log-flags] log group nflog_group [prefix quoted_string] [queue-threshold value] [snaplen size] The log statement enables logging of matching packets. When this statement is used from a rule, the Linux kernel will print some information on all matching packets, such as header fields, via the kernel log (where it can be read with dmesg(1) or read in the syslog). If the group number is specified, the Linux kernel will pass the packet to nfnetlink_log which will multicast the packet through a netlink socket to the specified multicast group. One or more userspace processes may subscribe to the group to receive the packets, see libnetfilter_queue documentation for details. This is a non-terminating statement, so the rule evaluation continues after the packet is logged. log statement options ┌────────────────┬──────────────────────────┬──────────────────────────┐ │Keyword │ Description │ Type │ ├────────────────┼──────────────────────────┼──────────────────────────┤ │prefix │ Log message prefix │ quoted string │ ├────────────────┼──────────────────────────┼──────────────────────────┤ │level │ Syslog level of logging │ string: emerg, alert, │ │ │ │ crit, err, warn │ │ │ │ [default], notice, info, │ │ │ │ debug │ ├────────────────┼──────────────────────────┼──────────────────────────┤ │group │ NFLOG group to send │ unsigned integer (16 │ │ │ messages to │ bit) │ ├────────────────┼──────────────────────────┼──────────────────────────┤ │snaplen │ Length of packet payload │ unsigned integer (32 │ │ │ to include in netlink │ bit) │ │ │ message │ │ ├────────────────┼──────────────────────────┼──────────────────────────┤ │queue-threshold │ Number of packets to │ unsigned integer (32 │ │ │ queue inside the kernel │ bit) │ │ │ before sending them to │ │ │ │ userspace │ │ └────────────────┴──────────────────────────┴──────────────────────────┘ log-flags ┌─────────────┬──────────────────────────────────┐ │Flag │ Description │ ├─────────────┼──────────────────────────────────┤ │tcp sequence │ Log TCP sequence numbers. │ ├─────────────┼──────────────────────────────────┤ │tcp options │ Log options from the TCP packet │ │ │ header. │ ├─────────────┼──────────────────────────────────┤ │ip options │ Log options from the IP/IPv6 │ │ │ packet header. │ ├─────────────┼──────────────────────────────────┤ │skuid │ Log the userid of the process │ │ │ which generated the packet. │ ├─────────────┼──────────────────────────────────┤ │ether │ Decode MAC addresses and │ │ │ protocol. │ ├─────────────┼──────────────────────────────────┤ │all │ Enable all log flags listed │ │ │ above. │ └─────────────┴──────────────────────────────────┘ Using log statement # 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 {icmp | icmp6 | icmpx} type {icmp_type | icmp6_type | icmpx_type} ] reject [ with tcp reset ] A reject statement is used to send back an error packet in response to the matched packet otherwise it is equivalent to drop so it is a terminating statement, ending rule traversal. This statement is only valid in the input, forward and output chains, and user- defined chains which are only called from those chains. The different ICMP reject variants are meant for use in different table families: ┌────────┬────────┬─────────────┐ │Variant │ Family │ Type │ ├────────┼────────┼─────────────┤ │icmp │ ip │ icmp_code │ ├────────┼────────┼─────────────┤ │icmp6 │ ip6 │ icmpv6_code │ ├────────┼────────┼─────────────┤ │icmpx │ inet │ icmpx_code │ └────────┴────────┴─────────────┘ For a description of the different types and a list of supported keywords refer to DATA TYPES section above. The common default reject value is port-unreachable. COUNTER STATEMENT A counter statement sets the hit count of packets along with the number of bytes. counter [ packets number bytes number ] CONNTRACK STATEMENT The conntrack statement can be used to set the conntrack mark and conntrack labels. ct {mark | event | label | zone} set value The ct statement sets meta data associated with a connection. The zone id has to be assigned before a conntrack lookup takes place, i.e. this has to be done in prerouting and possibly output (if locally generated packets need to be placed in a distinct zone), with a hook priority of -300. Conntrack statement types ┌────────┬──────────────────────────┬──────────────────────────┐ │Keyword │ Description │ Value │ ├────────┼──────────────────────────┼──────────────────────────┤ │event │ conntrack event bits │ bitmask, integer (32 │ │ │ │ bit) │ ├────────┼──────────────────────────┼──────────────────────────┤ │helper │ name of ct helper object │ quoted string │ │ │ to assign to the │ │ │ │ connection │ │ ├────────┼──────────────────────────┼──────────────────────────┤ │mark │ Connection tracking mark │ mark │ ├────────┼──────────────────────────┼──────────────────────────┤ │label │ Connection tracking │ label │ │ │ label │ │ ├────────┼──────────────────────────┼──────────────────────────┤ │zone │ conntrack zone │ integer (16 bit) │ └────────┴──────────────────────────┴──────────────────────────┘ save packet nfmark in conntrack ct mark set meta mark set zone mapped via interface table inet raw { chain prerouting { type filter hook prerouting priority -300; ct zone set iif map { "eth1" : 1, "veth1" : 2 } } chain output { type filter hook output priority -300; ct zone set oif map { "eth1" : 1, "veth1" : 2 } } } restrict events reported by ctnetlink ct event set new,related,destroy META STATEMENT A meta statement sets the value of a meta expression. The existing meta fields are: priority, mark, pkttype, nftrace. meta {mark | priority | pkttype | nftrace} set value A meta statement sets meta data associated with a packet. Meta statement types ┌─────────┬──────────────────────────┬───────────┐ │Keyword │ Description │ Value │ ├─────────┼──────────────────────────┼───────────┤ │priority │ TC packet priority │ tc_handle │ ├─────────┼──────────────────────────┼───────────┤ │mark │ Packet mark │ mark │ ├─────────┼──────────────────────────┼───────────┤ │pkttype │ packet type │ pkt_type │ ├─────────┼──────────────────────────┼───────────┤ │nftrace │ ruleset packet tracing │ 0, 1 │ │ │ on/off. Use monitor │ │ │ │ trace command to watch │ │ │ │ traces │ │ └─────────┴──────────────────────────┴───────────┘ LIMIT STATEMENT limit rate [over] packet_number / {second | minute | hour | day} [burst packet_number packets] limit rate [over] byte_number {bytes | kbytes | mbytes} / {second | minute | hour | day | week} [burst byte_number bytes] A limit statement matches at a limited rate using a token bucket filter. A rule using this statement will match until this limit is reached. It can be used in combination with the log statement to give limited logging. The over keyword, that is optional, makes it match over the specified rate. limit statement values ┌──────────────┬───────────────────┬──────────────────────────┐ │Value │ Description │ Type │ ├──────────────┼───────────────────┼──────────────────────────┤ │packet_number │ Number of packets │ unsigned integer (32 │ │ │ │ bit) │ ├──────────────┼───────────────────┼──────────────────────────┤ │byte_number │ Number of bytes │ unsigned integer (32 │ │ │ │ bit) │ └──────────────┴───────────────────┴──────────────────────────┘ NAT STATEMENTS snat to address [:port] [persistent, random, fully-random] snat to address - address [:port - port] [persistent, random, fully-random] dnat to address [:port] [persistent, random, fully-random] dnat to address [:port - port] [persistent, random, fully-random] masquerade to [:port] [persistent, random, fully-random] masquerade to [:port - port] [persistent, random, fully-random] redirect to [:port] [persistent, random, fully-random] redirect to [:port - port] [persistent, random, fully-random] The nat statements are only valid from nat chain types. The snat and masquerade statements specify that the source address of the packet should be modified. While snat is only valid in the postrouting and input chains, masquerade makes sense only in postrouting. The dnat and redirect statements are only valid in the prerouting and output chains, they specify that the destination address of the packet should be modified. You can use non-base chains which are called from base chains of nat chain type too. All future packets in this connection will also be mangled, and rules should cease being examined. The masquerade statement is a special form of snat which always uses the outgoing interface's IP address to translate to. It is particularly useful on gateways with dynamic (public) IP addresses. The redirect statement is a special form of dnat which always translates the destination address to the local host's one. It comes in handy if one only wants to alter the destination port of incoming traffic on different interfaces. Note that all nat statements require both prerouting and postrouting base chains to be present since otherwise packets on the return path won't be seen by netfilter and therefore no reverse translation will take place. NAT statement values ┌───────────┬──────────────────────────┬──────────────────────────┐ │Expression │ Description │ Type │ ├───────────┼──────────────────────────┼──────────────────────────┤ │address │ Specifies that the │ ipv4_addr, ipv6_addr, │ │ │ source/destination │ eg. abcd::1234, or you │ │ │ address of the packet │ can use a mapping, eg. │ │ │ should be modified. You │ meta mark map { 10 : │ │ │ may specify a mapping to │ 192.168.1.2, 20 : │ │ │ relate a list of tuples │ 192.168.1.3 } │ │ │ composed of arbitrary │ │ │ │ expression key with │ │ │ │ address value. │ │ ├───────────┼──────────────────────────┼──────────────────────────┤ │port │ Specifies that the │ port number (16 bits) │ │ │ source/destination │ │ │ │ address of the packet │ │ │ │ should be modified. │ │ └───────────┴──────────────────────────┴──────────────────────────┘ NAT statement flags ┌─────────────┬──────────────────────────────────┐ │Flag │ Description │ ├─────────────┼──────────────────────────────────┤ │persistent │ Gives a client the same │ │ │ source-/destination-address for │ │ │ each connection. │ ├─────────────┼──────────────────────────────────┤ │random │ If used then port mapping will │ │ │ be randomized using a random │ │ │ seeded MD5 hash mix using source │ │ │ and destination address and │ │ │ destination port. │ ├─────────────┼──────────────────────────────────┤ │fully-random │ If used then port mapping is │ │ │ generated based on a 32-bit │ │ │ pseudo-random algorithm. │ └─────────────┴──────────────────────────────────┘ Using NAT statements # create a suitable table/chain setup for all further examples add table nat add chain nat prerouting { type nat hook prerouting priority 0; } add chain nat postrouting { type nat hook postrouting priority 100; } # translate source addresses of all packets leaving via eth0 to address 1.2.3.4 add rule nat postrouting oif eth0 snat to 1.2.3.4 # redirect all traffic entering via eth0 to destination address 192.168.1.120 add rule nat prerouting iif eth0 dnat to 192.168.1.120 # translate source addresses of all packets leaving via eth0 to whatever # locally generated packets would use as source to reach the same destination add rule nat postrouting oif eth0 masquerade # redirect incoming TCP traffic for port 22 to port 2222 add rule nat prerouting tcp dport 22 redirect to :2222 QUEUE STATEMENT This statement passes the packet to userspace using the nfnetlink_queue handler. The packet is put into the queue identified by its 16-bit queue number. Userspace can inspect and modify the packet if desired. Userspace must then drop or reinject the packet into the kernel. See libnetfilter_queue documentation for details. queue [num queue_number] [bypass] queue [num queue_number_from - queue_number_to] [bypass,fanout] queue statement values ┌──────────────────┬──────────────────────────┬──────────────────────────┐ │Value │ Description │ Type │ ├──────────────────┼──────────────────────────┼──────────────────────────┤ │queue_number │ Sets queue number, │ unsigned integer (16 │ │ │ default is 0. │ bit) │ ├──────────────────┼──────────────────────────┼──────────────────────────┤ │queue_number_from │ Sets initial queue in │ unsigned integer (16 │ │ │ the range, if fanout is │ bit) │ │ │ used. │ │ ├──────────────────┼──────────────────────────┼──────────────────────────┤ │queue_number_to │ Sets closing queue in │ unsigned integer (16 │ │ │ the range, if fanout is │ bit) │ │ │ used. │ │ └──────────────────┴──────────────────────────┴──────────────────────────┘ queue statement flags ┌───────┬──────────────────────────────────┐ │Flag │ Description │ ├───────┼──────────────────────────────────┤ │bypass │ Let packets go through if │ │ │ userspace application cannot │ │ │ back off. Before using this │ │ │ flag, read libnetfilter_queue │ │ │ documentation for performance │ │ │ tuning recomendations. │ ├───────┼──────────────────────────────────┤ │fanout │ Distribute packets between │ │ │ several queues. │ └───────┴──────────────────────────────────┘ DUP STATEMENT The dup statement is used to duplicate a packet and send the copy to a different destination. dup to device dup to address device device Dup statement values ┌───────────┬──────────────────────────┬──────────────────────────┐ │Expression │ Description │ Type │ ├───────────┼──────────────────────────┼──────────────────────────┤ │address │ Specifies that the copy │ ipv4_addr, ipv6_addr, │ │ │ of the packet should be │ eg. abcd::1234, or you │ │ │ sent to a new gateway. │ can use a mapping, eg. │ │ │ │ ip saddr map { │ │ │ │ 192.168.1.2 : 10.1.1.1 } │ ├───────────┼──────────────────────────┼──────────────────────────┤ │device │ Specifies that the copy │ string │ │ │ should be transmitted │ │ │ │ via device. │ │ └───────────┴──────────────────────────┴──────────────────────────┘ Using the dup statement # send to machine with ip address 10.2.3.4 on eth0 ip filter forward dup to 10.2.3.4 device "eth0" # copy raw frame to another interface netdetv ingress dup to "eth0" dup to "eth0" # combine with map dst addr to gateways dup to ip daddr map { 192.168.7.1 : "eth0", 192.168.7.2 : "eth1" } FWD STATEMENT The fwd statement is used to redirect a raw packet to another interface. Its is only available in the netdev family ingress hook. It is similar to the dup statement except that no copy is made. fwd to device

ADDITIONAL COMMANDS

 These are some additional commands included in nft. MONITOR The monitor command allows you to listen to Netlink events produced by the nf_tables subsystem, related to creation and deletion of objects. When they occur, nft will print to stdout the monitored events in either XML, JSON or native nft format. To filter events related to a concrete object, use one of the keywords 'tables', 'chains', 'sets', 'rules', 'elements' , 'ruleset'. To filter events related to a concrete action, use keyword 'new' or 'destroy'. Hit ^C to finish the monitor operation. Listen to all events, report in native nft format % nft monitor Listen to added tables, report in XML format % nft monitor new tables xml Listen to deleted rules, report in JSON format % nft monitor destroy rules json Listen to both new and destroyed chains, in native nft format % nft monitor chains Listen to ruleset events such as table, chain, rule, set, counters and quotas, in native nft format % nft monitor ruleset

ERROR REPORTING

 When an error is detected, nft shows the line(s) containing the error, the position of the erroneous parts in the input stream and marks up the erroneous parts using carrets (^). If the error results from the combination of two expressions or statements, the part imposing the constraints which are violated is marked using tildes (~). For errors returned by the kernel, nft can't detect which parts of the input caused the error and the entire command is marked. Error caused by single incorrect expression <cmdline>:1:19-22: Error: Interface does not exist filter output oif eth0 ^^^^ Error caused by invalid combination of two expressions <cmdline>:1:28-36: Error: Right hand side of relational expression (==) must be constant filter output tcp dport == tcp dport ~~ ^^^^^^^^^ Error returned by the kernel <cmdline>:0:0-23: Error: Could not process rule: Operation not permitted filter output oif wlan0 ^^^^^^^^^^^^^^^^^^^^^^^

EXIT STATUS

 On success, nft exits with a status of 0. Unspecified errors cause it to exit with a status of 1, memory allocation errors with a status of 2, unable to open Netlink socket with 3.

SEE ALSO

 iptables(8), ip6tables(8), arptables(8), ebtables(8), ip(8), tc(8) There is an official wiki at: https://wiki.nftables.org

AUTHORS

 nftables was written by Patrick McHardy and Pablo Neira Ayuso, among many other contributors from the Netfilter community.

COPYRIGHT

 Copyright 2008-2014 Patrick McHardy <kaber@trash.net> Copyright 2013-2016 Pablo Neira Ayuso <pablo@netfilter.org> nftables is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This documentation is licenced under the terms of the Creative Commons Attribution- ShareAlike 4.0 license, CC BY-SA 4.0 ⟨http://creativecommons.org/licenses/by-sa/4.0/⟩ . 02 February 2018 nft(8)
Ubuntu Manpage:

       nft   -   Administration   tool  of  the  nftables  framework  for  packet  filtering  and (2024)
Top Articles
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 5486

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.