Migrate iptables to nftables in CentOS 8
iptables to nftables
Although 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
How to Convert iptables rules into nftables rules
IMPORTANT: 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 Ruleset
Now 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
Apply NFT rules from nft-rules.txt file
We can now have a look at the list of active NFT rules:
Configure nftables Rules to Apply upon Reboot
Assuming everything works as expected, we can now move the nfs-rules.txt file into default location that will be used by NFT upon reboot:
Make sure it belongs to root and has correct permissions (it’s not a script so needs no execution bits):
See Also
- Migrate to nftables
- Using nftables
- keep iptables after reboot
- Book review: iptables pocket reference
- Protect SSH with fail2ban
- Unix Tutorial Projects
- Ansible: getting started
iptables to nftables
Although 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
How to Convert iptables rules into nftables rules
IMPORTANT: 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 Ruleset
Now 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
Apply NFT rules from nft-rules.txt file
We can now have a look at the list of active NFT rules:
Configure nftables Rules to Apply upon Reboot
Assuming everything works as expected, we can now move the nfs-rules.txt file into default location that will be used by NFT upon reboot:
Make sure it belongs to root and has correct permissions (it’s not a script so needs no execution bits):
See Also
- Migrate to nftables
- Using nftables
- keep iptables after reboot
- Book review: iptables pocket reference
- Protect SSH with fail2ban
- Unix Tutorial Projects
- Ansible: getting started