Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … connect: connection refused

'Connection refused': nothing is listening there

The host answered, but nothing listens on that address and port.

Networking

What it means

Refused means a fast, explicit "no": the TCP SYN reached the host and got a reset. Nothing listens on that port, or the service listens only on 127.0.0.1 and you came from outside. A timeout instead means packets are dropped on the way (a firewall).

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. The service isn't running or crashed

Check:

systemctl status <svc>; ss -ltn

Fix: Start it and read its logs for why it stopped.

2. The service listens only on loopback (127.0.0.1)

Check:

ss -ltnp | grep <port>   # 127.0.0.1:<port> vs 0.0.0.0:<port>

Fix: Bind to 0.0.0.0 (or the right interface) in its configuration, and firewall what shouldn't be public.

3. Wrong port, or the wrong host/IP

Check:

nc -zv <host> <port>

Fix: Connect to where the service actually listens.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors