Fix: Connection refused and Connection timed out, what each one means
Refused means the host answered and nothing is listening there. Timed out means no answer at all, usually a firewall or wrong address. Each one points to a different fix.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
These two errors look similar but say opposite things. Reading them correctly saves a lot of random restarting.
curl: (7) Failed to connect to 192.0.2.10 port 8080: Connection refused
ssh: connect to host 192.0.2.10 port 22: Connection timed out
nc: connect to 192.0.2.10 port 5432 (tcp) failed: No route to host
Connection refused: the host is there, the port is not
Your packets reached the machine and its kernel replied “nothing is listening on that port” (a TCP RST). This is good news: name resolution, routing and usually the firewall are fine. Causes, in order of likelihood:
- The service is not running. On the server:
systemctl status myapp,docker ps. - It is running but on a different port. On the server:
sudo ss -ltnpand compare with what you are connecting to. - It listens only on
127.0.0.1, so it answers local connections but refuses remote ones. The samessoutput shows this. Databases do this by default; change the bind address in the service config (for examplelisten_addressesin PostgreSQL,bind-addressin MySQL) only if remote access is really intended, and then restrict it with the firewall. - You are connecting to the wrong host: a typo in the address, or the name resolves to an old address.
dig +short name. - Some firewalls are configured to reject instead of drop, which produces the same message. On the server,
sudo ufw status verboseorsudo firewall-cmd --list-all.
Connection timed out: nothing came back
Your packets went out and nothing at all returned, not even a refusal. After a while the client gives up. Something between you and the service silently dropped the traffic, or the address does not lead anywhere. Check from the outside in:
- Is the address right and reachable at all?
ping 192.0.2.10. Many hosts block ping, so a failed ping is not proof, but a successful one rules out routing. - Is it just this port?
nc -zv 192.0.2.10 22against a port you know is open (SSH). If SSH connects and 8080 times out, a firewall is dropping 8080. - On the server, is the port open in the host firewall?
sudo ufw status/sudo firewall-cmd --list-all. Cloud servers also have a security group or network firewall in the provider’s console that must allow the port; this is the single most common cause on fresh cloud machines. - Is the service listening on
0.0.0.0and not only on localhost? A localhost-only listener plus a firewall that drops gives a timeout too. - Is the route broken?
traceroute 192.0.2.10(ormtr) shows where replies stop. Inside a company network, a VPN that is not connected is a classic cause.
No route to host and Network is unreachable
No route to host usually means the last router knew the address was on its local network and nobody answered the ARP request: the machine is off, or the address is wrong. On a Linux server it can also come from firewalld, whose default reject rule answers with an ICMP “host prohibited” message. Network is unreachable means your own machine has no route for that address: you are offline, or you are trying to reach an IPv6 address without IPv6 connectivity (try curl -4).
Quick table
- refused: fix the service or its bind address on the server.
- timed out: fix the firewall, security group or address; the service itself may be fine.
- no route to host: wrong address, machine down, or firewalld reject.
- network unreachable: fix your own connectivity or route.
- name or service not known / could not resolve host: DNS, not the connection at all.
The port-check script in this topic turns these checks into one command you can run against a list of host:port pairs.
Official documentation
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0266 What is a port? A port is a numbered door on a computer that lets one machine run many network services at the same time. Beginner · Explains an idea · Any system Article DNS, IP addresses & ports 15 Oct 2026
- 0274 What is DNS? DNS is the internet's phone book: it turns names like example.com into the IP addresses computers actually use. Beginner · Explains an idea · Any system Article DNS, IP addresses & ports 15 Oct 2026
- 0275 What is an IP address? An IP address is the unique number that identifies a device on a network so data knows where to go. Beginner · Explains an idea · Any system Article DNS, IP addresses & ports 15 Oct 2026
- 0280 What is a firewall? A firewall is a filter that decides which network connections are allowed in or out of a computer or network. Beginner · Explains an idea · Any system Article Firewalls 15 Oct 2026
- 0341 DNS, IP addresses and ports explained for beginners An IP address says which machine, a port says which program on it, and DNS turns names into addresses. The three ideas… Beginner · Explains an idea · Linux, macOS Article DNS, IP addresses & ports 15 Oct 2026
- 0342 Which process is using a port, and how to free it Find the program behind a busy port with ss, lsof or fuser, decide whether to stop it properly or kill it, and… Beginner · Step by step · Linux, macOS Article DNS, IP addresses & ports · Networking & firewalls 15 Oct 2026
Repos in the wild
- Pi-hole: network-wide ad blocking with your own DNS server pi-hole/pi-hole A DNS server for your home or office network that answers queries for known advertising and tracking domains with nothing, so every device on the network is protected without installing anything on it. GitHub
- CrowdSec: collaborative intrusion prevention that shares blocklists crowdsecurity/crowdsec CrowdSec reads your logs, detects attacks such as brute force and scanning, blocks the source, and shares anonymised reports so that every participant receives a blocklist built from the whole community. GitHub
- Suricata: a network intrusion detection and prevention engine OISF/suricata Suricata inspects network traffic in real time, matches it against signature rules and protocol logic, and writes alerts and rich protocol logs. It can also sit inline and drop malicious packets. GitHub
- Nmap: the network mapper for inventorying your own network nmap/nmap Nmap is the long-standing open source tool for discovering hosts, open ports, services and operating systems on a network you administer, used to inventory systems and verify that firewall rules behave as intended. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +3,706 chars