A fast failure carries more information than a slow one. Read it before you touch the network.
What it means
The client sent a TCP SYN and got an immediate rejection back. Usually that's a TCP reset (RST) from a host that is up but has no socket listening on that IP and port. Clients show it as ECONNREFUSED, Connection refused, or curl: (7) Failed to connect.
Compare it with the other connect failures:
| Symptom | Usual meaning |
|---|---|
| Refused, instantly | host reached, nothing listening, or a firewall REJECT |
| Hangs, then times out | packets dropped: security group, NACL, firewall DROP, host down |
No route to host | routing problem, or a REJECT with icmp-host-prohibited |
Could not resolve host | DNS, not TCP |
Usual causes
- The process is down, crashed, or still starting.
- Wrong port: config says 8080, the app listens on 3000.
- The app is bound to
127.0.0.1and you're connecting to the machine's real IP. - Inside a container,
localhostis the container itself, not the host or another container. localhostresolves to::1while the server listens only on IPv4.- A Kubernetes Service with no ready endpoints, or a
targetPortthat doesn't match the container port. - A host firewall rule with
REJECT.
Debug commands
On the target host, see what is actually listening:
ss -ltnp | grep 8080 # LISTEN on 127.0.0.1 or 0.0.0.0 / [::]? systemctl status app journalctl -u app -n 50
From the client, test the exact host and port the app uses:
nc -vz 10.0.0.7 8080 curl -v http://10.0.0.7:8080/health getent ahosts localhost # does it return ::1 first?
In Kubernetes:
kubectl get endpointslices -l kubernetes.io/service-name=api
kubectl get svc api -o jsonpath='{.spec.ports}'
kubectl get pod -l app=api -o wideIf ss shows the listener but clients are still refused, check the host firewall:
sudo iptables -S | grep -i reject sudo nft list ruleset | grep -i reject
Fixes
- Start or fix the process, and make it fail loudly when it can't bind.
- Bind to
0.0.0.0(or::) if remote clients must connect. - Use service names between containers, not
localhost. - Make the Service selector and
targetPortmatch the pods. - Use
127.0.0.1instead oflocalhostwhen the server is IPv4-only.
Common wrong fix
Opening the port in the security group or cloud firewall. A security group that blocks traffic drops it, and the client times out. If you get an instant refusal, the packet already reached the host, so the cloud firewall is not the problem. Run ss -ltnp on the target before you touch the network rules.