Rocky Linux 10 Tutorial / firewalld zones, services and persistent rules

On Rocky Linux 10, firewalld applies a zone to network interfaces or traffic sources, then allows services or ports within that zone. Runtime rules and permanent rules loaded on reload or boot are separate, so inspect both rule sets and test new connections.

First, check the current zones and SSH allowance.

A firewall does not start a server application. Permission to pass traffic and an application listening on the intended address and port are separate requirements. The source lab compared runtime and permanent rules and new Hypertext Transfer Protocol (HTTP) requests in a dedicated Rocky Linux 10.2 VM with firewalld 2.4.3-4.el10_2 and Python 3.12.15.

rpm -q firewalld
sudo firewall-cmd --state
sudo firewall-cmd --get-default-zone
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --get-zone-of-interface=enp0s3
sudo firewall-cmd --zone=public --list-all
sudo firewall-cmd --permanent --zone=public --list-all
ss -lnt

Replace the device name and zone with your actual values. In the source VM, interface enp0s3 belonged to zone public, and the original service list included cockpit dhcpv6-client ssh. This reflects the observed existing configuration and does not mean the same service must be allowed on all servers. During the exercise, the existing services were preserved and only 8080/tcp was added or removed.

To maintain SSH (Secure Shell) remote access, check both the current allowed rules and the persistent rules. If SSH uses a different port or source restriction rules, simply looking up the service name below is not sufficient, so you need to compare it with the actual configuration.

sudo firewall-cmd --zone=public --query-service=ssh
sudo firewall-cmd --permanent --zone=public --query-service=ssh

If the result of --query-* is no, there may be an exit status of 1. Distinguish between there being no query target and an execution error of the command itself. Before remote operations, secure the recovery console prepared in the network change exercise and the original settings .

Before changing the firewall, separately back up the configuration files and runtime/persistent zones. The following example stops if the backup path already exists and does not overwrite the existing backup. On this VM, the original files and zone outputs were also stored in the same location.

sudo bash <<'BASH'
set -eu
test ! -e /root/lf-course-15-before
mkdir -m 700 /root/lf-course-15-before
cp -a /etc/firewalld /root/lf-course-15-before/
LC_ALL=C firewall-cmd --list-all-zones > /root/lf-course-15-before/runtime-zones.txt
LC_ALL=C firewall-cmd --permanent --list-all-zones > /root/lf-course-15-before/permanent-zones.txt
BASH

Differentiate the roles of zones, services, and ports

A zone is a set of policies applied to specific connections or sources. As described in the firewalld documentation on connections, interfaces and sources, NetworkManager passes the zone of a connection to firewalld, and if none is specified, the default zone may be used. In this VM, the zone value of the connection profile was empty, and the actual device was placed in the default public zone.

This article does not change the zone or the membership of an interface. To prevent the assumption that opening a port in another zone also applies to the current device, all modification commands explicitly specify --zone=public.

sudo firewall-cmd --info-service=http
sudo firewall-cmd --zone=public --list-services
sudo firewall-cmd --zone=public --list-ports

The firewalld service definition http in this environment was 80/tcp. If a web application listens on 8080, allowing the http name alone does not automatically open port 8080. You need to verify the actual port and protocol and designate it as in 8080/tcp. TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are different transport protocols, so even if the number is the same, they require separate allowance conditions. The query and allow options can be checked in by referring to the official firewall-cmd command .

When a regular web server is listening on the standard HTTP port, you can use the service name like --add-service=http. This is not a command to install a web server package or start a service. In this practice, we only looked up this definition and did not open port 80 additionally.

Prepare the paths from the test server and from the outside.

Prepare a simple web response in a new directory that has no materials to be exposed, only on the dedicated practice VM. If Python is not available, you should first review the installation plan and prepare it. The Python official http.server documentation also does not recommend using this server for production service.

Below is a simple example running as a normal user. If the same folder already exists, do not overwrite the existing materials and stop. Only continue execution in the same terminal if the folder was created successfully.

