AlmaLinux 9: open a single port
When to use it
Section titled “When to use it”Your service listens on 8080 but nothing can reach it — usually firewalld has not allowed it. firewalld is not one flat rule table but rules grouped by zone: find the zone your interface belongs to, then change that zone’s ports or services.
Test scope
Section titled “Test scope”In an almalinux:9 container (AlmaLinux 9.8, firewalld 1.3.4-20.el9_8) the static configuration was read with firewall-offline-cmd: --get-zones, --get-default-zone, --zone=public --list-services, --add-port=8080/tcp, --list-ports, --list-all. Log: plans/content-expansion/evidence/logs/alma-firewalld-zones.log.
The container has no systemd and firewall-cmd needs the running daemon, so the runtime firewall-cmd commands below were not executed here (E3); only the static-config output is tested (E1).
Look at the zone first
Section titled “Look at the zone first”firewall-offline-cmd --get-zonesfirewall-offline-cmd --get-default-zonefirewall-offline-cmd --zone=public --list-servicesblock dmz drop external home internal public trusted workpubliccockpit dhcpv6-client sshWith this firewalld installation the public zone allows cockpit, dhcpv6-client and ssh (static configuration; check --list-all on other hosts).
The output above is real
firewall-offline-cmdoutput (not runtimefirewall-cmdoutput).
Open a port
Section titled “Open a port”sudo firewall-cmd --permanent --zone=public --add-port=8080/tcpsudo firewall-cmd --reloadsudo firewall-cmd --zone=public --list-portsWith only --permanent and no --reload the rule applies on the next reload or reboot; without --permanent it vanishes on restart — you need both.
Verify
Section titled “Verify”firewall-cmd --zone=public --list-allpublic target: default icmp-block-inversion: no interfaces: sources: services: cockpit dhcpv6-client ssh ports: 8080/tcpOnly when ports: lists 8080/tcp is the port open.
Common traps
Section titled “Common traps”--add-port=8080without a protocol: it is treated as a single protocol; write8080/udpexplicitly when you need UDP;- Wrong zone: the interface is in
publicbut the command targets--zone=internal; checkfirewall-cmd --get-active-zonesfirst; - Service bound to 127.0.0.1: opening the port does not help; confirm with
ss -lntp | grep 8080.
Practice: open 8443/tcp and keep it after a restart
Section titled “Practice: open 8443/tcp and keep it after a restart”sudo firewall-cmd --permanent --zone=public --add-port=8443/tcpsudo firewall-cmd --reloadsudo systemctl restart firewalldfirewall-cmd --zone=public --list-portsChecks:
firewall-cmd --zone=public --list-ports→ includes8443/tcpfirewall-cmd --permanent --zone=public --list-ports→ also includes it- After
systemctl restart firewalld→ still there
常见问题
Why does `--add-port` disappear after a restart?
Because `--permanent` was missing: without it you only change the runtime state, which is lost on restart. With `--permanent` you also need `--reload` for it to take effect now. Use both.
The command succeeded but the port is still unreachable?
Check which zone the interface is in (`firewall-cmd --get-active-zones`) and what address the service listens on (`ss -lntp`). A service bound to 127.0.0.1 is unreachable no matter what the firewall allows.
How do I open a UDP port?
State the protocol explicitly: `--add-port=8080/udp`. Writing only `8080` treats it as a single protocol and often opens just half of what you need.
Next steps
Section titled “Next steps”- Package management: dnf transaction rollback
- Package management: dnf transaction rollback
- Security baseline: Hardening