Sub topic 4
Runtime and Permanent Configuration
This chapter assumes basic Linux command-line use, sudo, TCP and UDP ports, systemctl, and IPv4 CIDR notation. You should also know which firewalld zone applies to the server interface before changing rules.
Two configurations with different jobs
firewalld keeps two versions of its configuration:
- The runtime configuration is loaded in memory and controls traffic now. It changes immediately but disappears when firewalld reloads or the server restarts.
- The permanent configuration is stored on disk. It survives reloads and restarts, but it does not affect traffic until firewalld loads it.
The firewall-cmd command changes the runtime configuration by default. Add --permanent when you want to change the saved configuration.
| Command form | Changes now | Survives reload or reboot |
|---|---|---|
| `firewall-cmd --add-service=http` | Yes | No |
| `firewall-cmd --permanent --add-service=http` | No | Yes, after reload |
| `firewall-cmd --runtime-to-permanent` | Saves current runtime rules | Yes |
A reload replaces the active runtime rules with the saved permanent rules. This makes the two configurations match, unless a temporary rule was intentionally omitted from the permanent configuration.
Test a change at runtime first
Runtime changes are useful for testing. For example, this command opens HTTP only in memory:
sudo firewall-cmd --add-service=http --timeout=5m
sudo firewall-cmd --list-servicesThe --timeout=5m option automatically removes the runtime rule after five minutes. This safety net is useful when you are working remotely or are not yet sure that the rule is correct.
The change is not permanent. A reload, reboot, or timeout removes it. If testing succeeds, save the current runtime configuration:
sudo firewall-cmd --runtime-to-permanentThis copies the active runtime settings into the permanent configuration. Use this command carefully because it saves the complete runtime state, including changes you may not have intended to keep.
Make a permanent change and load it
You can instead write directly to the permanent configuration. The following command allows TCP port 8080 in the default zone:
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --query-port=8080/tcpThe first command changes the saved configuration. The reload then loads that configuration into runtime. The query should print yes.
The same pattern works for predefined services:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
sudo firewall-cmd --query-service=httpCheck the correct zone when the server has multiple interfaces or source-based rules:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --zone=public --list-allA rule added to public does not automatically apply to an interface assigned to another zone.
Avoid losing SSH access
Do not reload or replace firewall rules blindly during a remote SSH session. First identify the active zone and confirm that SSH is allowed there. Keep the current SSH session open while testing a new configuration. Open a second session to verify that a new connection works before ending the first one.
For a cautious workflow:
- Inspect the active zone and its rules.
- Add the rule at runtime, preferably with a timeout.
- Test the service from the server and from a remote host.
- Save the working rule as permanent.
- Reload and test again.
If a permanent change causes trouble, remove it from the permanent configuration and reload:
sudo firewall-cmd --permanent --remove-port=8080/tcp
sudo firewall-cmd --reloadExercise
You run sudo firewall-cmd --permanent --add-port=8080/tcp, but --query-port=8080/tcp still prints no. What step is missing?
Show answer
Reload firewalld with sudo firewall-cmd --reload so the permanent configuration is loaded into the runtime configuration.