A Git deployment workflow VPS setup helps you deploy application updates from a Git repository…
How to Troubleshoot TCP Connection Timeouts on a VPS

TCP connection timeouts on a VPS can cause websites to become unreachable, applications to stop responding, APIs to fail, and remote services to become intermittently unavailable. Unlike a connection-refused error, a TCP timeout often means the client did not receive a response within the expected period.
The cause may be a firewall silently dropping packets, an incorrect route, an overloaded server, a remote service that is not responding, or a network problem between the two endpoints.
This guide explains how to troubleshoot TCP connection timeouts on a Linux VPS using practical commands and a step-by-step diagnostic process.
What Is a TCP Connection Timeout?
TCP is a transport protocol that establishes a connection between two endpoints before exchanging application data. During connection establishment, a client typically sends a SYN packet, the server responds with SYN-ACK, and the client completes the handshake with an ACK packet.
A TCP connection timeout occurs when the connection attempt does not complete within the time allowed by the client, operating system, or application.
For example, an application connecting to a remote database might report a timeout because its SYN packets never receive a response. The same symptom can occur when a firewall drops traffic or the remote host is unreachable.
It is important to distinguish a TCP timeout from other connection errors:
- Connection timed out: The expected response did not arrive within the configured time.
- Connection refused: The destination or an intermediary actively rejected the connection.
- Network is unreachable: The local system has no usable route to the destination, or a network error explicitly reports that the destination is unreachable.
- Connection reset: The connection was reset rather than completing or continuing normally.
These errors can have different causes, so identifying the exact message is the first step toward an effective diagnosis.
1. Confirm the Destination IP and Port
Start by identifying the exact destination that is timing out. Record the hostname or IP address, destination port, source VPS, and approximate time of the failure.
For example, suppose your VPS needs to connect to a remote service at 203.0.113.20 on TCP port 443.
Test the connection with netcat:
nc -vz -w 5 203.0.113.20 443
The options mean:
-v: Display connection details.-z: Check whether a connection can be established without sending application data.-w 5: Set a five-second timeout for the connection attempt.
Replace the example address and port with the actual destination. The IP address above belongs to a documentation-only range and is not a real service endpoint.
If netcat is not installed, use an available alternative such as curl for HTTP or HTTPS services:
curl -v --connect-timeout 5 https://example.com/
This command tests an HTTPS connection and displays connection details. A failure may occur during DNS resolution, TCP connection establishment, TLS negotiation, or the HTTP exchange, so read the output carefully.
For a more targeted test against a particular address:
curl -v --connect-timeout 5 \
--resolve example.com:443:203.0.113.20 \
https://example.com/
This forces curl to connect to the specified IP while retaining the hostname for HTTP and TLS. Replace the example hostname and IP with your actual values.
What to check: If the connection fails consistently, continue with routing, firewall, and packet-level diagnostics. If it succeeds intermittently, collect several results and compare them with the time of the reported outage.
2. Verify DNS Resolution
If your application connects using a hostname, confirm that the hostname resolves to the expected address.
Use:
getent ahosts example.com
You can also query DNS directly with dig, if installed:
dig example.com A
dig example.com AAAA
Check both IPv4 and IPv6 records when the client or application may use either protocol.
A hostname can resolve to multiple addresses, and different addresses may lead to different results. An application may also prefer IPv6 even when its IPv6 route or destination service is not working correctly.
Compare the hostname-based result with a test against the destination IP.
For HTTPS, do not assume that opening the IP address directly is an equivalent test. TLS certificates and virtual hosting frequently depend on the requested hostname.
If the IP-based test works but the hostname-based test fails, investigate DNS answers, address selection, and resolver behavior before changing firewall rules.
3. Check the VPS Routing Table
A TCP connection requires a valid path from the source VPS to the destination. Incorrect routing, an unavailable gateway, or a policy-routing rule can prevent packets from reaching the remote host.
Display the routing table:
ip route show
Check which route the kernel selects for a destination:
ip route get 203.0.113.20
For IPv6, use:
ip -6 route show
ip -6 route get 2001:db8::20
The IPv6 address shown here is also reserved for documentation.
Review the selected interface, gateway, source address, and routing table. If your server has multiple network interfaces or policy-routing rules, also inspect:
ip rule show
ip route show table all
Do not add or replace a default route simply because a connection times out. A production VPS may rely on provider-specific routing, multiple interfaces, or custom network configuration.
If the route appears correct, test reachability to the gateway and destination where possible. Remember that some routers and servers block ICMP, so a failed ping does not automatically prove that TCP traffic is blocked.
4. Inspect the Local Firewall
A firewall may reject a TCP connection explicitly or silently drop packets. Silent drops are particularly relevant to connection timeouts because the client may continue waiting for a response.
First identify which firewall system your distribution uses.
For UFW:
sudo ufw status verbose
For firewalld:
sudo firewall-cmd --state
sudo firewall-cmd --list-all
For nftables:
sudo nft list ruleset
For iptables-based systems:
sudo iptables -S
sudo iptables -L -n -v
If IPv6 is enabled, review the applicable IPv6 firewall rules as well.
Look for rules that may drop traffic to the destination port, restrict outbound connections, or block established and related traffic unexpectedly. Review packet counters when available.
Remember that a locally permitted connection can still be blocked by a cloud firewall, provider network ACL, upstream filtering system, or remote firewall.
Avoid flushing firewall rules or disabling the firewall as a diagnostic shortcut on a production server. Doing so can expose services and interrupt existing connections.
If you need to test a rule change, use a narrowly scoped change with a documented rollback plan.
5. Check Whether the Destination Port Is Listening
If you control the destination server, verify that the application is listening on the expected port and interface.
On the destination server, run:
sudo ss -lntp
To filter for a specific port, such as TCP port 443:
sudo ss -lntp 'sport = :443'
Check whether the service is listening on the public or intended interface, rather than only on 127.0.0.1 or ::1.
A service bound only to loopback may accept connections from the same server but remain inaccessible to remote clients.
Check the application service status:
sudo systemctl status nginx
Replace nginx with the relevant service name.
If the service is not running, inspect its logs before restarting it:
sudo journalctl -u nginx --since "30 minutes ago"
A port that is not listening often leads to a connection-refused error when the host is reachable and actively rejects the connection. However, a timeout may still occur if a firewall silently drops the traffic before it reaches the service.
6. Use Packet Capture to Locate the Failure
Packet capture is one of the most useful ways to determine whether a TCP connection attempt reaches the destination and whether a response returns.
On the source VPS, capture traffic to the destination IP and port:
sudo tcpdump -ni any 'host 203.0.113.20 and tcp port 443'
Keep the capture running, then reproduce the failed connection from another terminal. Stop the capture with Ctrl+C after collecting enough data.
Interpret the packet sequence carefully.
Scenario A: SYN packets leave, but no response arrives
The source repeatedly sends TCP SYN packets without receiving a SYN-ACK or RST.
Possible causes include:
- A firewall silently dropping traffic.
- An unreachable destination.
- A missing return route.
- A provider-level network filter.
- A remote host that is not responding.
This result does not identify the exact device responsible. Capture traffic on the destination server as well, if you have access.
Scenario B: SYN reaches the destination, but no reply leaves
If the destination capture shows incoming SYN packets but no corresponding response, investigate the destination’s firewall, listening service, kernel networking, and system resource pressure.
Scenario C: SYN-ACK leaves the destination, but the source never receives it
This suggests a possible return-path problem, upstream filtering, or asymmetric routing. Compare captures at both endpoints and inspect the routes in both directions.
Scenario D: The TCP handshake completes
If SYN, SYN-ACK, and ACK are present, TCP connection establishment succeeded. The timeout may instead occur during TLS negotiation, application processing, database authentication, or another stage after the connection is established.
For HTTPS, use curl’s verbose output and timing information to identify the stage at which progress stops.
7. Check for Packet Loss and Path Problems
A connection can time out when packets are lost along the path between the VPS and the destination.
If available, use mtr to examine the route:
mtr -rwzc 50 203.0.113.20
This runs a report with 50 probes. Depending on the installed version, option support may differ.
You can also use traceroute:
traceroute -T -p 443 203.0.113.20
TCP traceroute may require additional privileges or a compatible implementation.
These tools can help identify routing changes and potential packet loss, but intermediate routers often limit or deprioritize diagnostic responses. Loss shown at an intermediate hop is not conclusive evidence of forwarding loss if later hops and the destination respond normally.
If the destination does not respond to diagnostic probes, use packet captures and application-specific tests to build a more reliable picture.
8. Examine Connection States and Socket Pressure
A VPS under heavy load or with an exhausted connection-related resource may struggle to establish new TCP connections.
Display TCP socket statistics:
ss -s
List TCP connections:
sudo ss -tan
Count connections in selected states:
sudo ss -tan | awk 'NR > 1 {count[$1]++} END {for (state in count) print state, count[state]}'
Review the output for unusually large numbers of established connections, SYN-RECV sockets, or TIME-WAIT sockets. The significance depends on the workload and normal connection patterns.
Check system resource pressure:
uptime
free -h
Also inspect the kernel log for relevant network or memory errors:
sudo journalctl -k --since "30 minutes ago"
Do not assume that TIME-WAIT sockets are inherently a problem. They are a normal part of TCP connection handling. Likewise, a large number of SYN-RECV sockets needs context before you conclude that the server is under attack.
Avoid increasing kernel limits or changing TCP tuning parameters until you have identified a specific resource bottleneck.
9. Investigate Conntrack and Connection Tracking Limits
Linux servers using connection tracking may experience problems if the connection-tracking table reaches its configured limit.
This can be relevant on firewalls, NAT gateways, and VPS instances handling many simultaneous connections.
If the relevant kernel interfaces are available, check the current connection-tracking count:
cat /proc/sys/net/netfilter/nf_conntrack_count
Check the configured maximum:
cat /proc/sys/net/netfilter/nf_conntrack_max
These files may not exist if connection tracking is unavailable or not loaded.
Review kernel logs for messages indicating that the connection-tracking table is full:
sudo journalctl -k --since "1 hour ago" | grep -iE 'conntrack|table full'
If you find evidence of connection-tracking exhaustion, determine which traffic is creating the load and whether the VPS is acting as a firewall, NAT gateway, or busy application server.
Increasing the maximum count without understanding memory usage and traffic patterns may only postpone the issue. Some providers also manage these resources outside the guest operating system.
10. Check the Remote Server’s Return Route
TCP requires a working path in both directions. Even if the source VPS can send packets to the destination, the response must return to the correct source address.
On the destination server, identify the source address seen in the incoming connection and inspect the route back to it:
ip route get SOURCE_IP
Replace SOURCE_IP with the actual source address.
If the server has multiple network interfaces, policy routing, a VPN, or a custom gateway, confirm that replies leave through the intended path.
Asymmetric routing is not always a problem, but it can cause failures when stateful firewalls or network policies expect traffic to follow a particular path.
If you cannot access the destination server, ask its administrator or hosting provider to verify inbound packets, firewall decisions, and return traffic.
11. Compare IPv4 and IPv6 Connectivity
Some connection failures affect only one IP protocol.
Test IPv4:
curl -4 -v --connect-timeout 5 https://example.com/
Test IPv6:
curl -6 -v --connect-timeout 5 https://example.com/
If IPv4 works while IPv6 times out, inspect the IPv6 address, route, firewall, and destination’s IPv6 listener.
If IPv6 works but IPv4 fails, perform the corresponding checks for IPv4.
Do not disable IPv6 globally just because one connection fails. First establish whether the problem is caused by DNS address selection, routing, filtering, or an application-specific configuration.
12. Check Provider-Level Firewalls and Network Policies
Not every network restriction is visible inside the VPS.
Depending on your hosting environment, traffic may also be filtered by:
- Cloud firewall rules.
- Virtual network security groups.
- Provider network ACLs.
- DDoS mitigation systems.
- Upstream routing or filtering policies.
- Remote service allowlists.
If local routes and firewall rules look correct, review the provider’s network settings and confirm that the source IP and destination port are allowed.
For a VPS-to-VPS connection, verify both servers’ firewall policies. The source server may permit outbound traffic while the destination server blocks the incoming connection.
When opening a support ticket, provide the source and destination IP addresses, destination port, timestamps with timezone, test output, and relevant packet-capture findings. Avoid including passwords, private keys, or other credentials.
13. Understand Application-Level Timeouts
Not all timeout errors indicate that TCP connection establishment failed.
Applications may use separate timeout settings for:
- DNS resolution.
- Establishing a TCP connection.
- Negotiating TLS.
- Waiting for the first response byte.
- Completing an entire request.
- Reading from or writing to a database.
For example, curl allows separate connection and overall operation time limits:
curl -v --connect-timeout 5 --max-time 20 https://example.com/
Here, --connect-timeout limits the connection phase, while --max-time limits the total operation duration.
If TCP connects successfully but the application still times out, investigate the service logs, application workers, upstream dependencies, database performance, and timeout configuration.
Increasing the timeout can sometimes help with legitimate long-running operations, but it does not repair packet loss, blocked traffic, or a service that is no longer responding.
14. Build a Repeatable Troubleshooting Workflow
When diagnosing a TCP timeout on a production VPS, follow a consistent sequence:
- Record the exact error, source, destination, port, and timestamp.
- Resolve the hostname and confirm the selected IP address.
- Test the destination port with an appropriate client.
- Check the source VPS routing table.
- Review local and provider-level firewall rules.
- Verify that the destination service is listening.
- Capture packets to determine whether requests and responses travel successfully.
- Check connection states, resource pressure, and connection-tracking limits where relevant.
- Verify the destination’s return route.
- Repeat the test after making one controlled change at a time.
This workflow helps distinguish network-path problems from local firewall restrictions, remote service failures, and application-level delays.
TCP connection timeouts on a VPS can originate from several layers, including DNS, routing, firewalls, remote services, connection tracking, and application configuration. The timeout message alone is not enough to identify the cause.
Start with a simple connection test, verify the route, inspect firewall rules, and use packet capture when the failure remains unclear. Comparing traffic at both endpoints is often the most effective way to locate where a connection stops progressing.
Avoid disabling security controls or changing kernel networking parameters without evidence. A structured diagnosis reduces unnecessary changes and helps restore reliable connectivity while keeping the server secure.
