However, it would be nice with some kind of walkthrough, since the topic is a bit confusing. E.g. there is also the package iptables-nft, which I guess is another way to migrate than converting the iptables rules, and makes iptables use nftables underneath(?)
Just FYI, the iptables-nft package will soon be replaced by iptables using the nft interface and the legacy backend will be available as iptables-legacy.
sudo iptables-save > iptables-rules.txt
iptables-restore-translate -f iptables-rules.txt
# bunch of output of converted iptable rules now in nftable format
sudo nft list ruleset
# no output
So why is there no output when I make nft list the ruleset?
I had planned to follow up with enabling and starting the nftable service, but since the ruleset is empty I don’t see much point.
One very important thing is not to store counter state in /etc/nftables.com since that will make counters not update as expected when doing something on the network and monitoring by watching the counters.
sudo watch -d -n 1 'nft list table ip filter`
It’s a trap I got caught in because I wrote the output from nft list ruleset directly into nftables.conf with counter information. The solution is to do some cleanup.
# This does not work - counter information is bad in nftable.conf
chain FORWARD {
type filter hook forward priority filter; policy drop;
counter packets 276 bytes 108725 jump DOCKER-USER
counter packets 276 bytes 108725 jump DOCKER-FORWARD
}
# Remove counter state :-)
chain FORWARD {
type filter hook forward priority filter; policy drop;
counter jump DOCKER-USER
counter jump DOCKER-FORWARD
}
Removing counter state from nftable.conf will make counters update as expected.
I had some trouble with Docker. So here’s what I did.
Install the package iptables-nft. By doing this Docker will still “think” that it uses iptables but in reality it’s just a wrapper around nftables. The package will also remove the old iptable package.
I had a fun time debuging the firewall, because of the drop policy on the inet filter on the forward chain. To enable Docker containers to initiate outbound communication make some rules for that in the /etc/nftable.conf file - Docker won’t do it, since it does not know your security model.
I’ve added two rules for accepting packets if the incoming interface is either docker0 or some bridge created by Docker, which requires a wildcard br-*.
table inet filter {
chain forward {
type filter hook forward priority filter; policy drop;
ct state { established, related } accept
ct state invalid drop
iifname "docker0" accept
iffname "br-*" accept
counter
}
}
And that’s it.
It could be fun (at some time) to try using Docker with the experimental support for nftables by adding /etc/docker/daemon.json with the content
{
"firewall-backend": "nftables"
}
But I have already had more drama than I need for today - I’m not a total masochist
Does that mean that the package iptables-nft will be renamed to iptables?
And does that also mean that systems will switch from iptables to nftables automatically?