Sub topic 1
How firewalld and firewall-cmd fit together
This chapter assumes basic Linux command-line use, sudo, TCP and UDP ports, systemctl, IPv4 addresses, and CIDR notation. You will use a Linux server running firewalld, preferably in a test environment or through a console session that remains available if SSH access changes.
Prerequisites
You should know how to:
- Open a shell on the server.
- Run administrative commands with
sudo. - Start and inspect services with
systemctl. - Distinguish a listening port from a firewall rule.
- Read addresses such as
192.0.2.10and networks such as192.0.2.0/24.
The two parts of the interface
firewalld is a firewall service that manages packet-filtering rules on Linux. It runs as a background process and maintains the firewall configuration through the system firewall framework.
firewall-cmd is the command-line client for firewalld. It sends requests to the running firewalld service. The command does not directly edit kernel firewall rules one command at a time. Instead, firewalld interprets your request and applies the resulting configuration.
This separation gives you a consistent interface for inspecting and changing firewall policy:
| Component | Role |
|---|---|
| firewalld | Background service that manages firewall policy |
| firewall-cmd | Command-line client used by an administrator |
| Zones | Rule sets that determine which traffic is allowed |
| Services and ports | Definitions of traffic that a zone may allow |
The service must be running before most firewall-cmd operations can work. Enable it at boot and start it now:
sudo systemctl enable --now firewalld
sudo firewall-cmd --stateA working service prints:
runningIf the command reports that firewalld is not running, inspect the service before changing rules:
sudo systemctl status firewalld
sudo journalctl -u firewalld -bThe working model
Firewalld evaluates incoming traffic against a zone. A zone is a named collection of rules that describes how much trust to give traffic arriving through a network interface or from a source address.
A rule can allow a predefined service, such as HTTP, or a specific port and protocol, such as TCP port 8080. A port being open in firewalld does not start an application. The application must separately listen on that port.
The basic path is:
network packet
|
v
interface or source matches a zone
|
v
zone rules evaluate service, port, and source
|
v
traffic is accepted, rejected, or droppedUse firewall-cmd to see the zone that firewalld uses by default:
sudo firewall-cmd --get-default-zoneThe default zone is used when an interface or source has no more specific assignment. It is often named public, but do not assume that name. Distribution defaults and administrator choices can differ.
Inspect before changing
Before opening a service or port, inspect the active zones and their rules:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --list-allThe active-zone output shows which interfaces or source networks are associated with zones. The --list-all command normally displays the rules for the default zone. To inspect a specific zone, provide its name:
sudo firewall-cmd --zone=public --list-allLook for the interfaces, sources, services, and ports fields. These fields tell you where the rule applies and which traffic the zone currently allows.
A safe first inspection
Run these commands as a single read-only inspection:
sudo firewall-cmd --state
sudo firewall-cmd --get-default-zone
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --list-allRecord the default zone and the interface attached to it before making changes. Later commands must target the zone that actually handles the server's traffic. Opening a port in an unused zone will not make the application reachable.
Exercise
What is the difference between firewalld and firewall-cmd?
Show answer
Firewalld is the background service that manages firewall policy. firewall-cmd is the command-line client that asks firewalld to inspect or change that policy.