Sub topic 3
Checking What Is Currently Allowed
Assume you know basic Linux commands, sudo, TCP and UDP ports, systemctl, IPv4 addresses, and CIDR notation such as 192.0.2.0/24. This chapter focuses on inspecting firewalld before changing anything.
How firewalld and firewall-cmd fit together
firewalld is a firewall service that manages rules for network traffic. It applies rules through zones, which are named rule sets for different trust levels or network connections.
firewall-cmd is the command-line client for asking firewalld questions and changing its configuration. Inspection commands do not alter firewall behavior.
A service is a named group of ports, such as ssh or http. A port rule allows a specific port and protocol, such as TCP port 8080. A rich rule expresses a more detailed condition, such as allowing port 22 only from one network.
Find the active zone
Start by confirming that firewalld is running:
sudo firewall-cmd --stateThe expected result is:
runningFind the default zone:
sudo firewall-cmd --get-default-zoneThe usual result is public, but do not assume that your server uses it. The default zone is used when a command does not specify another zone. It is not necessarily the only active zone.
List all active zones:
sudo firewall-cmd --get-active-zonesA result might look like this:
public
interfaces: ens3A zone is active when an interface or source address is assigned to it. An interface is the network connection through which packets enter the server. A source assignment matches traffic by its originating address or network.
To find the zone assigned to one interface, run:
sudo firewall-cmd --get-zone-of-interface=ens3Replace ens3 with the interface name on your server.
Inspect the rules in a zone
Show the complete configuration for the default zone:
sudo firewall-cmd --list-allTypical output contains fields like these:
public (active)
target: default
interfaces: ens3
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
forward:
masquerade: no
rich rules:The services line lists predefined services that are allowed. The ports line lists direct port and protocol rules. For example, 8080/tcp allows TCP traffic to port 8080. An empty ports line does not mean that no traffic is allowed because services may still open ports.
Inspect individual parts when you need a focused result:
sudo firewall-cmd --list-services
sudo firewall-cmd --list-ports
sudo firewall-cmd --list-rich-rulesThese commands inspect the default zone. Specify a zone when necessary:
sudo firewall-cmd --zone=public --list-all
sudo firewall-cmd --zone=drop --list-allTo compare every zone, use:
sudo firewall-cmd --list-all-zonesThis output is longer, but it helps reveal a rule placed in an unexpected zone.
Understand the inspection path
The following diagram shows how to identify the rule set that controls incoming traffic.
The output tells you what firewalld intends to allow. It does not prove that an application is listening. A firewall rule for port 8080 is ineffective if no process has bound to that port.
Compare runtime and permanent state
Firewalld maintains a runtime configuration currently used by the firewall and a permanent configuration saved for future reloads or restarts. You can inspect the permanent configuration with the same commands and the --permanent option:
sudo firewall-cmd --permanent --list-allIf runtime and permanent output differ, a recent change may not have been saved, or a saved change may not yet have been loaded. Treat this difference as important evidence before troubleshooting connectivity.
Exercise
The active zone is public, but port 8080 appears only in the drop zone. Which zone should you inspect for a connection arriving through ens3?
Show answer
Inspect the zone assigned to ens3 with sudo firewall-cmd --get-zone-of-interface=ens3, then inspect that zone with sudo firewall-cmd --zone=ZONE --list-all. The drop-zone rule does not control ens3 unless ens3 or its source is assigned there.