A firewall ruleset is a program. Reading one line in isolation can hide an earlier accept, a later drop, another base chain at a different priority, or a rule in a different protocol family. Start from the whole ruleset and follow the packet’s path.
Capture the current ruleset
sudo nft list rulesetFor tooling, request JSON rather than scraping the display format:
sudo nft --json list ruleset > ruleset.jsonThe ruleset can reveal internal addresses, interface names, exposed services, and counter volumes. Store it like other security configuration.
Read from the outside inward
The hierarchy is family, table, chain, then rule.1
- A family such as
ip,ip6,inet,arp,bridge, ornetdevdefines the packet context. - A table groups chains and objects inside one family.
- A base chain attaches to a networking hook and has a type and priority.
- A regular chain is reached by a jump or goto from another rule.
- A rule evaluates expressions and may return a verdict such as
accept,drop,jump, orreturn.1
For an inbound packet, identify every base chain attached to the relevant hook. Lower numeric priorities run earlier. A chain’s default policy applies when traversal reaches its end without an earlier final verdict.1
Use handles and counters
sudo nft --handle list ruleset
sudo nft --numeric list rulesetHandles identify rules for later changes. Numeric output avoids service-name lookups that can make ports harder to compare. Counters show that a rule matched traffic, but a zero counter does not prove the rule is wrong. The traffic may not have occurred since the counter was created or reset.
Sets and maps may hold the values that make a compact rule meaningful. Inspect referenced objects before deciding what the match covers.12
Check a candidate file
lab=$(mktemp -d)
candidate="$lab/candidate.nft"
cat > "$candidate" <<'EOF'
table inet demo_review {
chain input {
type filter hook input priority 0; policy accept;
ct state established,related accept
}
}
EOF
sudo nft --check --file "$candidate"Check mode validates commands without applying them. It is a useful gate, not a behavioral proof: a syntactically valid rule can still permit or block the wrong traffic.1
Remove the lab with trash "$lab" if trash is installed.
[!CAUTION] Never experiment with firewall changes over your only remote session. Keep console access or an automatic rollback, preserve the current ruleset, and use the system’s owning firewall manager rather than editing underneath it.