python3 --version
mkdir "$HOME/lf-firewall15"
printf 'firewall lesson15 test\n' > "$HOME/lf-firewall15/index.html"
python3 -m http.server 8080 --bind 0.0.0.0 \
  --directory "$HOME/lf-firewall15"

With the server running in the first window, check the receiving status and internal response from the second VM terminal. 0.0.0.0 means that it listens on all IPv4 interfaces, so do not perform this practice on a public server or in a folder that contains materials.

ss -lnt 'sport = :8080'
curl --silent --show-error --max-time 5 http://127.0.0.1:8080/

The expected content is firewall lesson15 test. The success of this internal request alone does not verify firewall traversal from an external device. You need to open a new connection from a separate client to compare.

In the source test, requests went from the Windows host to the VM through VirtualBox's local forwarding. The forwarding is host 127.0.0.1:18080 → guest 8080, and the existing SSH forwarding was maintained. If the same method is needed, you can check the actual VM name and port conflicts in the host PowerShell and prepare a separate rule as follows.

& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "Rocky10-Lab" natpf1 "lf-course-http15,tcp,127.0.0.1,18080,,8080"

If the same forwarding name or host port is already in use, do not add duplicates. Change the virtual machine name to your actual name. For a normal LAN practice, access using the server's actual address and port 8080, and in a cloud environment, higher-level firewalls and security groups are additional conditions.

An example of sending a new HTTP request from a Windows host is as follows. In actual comparison, repeated new requests were made to the same URL, and before allowing, the connection timed out, but the VM internal server responded normally.

curl.exe --connect-timeout 3 --max-time 5 http://127.0.0.1:18080/

Allow it with an runtime rule and check the effect of reload.

Before changing, check that there are no practice ports on both runtime and permanent. If the port is already in use, do not use it for the add/remove practice below. Runtime rules are the settings currently applied and are separate from permanent storage.

sudo firewall-cmd --zone=public --query-port=8080/tcp
sudo firewall-cmd --permanent --zone=public --query-port=8080/tcp
sudo firewall-cmd --zone=public --add-port=8080/tcp
sudo firewall-cmd --zone=public --query-port=8080/tcp
sudo firewall-cmd --permanent --zone=public --query-port=8080/tcp

After adding this runtime rule, runtime query was yes, permanent query was no, and the host received a 200 and the practice body for a new HTTP request. The server program and request path remained the same, only the firewall allowance was changed to observe the difference.

Check versions and timed rules before reloading. The source VM encountered an internal error and failed new SSH connections when reloading while timed port rules remained. The normal reload comparison below was performed separately, after console recovery, with rules that had no timeout. Do not combine --timeout rules and reload in this affected version.

sudo firewall-cmd --check-config
sudo firewall-cmd --reload
sudo firewall-cmd --zone=public --query-port=8080/tcp
sudo firewall-cmd --permanent --zone=public --query-port=8080/tcp

The actual reload under the condition without timeout objects ended successfully, and both port queries became no. The server continued running, but new requests from the host were blocked again. The official runtime and permanent configuration documentation explains that reload brings permanent settings to runtime settings, so normal rules added only at runtime were not retained.

Reloading on the operational server can also affect other changes that are runtime-only. First, review the full configuration and permanent SSH allowance, and do not assume that new connections have been verified just because existing connections are maintained. It should also be distinguished from --complete-reload, which initializes the state more extensively.

Compare saving the permanent configuration with reloading and rebooting.

Now, add the same practice ports only to the permanent configuration. Just before the next step, both runtime and permanent configurations should have no ports.

sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
sudo firewall-cmd --permanent --zone=public --query-port=8080/tcp
sudo firewall-cmd --zone=public --query-port=8080/tcp
sudo firewall-cmd --check-config

The actual result was permanent yes, runtime no, and host HTTP requests continued to be blocked. The fact that it was saved does not mean it is applied to current communications. Review the permanent configuration and SSH access, and after checking the conditions related to the time limit rules in the previous section, reload.

sudo firewall-cmd --reload
sudo firewall-cmd --zone=public --query-port=8080/tcp
sudo firewall-cmd --permanent --zone=public --query-port=8080/tcp
sudo firewall-cmd --zone=public --query-service=ssh

