Images of Nftables
Migrate iptables to nftables in CentOS 8iptables to nftablesAlthough Ansible provides support for managing firewall rules via module, I still find initial setup is best done with a tested batch of firewall rules instead of adding them one-by-one. Since I’m migrating CentOS 7 servers to CentOS 8 now, I decided to convert iptables into nftables.Will probably post a Unix Tutorial Project about this, but today I’m just capturing notes.What is nftables?nftables is the next (current) generation of NetFilter based firewall solutions, replacing iptables and providing backward compatible tools with iptables syntax.If all you used before is iptables, you can continue using familiar commands – but in CentOS 8 this means that on the firewall level there’s no longer iptables running, all the functionality is provided by NFT.How To Save iptables rules/chains into a file# iptables-save > /etc/sysconfig/iptables.currentHow to Convert iptables rules into nftables rules# iptables-restore-translate -f /etc/sysconfig/iptables.current > nft-rules.txtIMPORTANT: make sure you put this into some nft-rules.txt file outside of the /etc/sysconfig location – if things go wrong, you’ll just reboot server via hosting console and regain access.Try/Check NFT RulesetNow comes the moment to disable iptables and try NFT tables in their place.I did the following: flushed IPtables (removed any rules) and then applied NFT rules.Flush iptables# iptables -FApply NFT rules from nft-rules.txt file# nft -f nft-rules.txtWe can now have a look at the list of active NFT rules:# nft list rulesetConfigure nftables Rules to Apply upon RebootAssuming everything works as expected, we can now move the nfs-rules.txt file into default location that will be used by NFT upon reboot:# mv nft-rules.txt /etc/sysconfig/nftables.confMake sure it belongs to root and has correct permissions (it’s not a script so needs no execution bits):[email protected]:~ # ls -lad /etc/sysconfig/nftables.conf-rw-------. 1 root root 5227 Mar 12 01:48 /etc/sysconfig/nftables.confSee AlsoMigrate to nftablesUsing nftableskeep iptables after rebootBook review: iptables pocket referenceProtect SSH with fail2banUnix Tutorial ProjectsAnsible: getting started var disqus_config = function () { this.page.url = 'https://www.unixtutorial.org/migrate-iptables-to-nftables-in-centos-8/'; }; (function() { var d = document, s = d.createElement('script'); s.src = '//glebreys.disqus.com/embed.js'; s.setAttribute('data-timestamp', +new Date()); (d.head || d.body).appendChild(s); })(); Please enable JavaScript to view the comments powered by Disqus.