r/linuxadmin • u/Beneficial-Sock-5130 • Jun 08 '26
does anyone find nftables better than iptables?
Upgraded OS on rocky10 server last weekend, newest kernel doesnt bake in legacy iptables mods, so iptables rules cant get loaded
I start looking into nftables, it seems like a verbose nightmare compared to iptables, every command has to be typed out, no short version of commands
something that was simple w iptables
forward any request from ServerA port 80 to ServerB port 80 on server A
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination <IP of serverB>:80
iptables -t nat -A POSTROUTING -p tcp -j MASQUERADE
becomes this word salad
nft add table ip natnft add chain ip nat PREROUTING { type nat hook prerouting priority dstnat \; policy accept \; }nft add chain ip nat POSTROUTING { type nat hook postrouting priority srcnat \; policy accept \; }
nft add rule ip nat PREROUTING tcp dport 80 dnat to <IP of serverB>:80nft add rule ip nat POSTROUTING masquerade
whats the upside?
what was wrong w iptables?
15
u/Stenstad Jun 08 '26
Have you tried looking into a tool like firewalld instead of poking everything directly?
50
u/rankinrez Jun 08 '26
You’re just used to something else.
When you get used to nftables you’ll find it’s much better.
And sure, there are no predefined chains/tables you gotta add them yourself. But it’s very little effort most just add the normal input/output/forward etc
When you get used to it it’s both simpler and more powerful imo
27
u/thorhs Jun 08 '26
Nftables, all day, every day, hands down. Atomic reloads, easy edit of config file, easy support for re-generating fá config with automation, support for multiple encoding tools simultaneously (eg firewalld and kube) and many more.
22
u/meditonsin Jun 08 '26
Instead of calling a million individual commands like that, you could also just do it declaratively in a config file, which is a lot more readable and easier to modify:
8
u/wezelboy Jun 08 '26
I use the iptables translation layer, primarily because I use Firewall Builder and it doesn't offer native nftables support. It seems to work just fine.
8
u/britaliope Jun 08 '26
Once you're used to nft it feels so much better.
Don't use the CLI too much. Create a config file, make incremental changes to it and reload it once you made your modifications.
2
u/Beneficial-Sock-5130 Jun 08 '26
its the same w network manager, there was nothing wrong with older sysconfig files, they roll out NM and its a shitshow, just config nightmare
5
u/jess-sch Jun 08 '26 edited Jun 08 '26
The cli syntax might be a bit cumbersome (though still better than iptables if you haven't memorized all the flags) but that's cuz you're using it wrong.
Use an nftables configuration file. It's so much more readable than a list of iptables commands. Plus it applies atomically.
Also inet rules (which apply for both ipv4 and ipv6) are pretty convenient.
5
u/Brave_Confidence_278 Jun 08 '26
nftables is quite nice if you store it in a file with proper formatting.
3
u/CardOk755 Jun 08 '26
You don't have the compatibility version of iptables?
2
u/Unnamed-3891 Jun 08 '26
I used simple text based config files with iptables and continue doing exactly that with nftables. Much better than dealing with XML horror of ufw and whatnot.
2
u/Maitreya83 Jun 08 '26
When you use a tool for 30 years, you'll start to see it as normal and easy.
In a couple of years you'll have the inverse when you look at a old machine with iptables "what was that syntax again?"
2
u/Hynch Jun 08 '26
I used to dislike nft at first, but as CIS start shifting towards it in their benchmarks (iptables has been deprecated for some time now) I had to learn it. I find it much easier to configure now and prefer it to iptables. You'll find that on most modern distros, iptables is really just iptables-nft which is an iptables front end syntax with the backend firewall actually being nftables.
2
u/apxseemax Jun 09 '26
I can't handle either. Those cryptic snake rules just do not stick to my synapses and fuck with my brain in a weird way. Same goes for regex. While I find the concepts super interesting, they also are equally good nightmare fuel.
2
u/yrro Jun 09 '26 edited Jun 09 '26
nft is immeasurably better in all aspects save for the truly awful lack of documentation (and to be fair I hate running
nft,Error: syntax error, unexpected newline, expecting string or lastis an absolutely useless error message!)I think people only prefer iptables for that reason & because of familiarity. Structural, performance and composability problems aside, its UX was never good in the first place, it's just that we've been using it for 25 years so we no longer see the awfulness.
2
u/boards188 Jun 09 '26
nftables is MUCH better than iptables...for all the reasons already listed. But what sold me, was the ability to block an ip for 72 hours based on a failed authentication. No additional software needed.
2
u/Ancient-Opinion9642 Jun 08 '26
Nftables I found as better. I could make a static firewall and during starting nftables I could add active IP addresses at the end using a bash script.
1
u/btk667 Jun 08 '26
Have to admit, iptables was easy for me.. (Easier..)
1
u/Il_Falco4 Jun 08 '26
Nftables hands down because of the one static config file. Create a basic and copy over to new servers. Easy syntax on the file. Forget cli edits, not worth it.
1
u/jagardaniel Jun 08 '26
I'm just a simple user but I switched over from iptables on my home router years ago and I like it better. The syntax feels strange at first but you get used to it. Now it feels... more human? I don't have IPv6 anymore but it was nice to be able to use the same chain for both v4 and v6. No more separate configuration files that have almost the same rules. My nftables configuration is in a file and I only use the nft command to apply new changes.
1
u/iheartrms Jun 09 '26
While we're here talking iptables vs nftables: Is there any nftables enabled version of shorewall or something similar yet? I really liked shorewall.
1
u/GamerLymx Jun 10 '26
use firewalld
1
u/Adept_Percentage6893 Jun 11 '26
It becomes word salad because you have to add a table rather than assuming it already exists? If anything separating them out into different commands makes it more readable to people who don't understand firewalls that well.
2
u/dosman33 Jun 08 '26
I mean, if you've been writing iptables rules for decades, and then are forced to choose between firewalld and nftables, anything is better than reinventing the wheel with firewalld. Firewalld should die in a fire. Your iptables rule sets you've crafted over decades translate to nftables very easily. Yea, it is annoying having to change though, ngl.