In the realm of Linux network security, firewalld has emerged as a robust and user-friendly solution for managing firewall rules. This service, available in modern Linux distributions like CentOS, RHEL, and Fedora, provides a dynamic and efficient way to control incoming and outgoing network traffic. Let's delve into the world of firewalld and explore how to list firewall rules in this powerful tool.

Before we dive into listing rules, it's crucial to understand that firewalld operates using zones and services. Zones define the trust level of network interfaces, while services represent specific network services like SSH, HTTP, or DNS. By combining these concepts, we can create intricate firewall rules to safeguard our Linux systems.

Understanding Firewalld Zones and Services
To effectively manage firewall rules, we must first grasp the fundamentals of zones and services in firewalld. Zones are network profiles that determine the level of trust for network interfaces. Common zones include public, internal, dmz, and work. Services, on the other hand, represent specific network services that can be allowed or blocked by the firewall.

By default, firewalld comes with a predefined set of zones and services. However, you can create custom zones and services to cater to your specific network requirements. Understanding these concepts is vital for listing and managing firewall rules effectively.
Listing Available Zones

To list the available zones in firewalld, we can use the following command in the terminal:
firewall-cmd --get-zones
This command will display a list of all the zones currently defined in the system. You can also use the --list-all-zones option to show detailed information about each zone, including their default and current settings:
firewall-cmd --list-all-zones
Listing Available Services

Similarly, to list the available services in firewalld, we can use the following command:
firewall-cmd --get-services
This command will display a list of all the services currently defined in the system. To view detailed information about each service, including their default and current ports, use the --list-all-services option:
firewall-cmd --list-all-services
Listing Firewall Rules

Now that we have a solid understanding of zones and services, let's explore how to list firewall rules in firewalld. Listing rules is an essential task for auditing and managing your firewall configuration effectively.
To list all the active firewall rules, we can use the following command:




















firewall-cmd --list-all
This command will display a comprehensive list of all the active rules, including their zones, services, and the corresponding actions (allow or deny). To list only the rules for a specific zone, you can use the following syntax:
firewall-cmd --list-all --zone=ZONE_NAME
Listing Permanent and Runtime Rules
It's essential to understand that firewalld maintains two sets of rules: permanent and runtime. Permanent rules are stored in the configuration file (/etc/firewalld/zones/zone.file) and are applied during system startup. Runtime rules, on the other hand, are stored in the runtime directory (/run/firewalld/) and are applied immediately without requiring a system reboot.
To list permanent rules, use the following command:
firewall-cmd --permanent --list-all
To list runtime rules, use the following command:
firewall-cmd --runtime --list-all
Listing Rules for a Specific Service
To list rules for a specific service, you can use the following command:
firewall-cmd --list-all --service=SERVICE_NAME
Replace SERVICE_NAME with the name of the service you want to inspect. This command will display all the active rules related to the specified service.
Managing Firewall Rules
Listing firewall rules is just the beginning. firewalld offers a plethora of commands to manage your firewall rules effectively. You can add, remove, or modify rules, as well as enable or disable services and zones. To learn more about managing firewall rules, refer to the official firewalld documentation or consult our comprehensive guide on managing firewall rules with firewalld.
In the ever-evolving landscape of network security, staying informed and proactive is crucial. Listing and managing firewall rules with firewalld is an essential step in maintaining a robust and secure Linux environment. By mastering these techniques, you'll be well-equipped to protect your systems from potential threats and ensure seamless network connectivity.
As you continue your journey into Linux network security, consider exploring other aspects of firewalld and related tools. Stay curious, and always strive to expand your knowledge to better safeguard your systems and data. Happy learning!