How to flush and restore nftables rules from /etc/nftables.conf

nftables

For iptables I used to run iptables-restore < /etc/iptables/rules.v4 which would flush rules and restore them from /etc/iptables/rules.v4.

For nftables, I found nft -f /etc/nftables.conf, but the rules are not flushed* prior to restoring them from /etc/nftables.conf.

Is there a one-liner that flushes nftables rules and restores them from a file?

*Note that any rules already loaded are not automatically flushed.

Best Answer

Adding flush ruleset at the beginning of /etc/nftables.conf does the trick. See the notes on https://wiki.nftables.org/wiki-nftables/index.php/Atomic_rule_replacement.