Build a least-privilege Linux firewall with nftables
8 steps · about 2 h 28 min · Intermediate
- Learn the nftables rule model (guide, nftables wiki, 18 min)
Tables, chains, hooks and rules replace assumptions carried over from older firewall tools.
- Choose hooks and default policies (guide, nftables wiki, 20 min)
Base-chain placement and policy determine what traffic is evaluated and what happens when no rule matches.
- Match interfaces protocols and state (guide, nftables wiki, 20 min)
Precise metadata matches keep rules narrow and readable instead of opening broad address ranges.
- Preserve established connections (guide, nftables wiki, 18 min)
Connection tracking lets reply traffic continue while new inbound connections remain controlled.
- Group related addresses and ports (guide, nftables wiki, 18 min)
Named sets reduce duplicated rules and make later service changes safer to review.
- Log useful drops without flooding (guide, nftables wiki, 16 min)
Rate-limited logging provides evidence while avoiding a noisy rule that overwhelms the journal.
- Validate and apply a ruleset (guide, nftables wiki, 20 min)
Rule-management commands show how to inspect, add and remove policy changes deliberately.
- Trace packets and prove the policy (guide, nftables wiki, 18 min)
Tracing shows the exact chain and verdict for a test packet so verification is based on evidence.