In the realm of Linux, managing network traffic is a critical aspect of system administration. One powerful tool for this purpose is firewalld, a dynamic firewall manager that uses iptables and nftables as its backend. When you need to list all rules configured in firewalld, you might find yourself wondering about the best way to do so. This article will guide you through the process, ensuring you have a comprehensive understanding of the topic.

Before we dive into listing rules, let's briefly discuss why understanding and managing these rules is essential. Firewalld rules help control incoming and outgoing network traffic based on predefined security rules. They ensure only authorized traffic is allowed, enhancing your system's security. Now, let's explore how to list all rules in firewalld.

Understanding Firewalld Zones and Services
Before listing rules, it's crucial to understand the concept of zones and services in firewalld. Zones are a way to group settings for a set of network interfaces. Services, on the other hand, are predefined firewall rules that allow or block specific ports and protocols. Understanding these concepts will help you interpret the listed rules.

Firewalld uses a zone for each network interface by default. You can create custom zones and services to fit your specific needs. Now, let's proceed to list all rules configured in firewalld.
Listing Rules Using the Firewall-Cmd Command

The firewall-cmd command-line tool is the primary interface for managing firewalld. To list all rules, you can use the following command:
firewall-cmd --list-all
This command will display a list of all configured rules, including permanent and active rules. The output will be grouped by zones and services, making it easier to understand the rule set.
Here's an example of what the output might look like:

public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client ssh
ports: 22/tcp 80/tcp 443/tcp
protocols:
forward-ports:
source-ports:
icmp-blocks:
rich rules:
Listing Rules Using the Firewall-Cmd Command with Specific Options
Sometimes, you might want to list rules with specific details. The firewall-cmd command offers several options to filter the output. Here are a few examples:
- List permanent rules: To list only the permanent rules, use the
--permanentoption: - List rules for a specific zone: To list rules for a specific zone, use the
--zoneoption followed by the zone name: - List rules in a specific format: You can use the
--xmlor--jsonoptions to list rules in XML or JSON format, respectively. This can be useful for scripting or further processing the output.

For example, to list permanent rules for the public zone in JSON format, you would use the following command:
firewall-cmd --permanent --zone=public --json
Managing and Modifying Firewalld Rules




















Now that you know how to list rules, let's briefly discuss how to manage and modify them. Firewalld provides several commands to add, remove, or modify rules. Here are a few examples:
- Add a service: To allow a specific service, use the
--add-serviceoption followed by the service name: - Remove a service: To block a specific service, use the
--remove-serviceoption followed by the service name: - Add a port: To allow a specific port, use the
--add-portoption followed by the port number and protocol (e.g.,80/tcp): - Remove a port: To block a specific port, use the
--remove-portoption followed by the port number and protocol:
For example, to add the ssh service to the public zone, you would use the following command:
firewall-cmd --permanent --zone=public --add-service=ssh
After adding or modifying rules, you can reload the firewall to apply the changes:
firewall-cmd --reload
In the dynamic world of Linux system administration, understanding and managing firewalld rules is an essential skill. By mastering the firewall-cmd command and its various options, you can effectively control network traffic and enhance your system's security. Keep exploring and expanding your knowledge to become a proficient Linux administrator.