What it does
nftables replaced iptables. firewalld writes its rules into nftables (table inet firewalld). With nft list ruleset you see what the kernel really does. On systems with firewalld, use firewall-cmd for changes; write nft rules yourself only on systems without firewalld (then use nftables.service and /etc/sysconfig/nftables.conf).
How to write it
nft [OPTION]... COMMAND
nft -f FILEMain parts
listruleset- Show all rules.
listtables/listtableFAMILYNAME- Tables.
listchainFAMILYTABLECHAIN- One chain.
addtable,addchain,addrule- Create.
insertrule,replacerule,deleterulehandleN- Change rules.
addset,addelement- Address or port sets.
flushruleset- Remove all rules (dangerous).
monitor- Watch rule changes and traces.
FAMILY- ip, ip6, inet (both), arp, bridge, netdev.
Options 18
Most used
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1All rules
nft list ruleset | lessIncludes the rules firewalld made.
2Tables
nft list tables table inet firewalldfirewalld's table.
3firewalld zone rules
nft list chain inet firewalld filter_IN_public_allowThe services of the public zone as rules.
4Rules with handles
Handles identify single rules.
5Check a rules file
nft -c -f /etc/sysconfig/nftables.confSyntax check before loading.
6A simple firewall without firewalld
nft add table inet filter nft add chain inet filter input '{ type filter hook input priority 0; policy drop; }' nft add rule inet filter input ct state established,related accept nft add rule inet filter input iif lo accept nft add rule inet filter input tcp dport 22 acceptOnly on systems where firewalld is off.
7Block a list of attackers with a set
nft add set inet filter blocklist '{ type ipv4_addr; }' nft add element inet filter blocklist '{ 203.0.113.50 }' nft add rule inet filter input ip saddr @blocklist dropSets scale to many addresses.
8Save the current rules
nft list ruleset > /etc/sysconfig/nftables.confLoaded by nftables.service at boot.
9Watch rule changes
nft monitorShows changes live (for example from firewall-cmd).
10JSON for tools
nft -j list ruleset | jq '.nftables | length'Machine-readable.
Nothing matches this filter.
Watch out
- Do not change firewalld's tables by hand; a reload overwrites them.
flush rulesetwith a drop policy can cut your SSH session.
Files
/etc/sysconfig/nftables.conf- Rules for nftables.service.
/etc/nftables/- Example rule files.
Exit codes
0 :: Done. 1 :: Error.