nftables¶
Tested with nftables 1.0.9 and systemd 255 on Ubuntu 24.04, on a host that also runs Kubernetes (k3s) rules.
Default-deny that does not lock you out¶
Set up the revert first, then load. If the new rules cut your SSH session, the timer removes them two minutes later.
# 1. Arm the revert: in 120 s, delete the table this ruleset creates.
sudo systemd-run --unit=nft-revert --on-active=120 --timer-property=AccuracySec=1s \
nft delete table inet filter
# 2. Validate, then load. `nft -c` parses without applying.
sudo nft -c -f /etc/nftables.conf && sudo nft -f /etc/nftables.conf
# 3. Still connected? Cancel the revert.
sudo systemctl stop nft-revert.timer
Delete only the table you added. nft flush ruleset as a revert also deletes
Docker's and Kubernetes' rules, and restoring a saved copy of the whole ruleset
fails on those (unsupported xtables compat expression). If your
/etc/nftables.conf begins with flush ruleset, it has the same effect when
you load it, so on container hosts start it with table inet filter and
flush table inet filter instead.