Sub topic 13
When the Port Is Still Unreachable
You opened a port with firewall-cmd, the command reported success, and the client still can't connect. This chapter gives a fixed order of checks that finds the cause. The firewall is only one of several layers that can stop a connection, so you check each layer in turn.
This chapter assumes you can read ss output and know the zone, runtime, and permanent concepts from earlier chapters. It also assumes you have sudo access on the server and a second host to test from.
Read the symptom first
The way a connection fails tells you where to look. Run the test from a remote host with nc -zv server.example.com 8080 and compare the result with this table.
| What the client sees | Likely cause | Where to look |
|---|---|---|
| `Connection refused` immediately | The firewall let the packet through, but no process is listening on that address and port | The service itself, its bind address |
| `No route to host` or `Destination unreachable` immediately | A firewall rejected the packet and sent back an ICMP error (the zone default, or a reject rule) | Zone, rules, runtime versus permanent |
| Hangs until timeout | A drop rule, a rule on another device, or a network filter upstream silently discarded the packet | Drop zone, sources, cloud firewall, routing |
| Connects but the application fails | The network path is fine | Application logs, SELinux |
These are heuristics. A reject that firewalld sends in the public zone usually appears as No route to host, but a router in between can change what the client sees.
Follow the checks in order
Work from the server outward. Each step removes one layer from suspicion.
Step 1: Is anything listening?
A firewall rule cannot make a port work. It only lets traffic reach whatever is bound to it. Check on the server first:
sudo ss -tlnp | grep ':8080'Read the local address column:
- No output means nothing is listening. Start the service or correct its configured port.
127.0.0.1:8080or[::1]:8080means the process accepts only local connections. No firewall rule can fix this. Change the application's bind address, for example to0.0.0.0or the server's own IP.0.0.0.0:8080or*:8080means the process accepts connections on every IPv4 address. This is what you want for remote access.
Also confirm the protocol. A UDP service needs ss -ulnp, and a rule for 8080/tcp does nothing for it.
Step 2: Which zone applies?
You may have opened the port in a zone that never sees your traffic. Ask firewalld which zones are active, then which zone owns the interface and the client's address:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --get-zone-of-interface=eth0
sudo firewall-cmd --get-default-zone
sudo firewall-cmd --zone=public --list-allReplace eth0 and public with your interface and zone. A common cause is a server with an interface assigned to internal or dmz while you edited the default zone, public. Commands without --zone= change the default zone, not the zone that matches your traffic.
The matching order matters. Firewalld first checks whether the packet's source address belongs to a zone. Only if no source matches does it use the zone of the interface the packet arrived on. If the client's address is inside a network you assigned to a zone, that zone's rules apply, and the interface zone is ignored.
To find out whether a client address has its own zone, query it:
sudo firewall-cmd --get-zone-of-source=203.0.113.10
sudo firewall-cmd --query-source=203.0.113.0/24 --zone=dropThe first command prints the zone that has a source entry matching the address, or an error if none does. The second prints yes or no.
Step 3: Is the rule really active?
Rules added with --permanent do not take effect until you reload. Rules added without it vanish at the next reload or reboot. Compare both views for the zone:
sudo firewall-cmd --zone=public --list-ports
sudo firewall-cmd --permanent --zone=public --list-ports
sudo firewall-cmd --zone=public --list-services
sudo firewall-cmd --permanent --zone=public --list-servicesInterpret the pair of outputs:
- In the permanent list but not the runtime list: you forgot
--reload. - In the runtime list but not the permanent list: it works now and will break at the next reload or reboot. Run
sudo firewall-cmd --runtime-to-permanentonce you are satisfied. - In neither list: the rule was never added, or you added it to a different zone.
To test one specific port without parsing lists, use the query commands, which print yes or no:
sudo firewall-cmd --query-port=8080/tcp
sudo firewall-cmd --query-service=httpIf you changed a service definition, such as the custom myapp service, reload before you test. A permanent edit to the service file does not change the running firewall until you do.
Step 4: Does a more specific rule win?
An allow rule can be present and still lose. Check three places.
- A source assigned to a restrictive zone. If the client's network was added to
droporblock, firewalld uses that zone for the client and ignores the allow rule inpublic. Runsudo firewall-cmd --zone=drop --list-sourcesand check the client's address against the list. - A rich rule that rejects or drops. Rich rules with
rejectordropare evaluated before the ordinary service and port allows in the same zone. List them:
``bash sudo firewall-cmd --zone=public --list-rich-rules ``
- A broad rule covering your address. A reject for
203.0.113.0/24also covers a test host at203.0.113.77. This catches people who test from a machine in the same network they blocked.
When you find the blocking rule, remove it with the same text you used to add it, using --remove-rich-rule or --remove-source, and reload.
Step 5: Ask the firewall what it denies
If the earlier steps show nothing wrong, make firewalld log the packets it rejects or drops. This also tells you whether the firewall is involved at all.
sudo firewall-cmd --set-log-denied=all
nc -zv server.example.com 8080
sudo journalctl -k --since "10 minutes ago" | grep -i reject
sudo firewall-cmd --set-log-denied=offRun the nc line from the remote host, not the server. The other lines run on the server. A log entry names the chain that denied the packet. A name such as filter_IN_public_REJECT shows that the public zone rejected it, and the zone name in the chain tells you which zone matched. The entry also shows the source address, destination port, and interface.
Read the result like this:
- A log entry appears. Firewalld is the cause. Note the zone name in the chain and go back to steps 2 to 4 with that zone.
- No entry appears, but the connection fails. The packet probably never reaches firewalld. Look at the network path.
Keep the log setting on only for a short test. On a server exposed to the internet, all produces a large volume of scan noise. Turn it off afterward, as the last command above does.
Problems outside firewalld
If firewalld logs nothing and the process listens on the right address, look beyond the host firewall.
- SELinux. On Red Hat family systems, SELinux limits which ports a service may bind to. A web server moved to port 8080 may fail to start or fail to bind, which shows up in step 1 as nothing listening. Check
sudo ausearch -m avc -ts recentfor denials. Allowing a port is done withsemanage port, not with firewalld. - Cloud security groups and network ACLs. Providers such as AWS and Azure filter traffic before it reaches the instance. The port must be open in both the provider's rules and firewalld. These drops produce a timeout and leave no trace in the server's logs.
- A corporate or home router. The same applies to a network firewall between you and the server. Test from a host on the same subnet. If that works and the remote host fails, the cause is on the path.
- Another packet filter. Container engines such as Docker add their own rules and can publish a port in a way that bypasses the zone rules you see in
firewall-cmd. If a container port behaves differently from what--list-allsays, inspect the container engine's configuration, and consultsudo nft list rulesetfor the real rules in effect. - The wrong address. Confirm that the DNS name resolves to the server you are checking. A stale record points the client at a different machine.
A reusable checklist
Run these four commands on the server when a port is unreachable. They answer the first four questions in a minute.
sudo ss -tlnp | grep ':8080'
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --list-all
sudo firewall-cmd --query-port=8080/tcpIf the process listens on the right address, the active zone is the one you edited, and the query prints yes, the cause is almost certainly a source or rich rule, a logging-visible deny, or something outside the host.
Exercise
A web application listens on 127.0.0.1:8080. You ran sudo firewall-cmd --permanent --add-port=8080/tcp followed by sudo firewall-cmd --reload, and --query-port=8080/tcp prints yes. A remote nc -zv server.example.com 8080 still reports Connection refused. What is wrong, and what do you change?
Show answer
The firewall is not the cause. ss -tlnp shows the process bound only to the loopback address, so it accepts only local connections, and the server answers a remote connection attempt with a refusal because nothing listens on the server's external address. Change the application's bind address to 0.0.0.0 or the server's IP, restart it, and confirm with ss -tlnp that the local address changed. The firewall rule you added is correct and needs no change.
Exercise
A client at 203.0.113.77 times out when connecting to port 22, but --query-service=ssh prints yes for the public zone. List two firewalld checks that could explain this, with one command for each.
Show answer
First, the client's network may be a source of the drop zone: run sudo firewall-cmd --zone=drop --list-sources or sudo firewall-cmd --get-zone-of-source=203.0.113.77. Second, a rich rule may drop traffic from a range that includes the client: run sudo firewall-cmd --zone=public --list-rich-rules. Either one overrides the SSH allow in public, and a drop gives a timeout instead of an immediate error.