Ubuntu Server 22.04 Unreachable via SSH After Time: A Troubleshooting Guide

Abstract: Resolve Ubuntu Server 22.04 SSH disconnections caused by NAT timeouts and firewall state expirations by configuring client keep-alives and verifying network persistence.

Created: 2026-10-24 by
Ubuntu Server 22.04 becomes unreachable via SSH after a period of inactivity primarily due to network address translation timeouts, dynamic IP changes, or firewall state table expirations. This guide walks you through diagnosing these connectivity drops by verifying network persistence, checking firewall rules, and adjusting keep-alive settings to maintain stable remote access without manual intervention.

Diagnosing the Root Cause

The first step in resolving an intermittent SSH connection is to determine whether the issue lies with the server’s identity on the network or the network path itself. If the server loses its ability to be reached after some time, it often indicates that the IP address assigned to the machine has changed, or the router’s NAT (Network Address Translation) session has expired.

To verify if the IP address has changed, log into your server locally or via console access provided by your hosting provider. Run the command ip addr show to check the current IPv4 address. Compare this with the IP address you have been using in your SSH client. If they differ, your server is likely receiving a new lease from a DHCP server, which is common in cloud environments with ephemeral instances. If the IP remains static, the problem is likely related to connection state tracking in firewalls or intermediate network devices.

Another critical factor is the public IP usage. If you are connecting from a dynamic residential IP, your own outgoing port mappings might be resetting. However, the most frequent culprit for servers becoming "unreachable" specifically after a timeout is the expiration of the connection state in the server’s firewall or the cloud provider’s security group. These systems track active connections and drop them when they appear idle, but they may fail to re-establish the handshake properly if the client does not send periodic keep-alive signals.

Configuring SSH Keep-Alive Settings

To prevent the connection from being dropped by intermediate firewalls or routers, you must configure the SSH client to send periodic keep-alive messages. This ensures that the network devices recognize the connection as active and do not close the state table entry. You can achieve this by modifying the configuration file on your local client machine.

Edit your SSH client configuration file located at ~/.ssh/config. If the file does not exist, create it. Add the following lines to configure all connections or specify them for specific hosts:

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

The ServerAliveInterval directive tells the SSH client to send a message through the encrypted channel every 60 seconds if no data has been received from the server. The ServerAliveCountMax setting defines how many missed responses constitute a failure before disconnecting. With these settings, even if the server appears idle, the client will maintain the tunnel, preventing firewalls from timing out the connection. This is particularly effective against NAT timeouts which typically range from 5 to 15 minutes.

Adjusting Server-Side Firewall Rules

If client-side keep-alives do not resolve the issue, the problem may lie within the server’s own firewall, such as UFW (Uncomplicated Firewall) or iptables. Some firewall configurations drop established connections after a certain period of inactivity if the state tracking module is misconfigured or too aggressive.

Check your current firewall status by running sudo ufw status verbose. Ensure that the SSH port (usually 22) is allowed. More importantly, inspect the connection tracking limits. In Linux, the kernel parameter net.netfilter.nf_conntrack_tcp_timeout_established controls how long an established TCP connection is kept in memory. If this value is low, connections may be purged prematurely.

You can view the current timeout by running cat /proc/sys/net/netfilter/nf_conntrack_tcp_timeout_established. If it is set to a very low number, consider increasing it. However, note that changing kernel parameters requires root access and may affect system performance. A safer approach is to ensure that your cloud provider’s security groups (like AWS Security Groups or Azure Network Security Groups) do not have idle timeout settings that conflict with your application needs. These cloud-level firewalls often operate independently of the OS firewall and can block traffic before it reaches your local iptables rules.

Verifying Network Interface Stability

Sometimes, the network interface itself may go down or switch to a different carrier, causing the IP to become unreachable until the interface is restarted. This is less common in virtualized environments but can happen in bare-metal setups with unstable hardware or drivers.

Monitor the network interface logs by running dmesg | grep eth0 (replace eth0 with your actual interface name). Look for messages indicating link down/up events. If you see frequent disconnections, investigate physical cabling or virtual network driver updates. Additionally, ensure that your systemd-networkd or Netplan configuration is set to retry connection establishment automatically upon failure.

Related Troubleshooting Steps

If you have verified network stability and configured keep-alives but still face issues, consider other potential blockers. For instance, authentication failures can sometimes manifest as connection resets if the SSH daemon rejects the key repeatedly. Check the server logs at /var/log/auth.log for detailed rejection reasons. Also, ensure that your SSH service is running correctly by executing sudo systemctl status ssh.

For more complex scenarios involving credential management, refer to our guide on SSH Credentials Added Twice to rule out configuration conflicts. Similarly, if you cannot connect at all and need to regain access, see Unable to SSH into Ubuntu Server: Log in Locally First for recovery procedures.

Frequently Asked Questions

Why does my SSH connection drop exactly after 5 minutes?

This is typically caused by NAT timeout settings in your router or cloud provider’s load balancer. Most NAT devices drop idle TCP connections after 5 to 10 minutes to free up resources. Configuring ServerAliveInterval on your client sends periodic packets that reset this timer, keeping the connection alive indefinitely.

Can I enable keep-alives on the server side instead of the client?

No, the ServerAliveInterval directive is a client-side option. The server side uses ClientAliveInterval in /etc/ssh/sshd_config, which sends messages from the server to the client. While both can help, the client-side setting is more reliable for maintaining outbound connections through restrictive firewalls.

What should I do if I lose access and cannot reconnect?

If you are completely locked out, use your hosting provider’s console or VNC access to log in directly. Once logged in, restart the SSH service with sudo systemctl restart ssh and check /var/log/auth.log for errors. Ensure your firewall allows incoming traffic on port 22.

Does disabling password authentication affect SSH stability?

Disabling password authentication improves security but does not directly impact connection stability or timeouts. However, if you rely on key-based authentication, ensure your private key permissions are correct (chmod 600 ~/.ssh/id_rsa) to prevent authentication failures that might look like connection drops.

How do I check if my firewall is dropping idle connections?

You can monitor active connections using conntrack -L to see how many entries are tracked. If you suspect firewall drops, compare the connection duration with known NAT timeouts. Temporarily disabling the firewall with sudo ufw disable can help isolate if the firewall is the cause, but remember to re-enable it immediately after testing.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More