The Connection Timed Out error means a client tried to reach a server, but the server didn’t respond within the expected timeframe, indicating a breakdown in network communication between them.

This often stems from a firewall blocking the connection. Check iptables rules on the server, looking for rules that might drop or reject traffic on the specific port the client is trying to use. For example, if your client is trying to connect to a web server on port 80:

sudo iptables -L -n -v

If you find a rule that looks like this (or similar, blocking traffic):

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80

You can remove it with:

sudo iptables -D OUTPUT -p tcp --dport 80 -j DROP

This works because iptables is the Linux kernel’s firewall. Removing the DROP rule allows the outgoing TCP packets to reach their destination.

Another common culprit is the client’s own firewall. On the client machine, check ufw (Uncomplicated Firewall) or firewalld. For ufw:

sudo ufw status verbose

If you see a rule denying outbound traffic on the target port:

To                         Action      From
--                         ------      ----
80/tcp                     DENY IN     Anywhere

You’d allow it with:

sudo ufw allow out 80/tcp

This explicitly permits outbound TCP connections on port 80 from the client.

Network Address Translation (NAT) misconfigurations on routers or firewalls can also cause this. If the server is behind a NAT device and port forwarding isn’t set up correctly, incoming requests won’t reach the server. You’ll need to access the NAT device’s configuration interface and ensure the port forwarding rule maps the external IP and port to the server’s internal IP and port. For instance, on a typical home router, you’d find a section labeled "Port Forwarding" or "Virtual Servers" and set up an entry like:

  • External Port: 80
  • Internal Port: 80
  • Protocol: TCP
  • Internal IP Address: 192.168.1.100 (your server’s IP) This configures the router to send traffic arriving on its public IP address on port 80 to the specified internal server.

The server’s network interface might be down or misconfigured. Verify the status of the network interface on the server using ip addr show.

ip addr show eth0

Look for state UP and a valid IP address. If it’s down or has an incorrect IP:

sudo ip link set eth0 up
sudo ip addr add 192.168.1.100/24 dev eth0

Bringing the interface UP activates it, and ip addr add assigns the correct IP configuration, enabling network communication.

DNS resolution issues mean the client can’t even find the server’s IP address. On the client, test DNS resolution with dig or nslookup:

dig example.com

If it fails to resolve, check the client’s /etc/resolv.conf for correct DNS server entries. If the DNS server is 8.8.8.8, and it’s not working, try changing it to another public DNS server like 1.1.1.1 by editing the file:

nameserver 1.1.1.1

This ensures the client uses a functional DNS server to translate domain names into IP addresses.

An overloaded server can also lead to timeouts, as it might not be able to process new incoming connections. Check server load with top or htop. If CPU or memory usage is consistently high (e.g., >90%):

top

You might need to optimize the application running on the server or upgrade server resources. For example, if a web server process (apache2 or nginx) is consuming all CPU, investigate its configuration or add more worker processes if the server has sufficient cores.

Finally, network congestion or routing problems between the client and server can cause packets to be dropped. Use traceroute from the client to the server’s IP address to identify where the packets are being lost:

traceroute <server_ip_address>

If a hop shows excessive latency or * * * for multiple hops, it indicates a problem in that segment of the network path. The fix here is usually external to your immediate control, involving your ISP or network provider.

After fixing these, you might encounter a Connection Refused error, indicating the server is reachable but no process is listening on the requested port.

Want structured learning?

Take the full Computer Networking course →