In the realm of network security, firewalls play a pivotal role in protecting your Ubuntu system from unauthorized access and malicious activities. One of the most powerful firewall management tools for Ubuntu is firewalld, which offers a dynamic and flexible way to manage your firewall rules. If you're wondering how to list rules in firewalld on your Ubuntu system, you've come to the right place.

Before we dive into listing rules, let's ensure you have firewalld installed and running on your Ubuntu system. You can install it using the following command:

Installing and Enabling firewalld
To install firewalld, open your terminal and type:

sudo apt update
sudo apt install firewalld

Once installed, enable and start the firewalld service with:
sudo systemctl enable firewalld
sudo systemctl start firewalld

Checking the Status of firewalld
Before listing rules, ensure firewalld is active and running:
sudo systemctl status firewalld

If the service is active (running), you're ready to list your rules.
Listing Rules in firewalld




















To list all the rules in firewalld, use the following command:
sudo firewall-cmd --list-all
This command will display a list of all active rules, including zones, interfaces, sources, services, and ports.
Understanding firewalld Zones
firewalld uses zones to group settings for different levels of trust. Understanding zones is crucial for managing your rules effectively.
To list all available zones, use the following command:
sudo firewall-cmd --get-zones
Default Zone
The default zone is the one that applies when no other zone matches. To find out the default zone, use:
sudo firewall-cmd --get-default-zone
Current Zone
To check the current zone for an interface, use:
sudo firewall-cmd --get-zone-of-interface=eth0
Replace 'eth0' with your interface name.
Managing Rules in firewalld
Now that you know how to list rules and understand zones, let's explore how to manage rules in firewalld.
Adding a Rule
To add a rule allowing incoming traffic on a specific port (e.g., 80 for HTTP), use:
sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
The '--permanent' flag ensures the rule persists after a reboot.
Removing a Rule
To remove a rule, use:
sudo firewall-cmd --permanent --zone=public --remove-port=80/tcp
After adding or removing rules, reload the firewall to apply the changes:
sudo firewall-cmd --reload
Regularly reviewing and managing your firewall rules is essential for maintaining a secure Ubuntu system. With firewalld, listing and managing rules is a straightforward process that empowers you to control your system's network security effectively.