Home Network SSH Between Two Machines with Two Routers Between Them

Abstract: Configure port forwarding on two routers to establish an SSH connection between machines in a double-NAT home network.

Created: 2026-09-30 by

Establishing an SSH connection between two machines separated by two routers requires configuring port forwarding on both devices and ensuring proper NAT traversal. By mapping external ports to internal IP addresses at each router level, you can create a secure tunnel that bypasses intermediate network barriers. This guide details the specific steps to configure your home network for reliable remote access.

Understanding the Network Topology

Before modifying any settings, it is crucial to visualize how data travels through your infrastructure. In a typical double-NAT scenario, you have an Internet Service Provider (ISP) modem or primary router, followed by a secondary home router, which then connects to your target machine. The primary challenge here is that the secondary router hides the target machine from the outside world, and the primary router further obscures the entire home network. To bridge this gap, you must treat each router as a distinct gateway that needs explicit instructions on where to send incoming traffic. The goal is to create a chain of redirections: traffic arrives at the public IP of the primary router, gets forwarded to the secondary router’s IP, and finally reaches the specific local IP of your SSH server. Without this layered configuration, packets will be dropped because neither device knows how to handle the incoming request destined for a private address space.

Identifying Your Local Addresses

Start by identifying the static local IP addresses of all relevant devices. You should assign static IPs via DHCP reservation on both routers to prevent address changes that would break your configuration. For the target machine running the SSH service, note its local IP (e.g., 192.168.1.50). For the secondary router, note its LAN IP address (e.g., 192.168.1.1). Finally, identify the public IP address assigned to your primary router by the ISP. If your ISP uses Carrier-Grade NAT (CGNAT), standard port forwarding will not work, and you may need to contact your provider or use a tunneling service instead.

Configuring the Secondary Router

The first step in the chain is to configure the router closest to your target machine. Log into the administrative interface of the secondary router. Navigate to the Port Forwarding or Virtual Server section, which is often found under Advanced Settings or NAT rules. Create a new rule that maps an external port on this router to the internal IP of your SSH server. Most SSH servers listen on port 22, but it is highly recommended to change the internal listening port to something non-standard, such as 2222, to reduce automated scanning attacks. Configure the rule to forward incoming traffic on port 2222 (or your chosen port) to the local IP of the SSH machine on port 22. Save the settings and verify that the rule is active. This step ensures that any traffic directed to the secondary router’s WAN interface is correctly routed to your computer.

Configuring the Primary Router

Next, log into the primary router connected directly to your ISP modem. Locate the Port Forwarding section again. Here, you must forward traffic to the secondary router rather than the final machine. Create a new rule that forwards the same external port you used in the previous step (e.g., 2222) to the local IP address of the secondary router (e.g., 192.168.1.1) on the same port. This creates the necessary link between the public internet and your inner network. When a connection attempt arrives at your public IP on port 2222, the primary router passes it to the secondary router, which then passes it to your SSH machine. Ensure that no other conflicting rules exist that might intercept this traffic. Some modern routers offer "DMZ" host features; while these can simplify setup by exposing all ports, they significantly reduce security and are not recommended for SSH access unless absolutely necessary.

Testing and Troubleshooting Connectivity

Once both routers are configured, test the connection from an external network, such as using mobile data with Wi-Fi turned off. Open a terminal and run ssh -p 2222 user@your_public_ip. If the connection times out, several factors could be responsible. First, check if your ISP blocks common ports. Many residential providers block inbound traffic on ports 22, 80, and 443. If this is the case, ensure you are using a high-numbered port like 2222 or 49152. If the connection still fails, verify that firewalls on the target machine are allowing inbound traffic on the SSH port. On Linux systems, check ufw status or iptables rules. On Windows, ensure the Windows Defender Firewall allows SSH connections. Additionally, some ISPs implement strict firewall policies that drop ICMP or specific TCP flags, which can interfere with initial handshake attempts. If you suspect this, try connecting using different protocols or tools to isolate the issue. For more complex scenarios involving dynamic DNS or failed connections, reviewing related troubleshooting guides can provide additional context. You might find useful insights in Connection to host xxxxxxxxxx at port 22 connection timed out, which addresses common timeout errors during SSH initialization.

Security Best Practices

Exposing SSH to the internet introduces significant security risks. Always disable password authentication and rely exclusively on SSH key pairs for login. This prevents brute-force attacks that attempt to guess passwords. Furthermore, consider using fail2ban or similar intrusion prevention software to temporarily ban IPs that make multiple failed login attempts. Regularly update your SSH server software to patch known vulnerabilities. Monitor access logs for unusual activity, such as login attempts from unexpected geographic locations. If you do not frequently need remote access, consider setting up a VPN instead, which provides encrypted tunnels without exposing individual services to the public internet. This approach offers a more robust security posture for home networks.

Frequently Asked Questions

Why does my SSH connection time out even after port forwarding?

Timeouts usually indicate that packets are being dropped by a firewall or blocked by your ISP before reaching your router. Check your local firewall settings on the target machine and ensure no upstream network equipment is filtering traffic. Verify that you are using the correct public IP address and port number.

Can I use the same port for both routers?

Yes, you can use the same port number on both the primary and secondary routers, provided the internal destinations are different. The primary router forwards to the secondary router's IP, and the secondary router forwards to the machine's IP. Consistency in port numbers simplifies the configuration process.

What if my ISP uses CGNAT?

Carrier-Grade NAT means you do not have a unique public IP address, making direct port forwarding impossible. In this case, you cannot expose your home network directly to the internet. You must use a tunneling service like Tailscale or ZeroTier, or request a public IP from your ISP if available.

Is it safe to expose SSH to the internet?

Exposing SSH directly is risky due to constant automated scanning and brute-force attempts. It is safer to use a VPN for remote access or restrict SSH access to specific IP addresses using firewall rules. Always use key-based authentication and keep your server software updated to mitigate these risks.

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