GrepBoard/Manuals
605 manuals ·

Open a Port with firewalld on Rocky Linux 9

·Tested on firewalld docs and RHEL 9 docs (same family as Rocky 9) · 2026-10·Test scope ↓·7 steps

Add a port with firewall-cmd --permanent, apply it with --reload, and verify it. If Connection refused remains, use ss to check whether anything is listening.

firewall-cmd --add-port=34197/udp --permanent prints success, yet --list-ports shows an empty line. The command was fine. One step is missing: applying the change.

[1] Check that firewalld is running. If it is stopped, every command below fails.

console
# firewall-cmd --state

It prints the state and exits 0 when the daemon is up. systemctl status firewalld shows the service state as well.

[2] Find the zone the port belongs to. After installation the default zone is public (RHEL 9 docs). Without a zone option, commands apply to the default zone.

console
# firewall-cmd --get-default-zone# firewall-cmd --get-active-zones

[3] Add the port. The format is port/protocol, where the protocol is tcp, udp, sctp or dccp. A range is written 8000-8100/tcp (firewall-cmd(1)).

console
# firewall-cmd --permanent --add-port=8080/tcp

--permanent only writes the configuration files and leaves the running firewall alone. The man page says these changes are "not effective immediately, only after service restart/reload or system reboot". An empty --list-ports at this point is expected.

[4] Apply it. --reload turns the permanent configuration into the new runtime configuration. The RHEL 9 docs describe it as applying changes without interrupting network services.

console
# firewall-cmd --reload

[5] Check that the port is open.

console
# firewall-cmd --list-ports# firewall-cmd --query-port=8080/tcp

--list-ports prints the open ports as a space-separated list. --query-port answers with its exit code instead of output: 0 if the port has been added, 1 otherwise. Add --permanent to either command to check the saved configuration separately.

[6] For a port that has a service definition, open the service instead of the number. --get-services lists the names. To see what already listens on a port, read See which process is listening on a port.

console
# firewall-cmd --permanent --add-service=http# firewall-cmd --reload

[7] If Connection refused continues after the port is open, the firewall may not be the cause. The same message appears when no process listens on that port. In a forum thread, the user opened UDP 34197 and nc -vz -u localhost 34197 still failed as below. A reply pointed out that nothing was listening, so the result was expected.

output
Ncat: Connection refused.

On the server, check for a listening socket with ss. Use -u for UDP.

console
# ss -tlnp 'sport = :8080'

No output means nothing listens, so start the service first. If a line appears and Local Address is 127.0.0.1, the service accepts connections only from that server. Change the listen address in the service's own configuration; the firewall is not the problem.

#firewalld#firewall-cmd#ss