Securing your network is a critical aspect of maintaining a robust IT infrastructure, and Red Hat Enterprise Linux (RHEL) provides a powerful tool for this purpose with its integrated firewall, firewalld. Understanding how to manage and configure firewalld rules is essential for ensuring the security of your systems. This article will guide you through the process of creating and managing firewall rules in RHEL using firewalld.

Before we dive into creating rules, let's briefly understand what firewalld is. Firewalld is a dynamic firewall management tool that uses iptables and nftables as its backend. It provides a simple and intuitive way to manage firewall rules, making it easier to configure and maintain than traditional iptables-based firewalls.

Understanding Firewalld Zones
In firewalld, rules are organized into zones, which are groups of network interfaces with similar security requirements. Understanding these zones is crucial for creating effective firewall rules.

RHEL comes with several predefined zones: drop, block, public, external, dmz, work, and trusted. Each zone has a default set of services and ports open, and you can create custom zones to fit your specific needs.
Default Zones

Here's a brief overview of the default zones:
- drop: Drops all incoming traffic and allows all outgoing traffic.
- block: Similar to drop, but logs the blocked traffic.
- public: Allows incoming traffic from trusted networks, like your home network.
- external: Allows incoming traffic from untrusted networks, like the internet.
- dmz: Allows incoming traffic from both trusted and untrusted networks.
- work: Similar to public, but with fewer services open by default.
- trusted: Allows all incoming traffic and is typically used for internal networks.
Creating Custom Zones

To create a custom zone, use the following command:
firewall-cmd --permanent --new-zone=myzone
Then, you can add rules to this zone as needed.
Managing Firewall Rules

Now that we understand zones, let's look at how to manage rules within these zones.
Firewalld uses a simple command-line tool, firewall-cmd, to manage rules. This tool allows you to add, remove, and list rules, as well as check the status of the firewall.




















Adding Rules
To add a rule to a zone, use the following command:
firewall-cmd --permanent --zone=myzone --add-service=ssh
This command adds the SSH service to the myzone zone, allowing incoming SSH traffic.
Removing Rules
To remove a rule, use the following command:
firewall-cmd --permanent --zone=myzone --remove-service=ssh
This command removes the SSH service from the myzone zone, blocking incoming SSH traffic.
Listing Rules
To list all rules in a zone, use the following command:
firewall-cmd --zone=myzone --list-all
This command displays all rules in the myzone zone.
After making changes to the firewall rules, you must reload the firewall service for the changes to take effect:
firewall-cmd --reload
Remember, firewalld rules are persistent across reboots by default. If you want to make temporary changes, use the --runtime option instead of --permanent.
In the dynamic world of cybersecurity, it's crucial to stay proactive and vigilant. Regularly reviewing and updating your firewall rules ensures that your systems remain secure and protected from emerging threats. Happy securing!