brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: nft list ruleset shows the active nftables firewall rules

Linux
~/tips/tip-networking-nft-list-ruleset

sudo nft list ruleset

Prints every table, chain and rule that nftables currently has loaded in the kernel.

A firewall you cannot see is a firewall you cannot trust. On modern Linux, nftables holds the rules, and one command prints all of them.

sudo nft list ruleset
sudo nft -a list ruleset

The output lists each table and its chains, with the rules in order. The -a option adds handles, which are the numbers you need when you want to delete one specific rule later. Listing is read-only, so it is safe to run on a live system.

The nftables wiki also describes per-family listings, for example sudo nft list ruleset ip, which only prints the IPv4 tables. With --json, the same content is printed as JSON for scripts.

The output of list ruleset can be fed back to nft -f, which makes it the nftables counterpart of iptables-save. I would still save the file somewhere safe before touching anything on a remote machine, because a bad firewall change can lock you out.

The caveat is empty output. nftables does not create tables by default, so a machine that prints nothing may simply have no rules, or it may use another tool. Also, the Arch wiki warns that nft list does not print variable definitions, so rules saved from this output lose the variables you used in your config file.

Further reading: nftables wiki: operations at ruleset level, nft(8) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link