LinuxCommandLibrary

nft

command-line interface for nftables, the modern Linux kernel packet filtering

TLDR

List current ruleset

$ sudo nft list ruleset
copy
Add table
$ sudo nft add table inet filter
copy
Add chain
$ sudo nft add chain inet filter input \{ type filter hook input priority 0 \; policy accept \; \}
copy
Add rule for ports
$ sudo nft add rule inet filter input tcp dport \{ ssh, http, https \} accept
copy
Add NAT masquerade rule
$ sudo nft add rule nat postrouting ip saddr 192.168.0.0/24 masquerade
copy
Show rule handles
$ sudo nft --handle --numeric list chain family table chain
copy
Delete rule
$ sudo nft delete rule inet filter input handle 3
copy
Save configuration
$ sudo nft list ruleset > /etc/nftables.conf
copy

SYNOPSIS

nft [OPTIONS] [commands]

DESCRIPTION

nft is the command-line interface for nftables, the modern Linux kernel packet filtering framework. It replaces iptables, ip6tables, arptables, and ebtables with a unified syntax and improved performance.

PARAMETERS

list ruleset

Display the current complete ruleset
add table family name
Create a new table
add chain family table chain specification
Create a new chain
add rule family table chain statement
Add a rule to a chain
delete rule family table chain handle n
Delete a rule by its handle
flush ruleset
Remove all rules and tables
--handle
Show rule handles for deletion
--numeric
Show numeric output (no name resolution)

CAVEATS

Nftables syntax differs significantly from iptables. Tables must exist before chains, chains before rules. Changes are immediate but not persistent by default - save to /etc/nftables.conf for persistence.

HISTORY

nft is part of the nftables project, the successor to iptables, providing unified packet classification framework in the Linux kernel.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community