This reload was completed successfully, both ports showed yes, and the new HTTP connection returned 200. The method of specifying just one verified rule to the permanent configuration and the --runtime-to-permanent, which copies the entire runtime configuration to permanent, differ in scope. If there is no intention to save other temporary changes currently running, do not habitually use the full copy command.

Practice step Check runtime ports Check permanent ports New HTTP Connection
Original State no no Blocked
Add Only Runtime Rules yes no 200
After Normal Reload no no Blocked
Add Only Permanent Rules no yes Blocked
After Reloading Permanent Settings yes yes 200
After Reboot / Restarting the Practice Server yes yes 200

Even after properly rebooting the dedicated VM, the port allowance and new SSH connections were maintained. However, the test server was run as a temporary service, so it did not receive connections after reboot. The firewall lookup shows yes, but ss confirmed that 8080 was not present, and after restarting the test server, HTTP 200 was received. The simple foreground execution example above also needs to be restarted after a reboot.

In real validation that requires rebooting, set the maintenance time and check that there are no unsaved tasks. The reboot results in this article should not be interpreted to mean that all production servers can be rebooted immediately.

Distinguish reload errors of the time limit rule from normal completion.

At the beginning of the source exercise, reloading while the ports allowed by --timeout=60 were still open produced the following error and exit status 254 occurred. Afterwards, new SSH connections also failed due to banner exchange timeout.

Error: dictionary changed size during iteration

The guest log recorded a RuntimeError while cleaning the fw_policy.py timeout list. Upstream firewalld issue 1597 reports the same failure and blocking of new connections with timed port rules. Related fix PR 1632 was merged upstream, but that alone does not establish that a distribution package includes the fix.

On this VM, even if the firewalld service and --state showed as running, new connections actually failed. Therefore, a running status line was not used as proof of policy correctness. Logged into the recovery console, compared permanent files with the pre-exercise backup, performed offline validation, and then restarted firewalld for the guest.

sudo journalctl -u firewalld -n 70 --no-pager
sudo firewall-offline-cmd --check-config

The recovery action used in the console, once the review confirming that the permanent settings are correct and that existing management access is allowed, is sudo systemctl restart firewalld. Restarting is not a measure that preserves the current running-only configuration, so it is not used as a blanket solution for all firewall errors. The source lab confirmed that new SSH access and the existing zones were restored to the original settings. The source recovery did not disable firewalld or modify the installed Python source files.

Reloading and reloading permanent settings performed again with rules without a time limit were successful. This result shows the differences in the observed versions and conditions, and it does not mean that all reloads on other versions produce the same error. You should check your exact package version and whether your distribution provides any patches.

Remove only the rules and test data added for the exercise

Remove them on both sides only if it was confirmed before the exercise that 8080 was not in use and that it is a rule added this time. Do not delete existing rules used by other services.

sudo firewall-cmd --zone=public --remove-port=8080/tcp
sudo firewall-cmd --permanent --zone=public --remove-port=8080/tcp
sudo firewall-cmd --zone=public --query-port=8080/tcp
sudo firewall-cmd --permanent --zone=public --query-port=8080/tcp
sudo firewall-cmd --zone=public --query-service=ssh
sudo firewall-cmd --permanent --zone=public --query-service=ssh

Even under conditions where the server continues to run, check whether new requests from the host are blocked again, then stop the test server. If it was a foreground execution example from earlier, finish in that window with Ctrl+C, and check and organize only the contents and paths of the files you created.

cat "$HOME/lf-firewall15/index.html"
rm -- "$HOME/lf-firewall15/index.html"
rmdir -- "$HOME/lf-firewall15"

If other materials have appeared in this example folder, do not proceed with deletion. If you have newly created the VirtualBox forwarding this time, remove only the corresponding name on the host.

& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "Rocky10-Lab" natpf1 delete "lf-course-http15"

After actual cleanup, port 8080, the practice server, practice files, and HTTP forwarding were removed, while the existing SSH forwarding was retained. The source lab compared the full runtime/permanent zone output and the existing firewalld files to confirm they were the same as before the practice. SELinux remained in Enforcing mode.