Since Debian 10, iptables has been living on borrowed time. When you configure nftables on Debian 12, you are using the modern, native packet-filtering framework that replaced iptables, ip6tables, arptables, and ebtables with a single tool and a single ruleset syntax. It is faster, easier to audit, and it is what Debian’s own firewall packages now build on.
This guide shows how to set up nftables on Debian 12 from scratch: understanding tables, chains, and rules; writing a safe baseline ruleset for a typical server; allowing SSH, HTTP, and HTTPS; rate-limiting connection attempts; and making the rules survive a reboot. We will also cover the mistakes that lock administrators out of their own servers — and how to avoid them.
Why nftables on Debian 12 Instead of iptables? – How to Configure nftables Firewall on
On Debian 12, the iptables commands you may remember are actually a compatibility layer (iptables-nft) that translates your rules into nftables under the hood. Working with nft directly has real advantages:
- One ruleset for IPv4 and IPv6 using
inetfamily tables, instead of maintaining parallel rules. - Readable, file-based configuration that looks like a real config file, not a long list of commands.
- Better performance thanks to sets and maps that match many addresses or ports in one rule.
- Atomic updates — a new ruleset loads completely or not at all, never half-applied.
To see what is currently loaded on your system, run sudo nft list ruleset. On a clean Debian 12 install it is usually empty, which means everything is allowed — exactly what we are going to fix.

Core Concepts: Tables, Chains, and Rules – How to Configure nftables Firewall on
An nftables ruleset is organized in three levels. A table groups chains for one address family (use inet to cover IPv4 and IPv6 together). A chain is a list of rules attached to a hook such as input, output, or forward, with a default policy of accept or drop. A rule matches packets and applies a verdict such as accept, drop, or counter.
For a standalone server we only need one table with three chains: filter input with policy drop, filter forward with policy drop (a server does not route packets), and allow output.
Step 1: Install and Enable nftables on Debian 12
Install the package and enable the service so the ruleset in /etc/nftables.conf loads at boot:
sudo apt update && sudo apt install -y nftables
sudo systemctl enable nftables
Step 2: Write a Baseline Ruleset
Replace the contents of /etc/nftables.conf with the following server baseline. It drops unsolicited incoming traffic while keeping your management access and web services reachable:
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
iif "lo" accept
ct state established,related accept
ct state invalid drop
# ICMP and ICMPv6 (needed for IPv6 neighbor discovery)
ip protocol icmp accept
ip6 nexthdr icmpv6 accept
# SSH with connection rate limiting
tcp dport 22 ct state new limit rate over 15/minute burst 5 packets drop
tcp dport 22 accept
# Web traffic
tcp dport { 80, 443 } accept
}
chain forward {
type filter hook forward priority 0; policy drop;
}
chain output {
type filter hook output priority 0; policy accept;
}
}
Notice the set syntax { 80, 443 }: one rule opens both web ports. This is one of the small quality-of-life improvements that make nftables rulesets pleasant to maintain.
Step 3: Validate and Load the Ruleset
Before loading anything, keep your current SSH session open. Validate the file syntax first — the -c flag checks without applying:
sudo nft -c -f /etc/nftables.conf
If there are no errors, load it and confirm:
sudo systemctl restart nftables
sudo nft list ruleset
Immediately open a new SSH connection in a second terminal to prove you can still log in. Only close the original session after the new one works. The Debian Wiki nftables page is the authoritative reference for Debian-specific details.
Common Rules You Will Add Later
Restricting SSH to your office IP address is the single most effective hardening step:
tcp dport 22 ip saddr 203.0.113.10 accept
For a database that only your application server may reach:
tcp dport 5432 ip saddr 10.0.0.5 accept
Add such rules inside the input chain before it ends, re-run the syntax check, and reload. Because the file is the single source of truth, your firewall stays reproducible and reviewable in version control.
Migrating from UFW or iptables
If you previously used UFW (as in our guide to configuring UFW on Ubuntu), disable it before enabling nftables so two frameworks do not fight: sudo ufw disable and stop its service. Existing raw iptables rules can be translated automatically with iptables-restore-translate, but for most servers rewriting the handful of rules by hand produces a cleaner result.
Troubleshooting
A service is unreachable after enabling the firewall
Check whether the port is actually listening with ss -tulpn, then verify a matching accept rule exists in nft list ruleset. Test locally with curl localhost:PORT to separate firewall problems from application problems.
IPv6 stopped working entirely
You blocked ICMPv6, which IPv6 needs for neighbor discovery and path MTU detection. Always keep the ip6 nexthdr icmpv6 accept rule in inet tables.
Rules disappeared after reboot
The rules were loaded interactively with nft add but never saved to /etc/nftables.conf, or the nftables service is not enabled. Save the live ruleset with sudo nft list ruleset > /etc/nftables.conf (keeping the shebang line) and run systemctl enable nftables.
Conclusion
Learning to configure nftables on Debian 12 pays off on every server you touch afterward: one readable file defines your entire packet policy for IPv4 and IPv6, loads atomically, and survives reboots through the nftables service. Start from the default-deny baseline above, open only the ports each service truly needs, and keep SSH restricted and rate-limited. Combined with key-only SSH login and regular updates, this is the firewall foundation we recommend for every Debian deployment.