Quick reference-nftables in 10 minutes - nftables wiki
Quick reference-nftables in 10 minutes
From nftables wiki
Jump to navigation
Jump to search
Find below some basic concepts to know before using nftables.
table
refers to a container of
chains
with no specific semantics.
chain
within a
table
refers to a container of
rules
rule
refers to an action to be configured within a
chain
Contents
nft command line
1.1
Tables
1.2
Chains
1.3
Rules
1.3.1
Matches
1.3.1.1
Ip
1.3.1.2
Ip6
1.3.1.3
Tcp
1.3.1.4
Udp
1.3.1.5
Udplite
1.3.1.6
Sctp
1.3.1.7
Dccp
1.3.1.8
Ah
1.3.1.9
Esp
1.3.1.10
Comp
1.3.1.11
Icmp
1.3.1.12
Icmpv6
1.3.1.13
Ether
1.3.1.14
Dst
1.3.1.15
Frag
1.3.1.16
Hbh
1.3.1.17
Mh
1.3.1.18
Rt
1.3.1.19
Vlan
1.3.1.20
Arp
1.3.1.21
Ct
1.3.1.22
Meta
1.3.2
Statements
1.3.2.1
Verdict statements
1.3.2.2
Log
1.3.2.3
Reject
1.3.2.4
Counter
1.3.2.5
Limit
1.3.2.6
Nat
1.3.2.7
Queue
1.4
Extras
1.4.1
Export Configuration
1.4.2
Monitor Events
Nft scripting
2.1
List ruleset
2.2
Flush ruleset
2.3
Load ruleset
Examples
3.1
Simple IP/IPv6 Firewall
nft command line
nft
is the command line tool in order to interact with nftables at userspace.
Tables
family
refers to a one of the following table types:
ip
arp
ip6
bridge
inet
netdev
. It defaults to
ip
nft
list
tables

nft
-n
-a
list
table


nft
add
delete
flush
table


The argument
-n
shows the addresses and other information that use names in numeric format. The
-a
argument is used to display each rule's
handle
(i.e., a numerical identifier).
Chains
type
refers to the kind of chain to be created. Possible types are:
filter
: Supported by
arp
bridge
ip
ip6
and
inet
table families.
route
: Mark packets (like mangle for the
output
hook, for other hooks use the type
filter
instead), supported by
ip
and
ip6
nat
: In order to perform Network Address Translation, supported by
ip
and
ip6
hook
refers to an specific stage of the packet while it's being processed through the kernel. More info in
Netfilter hooks
The hooks for
ip
ip6
and
inet
families are:
prerouting
input
forward
output
postrouting
The hooks for
arp
family are:
input
output
The
bridge
family handles ethernet packets traversing bridge devices.
The hooks for
netdev
are:
ingress
egress
priority
refers to a number used to order the chains or to set them between some Netfilter operations. Possible values are:
NF_IP_PRI_CONNTRACK_DEFRAG (-400)
NF_IP_PRI_RAW (-300)
NF_IP_PRI_SELINUX_FIRST (-225)
NF_IP_PRI_CONNTRACK (-200)
NF_IP_PRI_MANGLE (-150)
NF_IP_PRI_NAT_DST (-100)
NF_IP_PRI_FILTER (0)
NF_IP_PRI_SECURITY (50)
NF_IP_PRI_NAT_SRC (100)
NF_IP_PRI_SELINUX_LAST (225)
NF_IP_PRI_CONNTRACK_HELPER (300)
policy
is the default verdict statement to control the flow in the base chain. Possible values are:
accept
(default) and
drop
. Warning: Setting the policy to
drop
discards all packets that
have not been accepted by the ruleset.
nft
add
create
chain



\{
type

hook

device

priority

\;
policy

\;
\}
nft
delete
list
flush
chain



nft
rename
chain




Rules
handle
is an internal number that identifies a certain
rule
nft
add
rule





nft
insert
rule



position



nft
replace
rule



handle



nft
delete
rule



handle

Inserted rules are placed at the beginning of the chain, by default. However, if you specify a
position
handle, then the new rule is inserted just before the existing rule with that handle.
Matches
matches
are clues used to access to certain packet information and create filters according to them.
Ip
ip match
dscp
ip
dscp
cs1
ip
dscp
cs1
ip
dscp
0x38
ip
dscp
0x20
ip
dscp
cs0,
cs1,
cs2,
cs3,
cs4,
cs5,
cs6,
cs7,
af11,
af12,
af13,
af21,
af22,
af23,
af31,
af32,
af33,
af41,
af42,
af43,
ef
length
Total packet length
ip
length
232
ip
length
233
ip
length
333
-435
ip
length
333
-453
ip
length
333
553
673
838
id
IP ID
ip
id
22
ip
id
233
ip
id
33
-45
ip
id
33
-45
ip
id
33
55
67
88
frag-off
Fragmentation offset
ip
frag-off
0x1fff
# match fragments
ip
frag-off
0x2000
# match MF flag
ip
frag-off
0x4000
# match DF flag
ttl
Time to live
ip
ttl
ip
ttl
233
ip
ttl
33
-55
ip
ttl
45
-50
ip
ttl
43
53
45
ip
ttl
33
-55
protocol
Upper layer protocol
ip
protocol
tcp
ip
protocol
ip
protocol
tcp
ip
protocol
icmp,
esp,
ah,
comp,
udp,
udplite,
tcp,
dccp,
sctp
checksum
IP header checksum
ip
checksum
13172
ip
checksum
22
ip
checksum
233
ip
checksum
33
-45
ip
checksum
33
-45
ip
checksum
33
55
67
88
ip
checksum
33
-55
saddr
Source address
ip
saddr
192
.168.2.0/24
ip
saddr
192
.168.2.0/24
ip
saddr
192
.168.3.1
ip
daddr
192
.168.3.100
ip
saddr
.1.1.1
ip
saddr
.1.1.1
ip
saddr
0xff
==
ip
saddr
.0.0.255
.0.0.127
daddr
Destination address
ip
daddr
192
.168.0.1
ip
daddr
192
.168.0.1
ip
daddr
192
.168.0.1-192.168.0.250
ip
daddr
10
.0.0.0-10.255.255.255
ip
daddr
172
.16.0.0-172.31.255.255
ip
daddr
192
.168.3.1-192.168.4.250
ip
daddr
192
.168.0.1-192.168.0.250
ip
daddr
192
.168.0.1-192.168.0.250
ip
daddr
192
.168.5.1,
192
.168.5.2,
192
.168.5.3
version
Ip Header version
ip
version
hdrlength

IP header length
ip
hdrlength
ip
hdrlength
15
Ip6
ip6 match
dscp
ip6
dscp
cs1
ip6
dscp
cs1
ip6
dscp
0x38
ip6
dscp
0x20
ip6
dscp
cs0,
cs1,
cs2,
cs3,
cs4,
cs5,
cs6,
cs7,
af11,
af12,
af13,
af21,
af22,
af23,
af31,
af32,
af33,
af41,
af42,
af43,
ef
flowlabel