๐Ÿ”ฅ Modern Firewall Management with nftables on RHEL-Based Systems (AlmaLinux, CentOS, Rocky Linux) Print

  • 0

๐Ÿš€ Introduction

RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux marks a significant evolution in Linux firewall management by adopting nftables as its default packet filtering framework. This article provides an in-depth look at nftables on RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux--explaining its architecture, benefits over legacy systems, basic command usage, and best practices for configuration and management.


๐Ÿ“Œ 1๏ธโƒฃ What is nftables?

nftables is a modern packet filtering framework introduced to replace the older iptables-legacy system. It simplifies rule management and improves performance while offering enhanced flexibility through sets, maps, and stateful filtering.

๐Ÿ”น Key Features:

โœ… Simplified Syntax

  • Uses a more streamlined language for defining firewall rules, reducing complexity in large rule sets.

โœ… Efficient Rule Handling

  • Processes rules more efficiently, particularly for complex filtering requirements or high packet rates.

โœ… Enhanced Flexibility

  • Supports sets and maps, allowing administrators to group IP addresses, ports, or protocols together for easier management.

โœ… Stateful Filtering

  • Natively supports connection tracking, enabling dynamic and intelligent packet filtering.


๐Ÿ† 2๏ธโƒฃ Why RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux Uses nftables

RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux has moved away from iptables-legacy in favor of nftables for several reasons:

๐Ÿ”น Performance Improvements

  • Handles high volumes of traffic more efficiently.

๐Ÿ”น Modern Architecture

  • Reduces redundancy and complexity, making rule management and debugging easier.

๐Ÿ”น Future-Proofing

  • With widespread adoption across Linux distributions, nftables is the sustainable solution for evolving security needs.

Unlike some distributions where you can switch between iptables-legacy and nftables, RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux uses nftables by default with an iptables-nft compatibility layer, meaning traditional iptables commands are automatically translated into nftables rules.


๐Ÿ› ๏ธ 3๏ธโƒฃ Basic nftables Commands

๐Ÿ”Ž Viewing the Entire Ruleset

nft list ruleset

๐Ÿ“Œ This displays all tables and chains currently loaded into nftables.

โž• Adding a New Rule

nft add rule ip filter INPUT ip saddr 192.168.1.0/24 accept

๐Ÿ“Œ This rule allows traffic from 192.168.1.0/24 in the INPUT chain of the ip filter table.

โŒ Deleting a Rule

nft delete rule ip filter INPUT handle <rule_handle>

๐Ÿ“Œ Find the rule handle from the output of nft list ruleset before deleting.

๐Ÿ’พ Save and Restore Rules

โœ… Save your configuration:

nft list ruleset > /etc/nftables.conf

โœ… Restore your ruleset after a reboot:

nft -f /etc/nftables.conf

โš™๏ธ 4๏ธโƒฃ Configuring Persistence

To ensure that nftables rules persist after a reboot:

โœ… Enable the Service:

systemctl enable nftables

โœ… Start the Service:

systemctl start nftables

๐Ÿ“Œ The nftables service will automatically load /etc/nftables.conf during system startup.


๐Ÿ—๏ธ 5๏ธโƒฃ Best Practices for Managing nftables on RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux

โœ… Use Configuration Files

  • Always manage firewall rules via configuration files, avoiding direct kernel changes where possible.

๐Ÿ”„ Backup Your Configuration

  • Before making changes, backup your ruleset:

cp /etc/nftables.conf /etc/nftables.conf.bak

๐Ÿ›  Test Rules in a Controlled Environment

  • Apply new rules on a test server or during a maintenance window to prevent disruptions.

๐Ÿ“Š Leverage Sets and Maps

  • Use nftables' powerful grouping features for easier management of large or dynamic IP lists.

๐Ÿ“ˆ Regularly Review Active Rules

nft list ruleset
  • Periodically review active rules to ensure they align with security policies.


๐ŸŽฏ 6๏ธโƒฃ Conclusion

nftables on RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux provides a modern, efficient, and flexible approach to firewall management. By moving away from iptables-legacy, RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux simplifies firewall rule handling while improving performance and scalability.

๐Ÿš€ Key Takeaways:

โœ”๏ธ nftables is faster and more efficient than iptables-legacy. โœ”๏ธ RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux automatically translates iptables commands into nftables rules. โœ”๏ธ Use configuration files and best practices to ensure persistence and security. โœ”๏ธ Regularly review rulesets to maintain a secure firewall configuration.

By understanding and utilizing nftables, administrators can effectively manage firewalls on RHEL-based distributions like AlmaLinux, CentOS, and Rocky Linux, taking full advantage of its enhanced security and performance capabilities. ๐Ÿ”ฅ๐Ÿ”’


Was this answer helpful?

« Back