'\" t -*- coding: us-ascii -*-
.if \n(.g .ds T< \\FC
.if \n(.g .ds T> \\F[\n[.fam]]
.de URL
\\$2 \(la\\$1\(ra\\$3
..
.if \n(.g .mso www.tmac
.TH nft 8 "20 June 2018" "" ""
.SH NAME
nft \- Administration tool for packet filtering and classification
.SH SYNOPSIS
'nh
.fi
.ad l
\fBnft\fR \kx
.if (\nx>(\n(.l/2)) .nr x (\n(.l/5)
'in \n(.iu+\nxu
[\fB-n\fR | \fB--numeric\fR] [\fB-N\fR | \fB--reversedns\fR] [\fB-s\fR | \fB--stateless\fR] [\fB-c\fR | \fB--check\fR] [\fB-a\fR | \fB--handle\fR] [\fB-e\fR | \fB--echo\fR] [
{\fB-I\fR | \fB--includepath\fR}
\fIdirectory\fR
] [
{\fB-f\fR | \fB--file\fR}
\fIfilename\fR
|
{\fB-i\fR | \fB--interactive\fR}
|
\fIcmd\fR
\&...]
'in \n(.iu-\nxu
.ad b
'hy
'nh
.fi
.ad l
\fBnft\fR \kx
.if (\nx>(\n(.l/2)) .nr x (\n(.l/5)
'in \n(.iu+\nxu
[\fB-h\fR | \fB--help\fR] [\fB-v\fR | \fB--version\fR]
'in \n(.iu-\nxu
.ad b
'hy
.SH DESCRIPTION
nft is used to set up, maintain and inspect packet
filtering and classification rules in the Linux kernel.
.SH OPTIONS
For a full summary of options, run \fBnft --help\fR.
.TP
\*(T<\fB\-h, \-\-help\fR\*(T>
Show help message and all options.
.TP
\*(T<\fB\-v, \-\-version\fR\*(T>
Show version.
.TP
\*(T<\fB\-n, \-\-numeric\fR\*(T>
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.
.TP
\*(T<\fB\-s, \-\-stateless\fR\*(T>
Omit stateful information of rules and stateful objects.
.TP
\*(T<\fB\-c, \-\-check\fR\*(T>
Check commands validity without actually applying the changes.
.TP
\*(T<\fB\-N, \-\-reversedns\fR\*(T>
Translate IP addresses to names. Usually requires network traffic for DNS lookup.
.TP
\*(T<\fB\-a, \-\-handle\fR\*(T>
Show rule handles in output.
.TP
\*(T<\fB\-e, \-\-echo\fR\*(T>
When inserting items into the ruleset using \fBadd\fR,
\fBinsert\fR or \fBreplace\fR commands,
print notifications just like \fBnft monitor\fR.
.TP
\*(T<\fB\-I, \-\-includepath \fR\*(T>\fIdirectory\fR
Add the directory \fIdirectory\fR to the list of directories to be searched for included files. This option may be specified multiple times.
.TP
\*(T<\fB\-f, \-\-file \fR\*(T>\fIfilename\fR
Read input from \fIfilename\fR.
.TP
\*(T<\fB\-i, \-\-interactive\fR\*(T>
Read input from an interactive readline CLI.
.SH "INPUT FILE FORMAT"
.SS "LEXICAL CONVENTIONS"
Input is parsed line-wise. When the last character of a line, just before
the newline character, is a non-quoted backslash (\*(T<\e\*(T>),
the next line is treated as a continuation. Multiple commands on the
same line can be separated using a semicolon (\*(T<;\*(T>).
.PP
A hash sign (\*(T<#\*(T>) begins a comment. All following characters
on the same line are ignored.
.PP
Identifiers begin with an alphabetic character (\*(T),
followed zero or more alphanumeric characters (\*(T)
and the characters slash (\*(T\*(T>), backslash (\*(T<\e\*(T>),
underscore (\*(T<_\*(T>) and dot (\*(T<.\*(T>). Identifiers
using different characters or clashing with a keyword need to be enclosed in
double quotes (\*(T<"\*(T>).
.PP
.SS "INCLUDE FILES"
'nh
.fi
.ad l
\fBinclude\fR \kx
.if (\nx>(\n(.l/2)) .nr x (\n(.l/5)
'in \n(.iu+\nxu
\fIfilename\fR
'in \n(.iu-\nxu
.ad b
'hy
.PP
Other files can be included by using the \fBinclude\fR statement.
The directories to be searched for include files can be specified using
the \*(T<\fB\-I/\-\-includepath\fR\*(T> 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.
.PP
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.
.PP
Include statements support the usual shell wildcard symbols
(\*(T<*,?,[]\*(T>). 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
\*(T. The wildcard matches are
loaded in alphabetical order. Files beginning with dot (\*(T<.\*(T>) are
not matched by include statements.
.SS "SYMBOLIC VARIABLES"
'nh
.fi
.ad l
\fBdefine\fR \kx
.if (\nx>(\n(.l/2)) .nr x (\n(.l/5)
'in \n(.iu+\nxu
variable \fIexpr\fR
'in \n(.iu-\nxu
.ad b
'hy
'nh
.fi
.ad l
\fB$variable\fR \kx
.if (\nx>(\n(.l/2)) .nr x (\n(.l/5)
'in \n(.iu+\nxu
'in \n(.iu-\nxu
.ad b
'hy
.PP
Symbolic variables can be defined using the \fBdefine\fR 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.
\fBUsing symbolic variables\fR
.PP
.nf
\*(T<
define int_if1 = eth0
define int_if2 = eth1
define int_ifs = { $int_if1, $int_if2 }
filter input iif $int_ifs accept
\*(T>
.fi
.SH "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.
.PP
.TP
\*(T<\fBip\fR\*(T>
IPv4 address family.
.TP
\*(T<\fBip6\fR\*(T>
IPv6 address family.
.TP
\*(T<\fBinet\fR\*(T>
Internet (IPv4/IPv6) address family.
.TP
\*(T<\fBarp\fR\*(T>
ARP address family, handling IPv4 ARP packets.
.TP
\*(T<\fBbridge\fR\*(T>
Bridge address family, handling packets which traverse a bridge device.
.TP
\*(T<\fBnetdev\fR\*(T>
Netdev address family, handling packets from ingress.
.PP
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 \*(T family is used by default.
.SS "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.
.PP
\fBIPv4/IPv6/Inet address family hooks\fR
.TS
allbox ;
l | l.
T{
Hook
T} T{
Description
T}
.T&
l | l.
T{
prerouting
T} T{
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.
T}
T{
input
T} T{
Packets delivered to the local system are processed by the input hook.
T}
T{
forward
T} T{
Packets forwarded to a different host are processed by the forward hook.
T}
T{
output
T} T{
Packets sent by local processes are processed by the output hook.
T}
T{
postrouting
T} T{
All packets leaving the system are processed by the postrouting hook.
T}
.TE
.SS "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.
.PP
\fBARP address family hooks\fR
.TS
allbox ;
l | l.
T{
Hook
T} T{
Description
T}
.T&
l | l
l | l.
T{
input
T} T{
Packets delivered to the local system are processed by the input hook.
T}
T{
output
T} T{
Packets send by the local system are processed by the output hook.
T}
.TE
.SS "BRIDGE ADDRESS FAMILY"
The bridge address family handles ethernet packets traversing bridge devices.
.PP
The list of supported hooks is identical to IPv4/IPv6/Inet address families above.
.SS "NETDEV ADDRESS FAMILY"
The Netdev address family handles packets from ingress.
.PP
\fBNetdev address family hooks\fR
.TS
allbox ;
l | l.
T{
Hook
T} T{
Description
T}
.T&
l | l.
T{
ingress
T} T{
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.
T}
.TE
.SH RULESET
'nh
.fi
.ad l
{list | flush} \fBruleset\fR [\fIfamily\fR]
.ad b
'hy
'nh
.fi
.ad l
{export} [\fBruleset\fR] {\fIformat\fR}
.ad b
'hy
.PP
The \fBruleset\fR keyword is used to identify the whole
set of tables, chains, etc. currently in place in kernel. The
following \fBruleset\fR commands exist:
.TP
\*(T<\fBlist\fR\*(T>
Print the ruleset in human-readable format.
.TP
\*(T<\fBflush\fR\*(T>
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.
.TP
\*(T<\fBexport\fR\*(T>
Print the ruleset in machine readable format. The
mandatory \fIformat\fR parameter
may be either \*(T or
\*(T.
.PP
It is possible to limit \fBlist\fR and
\fBflush\fR to a specific address family only. For a
list of valid family names, see \*(T above.
.PP
Note that contrary to what one might assume, the output generated
by \fBexport\fR is not parseable by
\fBnft -f\fR. Instead, the output of
\fBlist\fR command serves well for that purpose.
.SH TABLES
'nh
.fi
.ad l
{add | delete | list | flush} \fBtable\fR [\fIfamily\fR] {\fItable\fR}
.ad b
'hy
.PP
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
\*(T, \*(T, \*(T, \*(T, \*(T, \*(T.
The \*(T address family is a dummy family which is used to create
hybrid IPv4/IPv6 tables. The \*(T expression \*(T
keyword can be used to test which family (ipv4 or ipv6) context the packet is being processed in.
When no address family is specified, \*(T is used by default.
.TP
\*(T<\fBadd\fR\*(T>
Add a new table for the given family with the given name.
.TP
\*(T<\fBdelete\fR\*(T>
Delete the specified table.
.TP
\*(T<\fBlist\fR\*(T>
List all chains and rules of the specified table.
.TP
\*(T<\fBflush\fR\*(T>
Flush all chains and rules of the specified table.
.SH CHAINS
'nh
.fi
.ad l
{add | create} \fBchain\fR [\fIfamily\fR] \fItable\fR \fIchain\fR [
{
{\fItype\fR}
{\fIhook\fR}
[\fIdevice\fR]
{\fIpriority\fR ;}
[\fIpolicy\fR ;]
}
]
.ad b
'hy
'nh
.fi
.ad l
{delete | list | flush} \fBchain\fR [\fIfamily\fR] {\fItable\fR} {\fIchain\fR}
.ad b
'hy
'nh
.fi
.ad l
{rename} \fBchain\fR [\fIfamily\fR] {\fItable\fR} {\fIchain\fR} {\fInewname\fR}
.ad b
'hy
.PP
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.
.TP
\*(T<\fBadd\fR\*(T>
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.
.TP
\*(T<\fBcreate\fR\*(T>
Similar to the \fBadd\fR command, but returns an error if the
chain already exists.
.TP
\*(T<\fBdelete\fR\*(T>
Delete the specified chain. The chain must not contain any rules or be
used as jump target.
.TP
\*(T<\fBrename\fR\*(T>
Rename the specified chain.
.TP
\*(T<\fBlist\fR\*(T>
List all rules of the specified chain.
.TP
\*(T<\fBflush\fR\*(T>
Flush all rules of the specified chain.
.PP
For base chains, \fBtype\fR, \fBhook\fR and \fBpriority\fR parameters are mandatory.
.PP
\fBSupported chain types\fR
.TS
allbox ;
l | l | l | l.
T{
Type
T} T{
Families
T} T{
Hooks
T} T{
Description
T}
.T&
l | l | l | l
l | l | l | l
l | l | l | l.
T{
filter
T} T{
all
T} T{
all
T} T{
Standard chain type to use in doubt.
T}
T{
nat
T} T{
ip, ip6
T} T{
prerouting, input, output, postrouting
T} T{
Chains of this type perform Native 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).
T}
T{
route
T} T{
ip, ip6
T} T{
output
T} T{
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.
T}
.TE
.PP
Apart from the special cases illustrated above (e.g. \*(T type not supporting \*(T hook or \*(T type only supporting \*(T