summaryrefslogtreecommitdiffstats
path: root/doc/nft.txt
blob: 5b477d862d8690d9095e1a9ac39848078ffc2496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
nft(8)
======

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


SYNOPSIS
--------
[verse]
*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.

*-s*::
*--stateless*::
	Omit stateful information of rules and stateful objects.

*-l*::
*--literal*::
	Translate numeric to literal. When used once (the default
	behaviour),  print  services (instead of numerical port numbers). Use
	twice to perform the IP address to name lookup, this usually
	requires  network traffic for DNS lookup that slows down the
	ruleset listing.

*-c*::
*--check*::
	Check commands validity without actually applying the changes.

*-a*::
*--handle*::
	Show object 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'. If 'filename' is -, read from stdin. +
	nft scripts must start #!/usr/sbin/nft -f

*-i*::
*--interactive*::
	Read  input from an interactive readline CLI. You can use quit to exit, or use the EOF marker,
	normally this is CTRL-D.

INPUT FILE FORMATS
------------------
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
~~~~~~~~~~~~~
[verse]
*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 (i.e.
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
~~~~~~~~~~~~~~~~~~
[verse]
*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
----------------
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.

[horizontal]
*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
[options="header"]
|==================
|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
[options="header"]
|=================
|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
[options="header"]
|=================
|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
-------
[verse]
{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:

[horizontal]
*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
------
[verse]
{add | create} *table* ['family'] 'table' [ {flags 'flags'} ]
{delete | list | flush} *table* ['family'] 'table'
delete *table* ['family'] handle 'handle'

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. The only difference between add and create is that the former will
not return an error if the specified table already exists while *create* will
return an error.

.Table flags
[options="header"]
|=================
|Flag | Description
|dormant |
table is not evaluated any more (base chains are unregistered).
|=================

.*Add, change, delete a table*
---------------------------------------
# start nft in interactive mode
nft --interactive

# create a new table.
create table inet mytable

# add a new base chain: get input packets
add chain inet mytable myin { type filter hook input priority 0; }

# add a single counter to the chain
add rule inet mytable myin counter

# disable the table temporarily -- rules are not evaluated anymore
add table inet mytable { flags dormant; }

# make table active again:
add table inet mytable
---------------------------------------

[horizontal]
*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
------
[verse]
{add | create} *chain* ['family'] 'table' 'chain' [ { type 'type' hook 'hook' [device 'device'] priority 'priority' ; [policy 'policy' ;] }]
{delete | list | flush} *chain* ['family'] 'table' 'chain'
delete *chain* ['family'] 'table' handle 'handle'
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.

[horizontal]
*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
[options="header"]
|=================
|Type | Families | Hooks | Description
|filter | all | all |
Standard chain type to use in doubt.
|nat | ip, ip6 |
prerouting, input, output, postrouting |
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).
|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
-----
[verse]
{add | insert} *rule* ['family'] 'table' 'chain' [ {handle | position} 'handle' | index 'index' ] 'statement' ... [ comment 'comment' ]
replace *rule* ['family'] 'table' 'chain' handle 'handle' 'statement' ... [ comment 'comment' ]
delete *rule* ['family'] 'table' 'chain' handle 'handle'

Rules are added to chains in the given table. If the family is not specified, the
ip family is used. Rules are constructed from two kinds of components according
to a set of grammatical rules: expressions and statements.

The add and insert commands support an optional location specifier, which is
either a 'handle' of an existing rule or an 'index' (starting  at zero).
Internally, rule locations are always identified by 'handle' and the translation
from 'index' happens in userspace. This has two potential implications in case a
concurrent ruleset change happens after the translation was done: The effective
rule  index might change if a rule was inserted or deleted before the referred
one. If the referred rule was deleted, the command is rejected by the kernel
just as if an invalid 'handle' was given.

A 'comment' is a single word or a double-quoted (") multi-word string which can
be used to make notes regarding the actual rule. *Note:* If you use bash for
adding rules, you have to escape the quotation marks (eg. \"enable ssh for
servers\")

[horizontal]
*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 'handle'. The alternative
name position is deprecated and should not be used anymore.
*insert*:: Similar to the *add* command, but the rule is prepended to the
beginning of the chain or before the rule with the given 'handle'.
*replace*:: Similar to the add command, but the rule replaces the specified
rule.
*delete*:: Delete the specified rule.

.*add a rule to ip table input chain*
-------------
nft add rule filter output ip daddr 192.168.0.0/24 accept # 'ip filter' is assumed
# same command, slightly more verbose
nft add rule ip filter output ip daddr 192.168.0.0/24 accept
--------------

.*delete rule from inet table*
-----------------------
# nft -a list ruleset
table inet filter {
	chain input {
		type filter hook input priority 0; policy accept;
		ct state established,related accept # handle 4
		ip saddr 10.1.1.1 tcp dport ssh accept # handle 5
	  ...
# delete the rule with handle 5
# nft delete rule inet filter input handle 5
-------------------------

SETS
----
nftables offers two kinds of set concepts.  Anonymous sets are sets that have no
specific name. The set members are enclosed in curly braces, with commas to
separate elements when creating the rule the set is used in. Once that rule is
removed, the set is removed as well. They cannot be updated, i.e. once an
anonymous set is declared it cannot be changed anymore except by
removing/altering the rule that uses the anonymous set.

.*Using anonymous sets to accept particular subnets and ports*
----------
nft add rule filter input ip saddr { 10.0.0.0/8, 192.168.0.0/16 } tcp dport { 22, 443 } accept
----------

Named sets are sets that need to be defined first before they can be referenced
in rules. Unlike anonymous sets, elements can be added to or removed from a
named set at any time. Sets are referenced from rules using an @ prefixed to the
sets name.

.*Using named sets to accept addresses and ports*
------------------
nft add rule filter input ip saddr @allowed_hosts tcp dport @allowed_ports accept
------------------

The sets allowed_hosts and allowed_ports need to be created first. The next
section describes nft set syntax in more detail.

[verse]
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'
delete *set* ['family'] 'table' handle 'handle'
{add | delete} *element* ['family'] 'table' 'set' { 'element'[,...] }

Sets are elements containers of a user-defined data type, they are uniquely
identified by a user-defined name and attached to tables. Their behaviour can
be tuned with the flags that can be specified at set creation time.

[horizontal]
*add*:: Add a new set in the specified table. See the Set specification table below for more information about how to specify a sets properties.
*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
[options="header"]
|=================
|Keyword | Description | Type
|type |
data type of set elements |
string: ipv4_addr, ipv6_addr, ether_addr, inet_proto, inet_service, mark
|flags |
set flags |
string: constant, dynamic, interval, timeout
|timeout |
time an element stays in the set, mandatory  if  set is added to from the packet path (ruleset).|
string, decimal followed by unit. Units are: d, h, m, s
|gc-interval |
garbage collection interval, only available when timeout or flag timeout are
active |
string, decimal followed by unit. Units are: d, h, m, s
|elements |
elements contained by the set |
set data type
|size |
maximum number of elements in the set, mandatory if set is added to from the packet path (ruleset).|
unsigned integer (64 bit)
|policy |
set policy |
string: performance [default], memory
|auto-merge |
automatic  merge  of adjacent/overlapping set elements (only for  interval sets) |
|=================


MAPS
-----
[verse]
add *map* ['family'] 'table' 'map' { type 'type' [flags 'flags' ;] [elements = {'elements'[,...] } ;] [size 'size' ;] [policy 'policy' ;] }
{delete | list | flush} *map* ['family'] 'table' 'map'
{add | delete} *element* ['family'] 'table' 'map' { elements = { 'elements'[,...] } ; }

Maps store data based on some specific key used as input, they are uniquely identified by a user-defined name and attached to tables.

[horizontal]
*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
[options="header"]
|=================
|Keyword | Description | Type
|type |
data type of map elements |
string `:' string: 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 the map |
map data type
|size |
maximum number of elements in the map |
unsigned integer (64 bit)
| policy |
map policy |
string: performance [default], memory
|=================


FLOWTABLES
-----------
[verse]
{add | create} *flowtable* ['family'] 'table' 'flowtable' { hook 'hook' priority 'priority' ; devices = { 'device'[,...] } ; }
{delete | list} *flowtable* ['family'] 'table' 'flowtable'

Flowtables allow you to accelerate packet forwarding in software. Flowtables
entries are represented through a tuple that is composed of the input interface,
source and destination address, source and destination port; and layer 3/4
protocols. Each entry also caches the destination interface and the gateway
address - to update the destination link-layer address - to forward  packets.
The ttl and hoplimit fields are also decremented. Hence, flowtables provides an
alternative path that allow packets to bypass the classic forwarding path.
Flowtables reside in the ingress hook, that is located before the prerouting
hook. You can select what flows you want to offload through the flow offload
expression from the forward chain. Flowtables are identified by their address
family and their name. The address family must be one of ip, ip6, inet. The inet
address family is a dummy family which is used to create hybrid IPv4/IPv6
tables.  When no address family is specified, ip is used by default.

[horizontal]
*add*:: Add a new flowtable for the given family with the given name.
*delete*:: Delete the specified flowtable.
*list*:: List all flowtables.


STATEFUL OBJECTS
----------------
[verse]
{add | delete | list | reset} type ['family'] 'table' 'object'
delete type ['family'] 'table' handle 'handle'

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".

[horizontal]
*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.

include::stateful-objects.txt[]

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
~~~~~~~~~~~~~~~~
[verse]
*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

predefined 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.

include::data-types.txt[]

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.

include::primary-expression.txt[]

PAYLOAD EXPRESSIONS
-------------------
Payload expressions refer to data from the packet's payload.

include::payload-expression.txt[]

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.

include::statements.txt[]

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 carets (^). 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
--------
[verse]
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-2018 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 licensed 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/.