How to Fix 'Connection Refused' Error
DodaTech
1 min read
In this tutorial, you'll learn about How to Fix 'Connection Refused' Error. We cover key concepts, practical examples, and best practices.
The Problem
You try to connect to a service and get:
ssh: connect to host example.com port 22: Connection refused
or
curl: (7) Failed to connect to localhost port 8080: Connection refused
Quick Fix
1. Check if the service is running
# For systemd services
sudo systemctl status nginx
# Check if anything is listening on the port
ss -tlnp | grep :8080
Expected output (service running):
LISTEN 0 511 0.0.0.0:8080 0.0.0.0:* users:(("nginx",pid=1234))
If the ss command shows nothing, the service isn't listening.
2. Start the service
sudo systemctl start nginx
sudo systemctl enable nginx # Start on boot
3. Check the firewall
The service may be running but blocked:
sudo ufw status | grep 8080
If blocked, allow the port:
sudo ufw allow 8080/tcp
4. Check if it's listening on the right interface
ss -tlnp | grep nginx
If it says 127.0.0.1:8080, it only accepts local connections. Change config to 0.0.0.0:8080 for external access.
Common Scenarios
| Error | Likely Cause | Fix |
|---|---|---|
| SSH connection refused | SSH daemon not running | sudo systemctl start ssh |
| MySQL connection refused | MySQL not started or wrong bind-address | Check my.cnf bind-address |
| Port 3000 refused | Dev server crashed | Restart with npm start |
| Remote connection refused | Firewall blocking port | Check with nc -zv host port |
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro