What does "Connection refused" mean and how do you troubleshoot it?
Quick Answer
The host was reachable but nothing is listening on that port (or a firewall actively rejected it). Check the service is running and bound to the expected port/interface, and that no firewall blocks it.
Detailed Answer
Connection refused = the TCP SYN reached the host and got an RST — the service is down, listening on a different port/interface (e.g., 127.0.0.1 only), or a firewall rejects it. Diagnose: ss -tulnp (is it listening?), systemctl status <svc>, firewall-cmd --list-ports / iptables, and nc -zv <host> <port> to test connectivity.
Code Example
ss -tulnp | grep <port> systemctl status <svc> nc -zv <host> <port>
Interview Tip
Contrast it with connection timed out (no response = firewall drop/network) — refused means something actively said no.