Sub topic 13
When the Port Is Still Unreachable
Assume you can use the Linux command line, sudo, systemctl, and firewall-cmd. You should also know that a listening service accepts connections on a TCP or UDP port, and that an IPv4 address can include a network prefix such as /24.
Opening a port in firewalld does not create a service. Firewalld only filters traffic. The application must already be running and listening on the expected address and port. A connection can also fail because the traffic matches a different zone, the rule exists only in the runtime configuration, or another firewall blocks it before it reaches the server.
Diagnose from the server outward
Start by checking whether a process is listening. Run this on the server:
sudo ss -tlnp | grep ':8080'For UDP, use:
sudo ss -ulnp | grep ':8080'No output means that no process is listening on that port. Check the application service and its logs:
sudo systemctl status myapp
sudo journalctl -u myapp --since "15 minutes ago"A process may listen only on 127.0.0.1, the loopback address. That accepts connections from the server itself but not from remote hosts. The ss output shows the bind address. An entry such as 127.0.0.1:8080 is local only. An entry such as 0.0.0.0:8080 listens on all IPv4 interfaces.
Next, check the zone and its rules:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --get-default-zone
sudo firewall-cmd --zone=public --list-all
sudo firewall-cmd --query-port=8080/tcpReplace public with the zone assigned to the server's network interface. A port allowed in public does not help if the interface is assigned to internal or another zone.
The command --query-port checks the runtime configuration. To inspect the permanent configuration, add --permanent:
sudo firewall-cmd --permanent --query-port=8080/tcpIf the permanent rule is present but the runtime rule is absent, reload firewalld:
sudo firewall-cmd --reloadIf the runtime rule is present but the permanent rule is absent, the rule will disappear after a reload or reboot. Save it only after confirming that it is the intended rule:
sudo firewall-cmd --runtime-to-permanentCompare the failure layers
Use this order so that each test removes one possible cause.
| Check | Command or action | What a failure suggests |
|---|---|---|
| Process listening | `ss -tlnp` or `ss -ulnp` | The application is stopped or bound incorrectly |
| Local connection | `nc -zv 127.0.0.1 8080` | The application is not accepting connections |
| Server address | `ip address` | You may be testing the wrong address |
| Firewalld rule | `firewall-cmd --list-all` | The port is not allowed in the active zone |
| Remote connection | `nc -zv server.example.com 8080` | A network or upstream firewall may block traffic |
A successful local test proves only that the application works on the server. Test the server's actual address too:
nc -zv 192.0.2.20 8080Then test from another host:
nc -zv server.example.com 8080If the service works locally but not remotely, inspect the bind address, active zone, routing, and any cloud security group or network firewall. If the hostname resolves to an unexpected address, check DNS and test the correct IPv4 or IPv6 address directly.
Use denied-packet logging briefly
When the service is listening and the zone looks correct, temporarily log packets denied by firewalld:
sudo firewall-cmd --set-log-denied=all
sudo journalctl -k --since "10 minutes ago" | grep -i reject
sudo firewall-cmd --set-log-denied=offLogging helps distinguish a firewalld denial from a packet that never reaches the server. Turn it off after testing because busy servers can produce many kernel log entries.
Exercise
A service listens on 0.0.0.0:8080, a local netcat test succeeds, and firewalld allows 8080/tcp in the active zone. A remote test times out. Name two places to investigate next.
Show answer
Check an upstream firewall or cloud security group, and check routing, DNS, or the remote host's network path.