nftables Error: 'nft: Error: Could not process rule: No such file or directory' — Cause, Fix, and Troubleshooting Guide
Fix nft 'Could not process rule: No such file or directory': missing table/chain, unloaded kernel module, or wrong family. Diagnose and build rulesets safely.
- #security
- #hardening
- #troubleshooting
- #linux
- #nftables
Stuck on this DevOps Security & Hardening error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
What this error means
nft tried to add a rule but the object it depends on — the table, the chain, or a kernel feature — does not exist, so the kernel returns ENOENT and nft reports the rule could not be processed. The confusing part is that the “file or directory” is really a firewall object, not a path on disk.
nft: Error: Could not process rule: No such file or directory
add rule inet filter input tcp dport 22 accept
^^^^^^^^^^^^
The caret under the failing token tells you which reference nft could not resolve — usually a table/chain that was never created, or a family mismatch.
How it manifests on the host
nft add rule ...fails immediately withCould not process rule: No such file or directory.nft -f /etc/nftables.confaborts partway, leaving a half-applied ruleset.- A rule referencing a set or map fails even though the set name looks correct.
- The same rule works on one host but fails on a minimal/container kernel.
System configuration causes
- Missing table. You added a rule into
inet filterbut never ranadd table inet filter. - Missing chain. The table exists but the target chain (e.g.
input) was not created with a hook. - Family mismatch. The rule targets
ip filterwhile the table was created asinet filter(or vice versa). - Ordering in a script. A ruleset file references a set/chain defined later in the same file.
- Missing kernel module/feature.
nf_tablesor a specific expression (e.g.nftablesconnection tracking) is not available on a stripped-down kernel.
Interrogating the host
# What tables and chains actually exist right now?
sudo nft list ruleset
sudo nft list tables
# Is the nftables kernel subsystem present?
lsmod | grep -E 'nf_tables|nft_'
sudo modprobe nf_tables && echo loaded
# Validate a ruleset file without committing it (checks syntax + object refs)
sudo nft -c -f /etc/nftables.conf
nft -c -f performs a dry run and reports the exact line/object that cannot be resolved, which is faster than trial and error on a live ruleset.
Remediation
1. Create the table and chain before adding rules (the most common fix):
sudo nft add table inet filter
sudo nft add chain inet filter input '{ type filter hook input priority 0; policy drop; }'
sudo nft add rule inet filter input tcp dport 22 accept
2. Match the family consistently. Decide on inet (covers IPv4+IPv6) and use it everywhere the object is referenced.
3. Order a ruleset file correctly — define tables, then sets/maps, then chains, then rules — and validate before loading:
sudo nft -c -f /etc/nftables.conf # dry run; fix the flagged line
sudo nft -f /etc/nftables.conf # apply atomically
4. Load the kernel module on minimal hosts and make it persist:
sudo modprobe nf_tables
echo nf_tables | sudo tee /etc/modules-load.d/nftables.conf
Hardening the host
- Use
nft -ffor whole-file loads: it applies atomically, so a bad line leaves the previous ruleset intact rather than a half-applied one. - Never mix
iptables-legacyandnfttooling on the same host — coexisting rulesets cause confusingENOENT/ordering failures. - Flushing and reloading over SSH can lock you out; stage a rollback (
atjob or console access) before applyingpolicy drop. inettables simplify dual-stack hosts; splittingipandip6doubles the objects you must keep in sync.
Related system errors
- firewalld ‘COMMAND_FAILED’ iptables Error Guide
- ufw ‘problem running ufw-init’ Error Guide
- CIS Benchmark Hardening for Linux Servers
Fixed it? Get 500 DevOps Security & Hardening & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Stuck on this? Start guided troubleshooting
Open an interactive diagnostic session with this error already loaded. Work a step-by-step plan, record what each check returns, land on a root cause, and export a clean incident summary — no account needed to start.
Did this fix your issue?
Solved it a different way?
Share the fix that worked for you — reviewed, then published to help the next engineer.
That looks like it may contain a secret (key, token, password, or connection string). Please remove it — a note with a detected secret can’t be published.
Thanks — that helps. Published notes appear after a quick review.
Trending errors this week
The error guides other engineers are actually reading right now.
- 1mount: wrong fs type, bad option, bad superblock
- 2Docker 'failed to set up container networking': Fix the Bridge and IP Pool
- 3Docker 'failed to create shim task': How to Fix the containerd Runtime Error
- 4Transport endpoint is not connected
- 5modprobe: FATAL: Module not found
- 6mount: wrong fs type, bad option, bad superblock
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.