rescueshell Start trial

SSH into an OpenWrt router behind CGNAT

A router on a 4G modem, a satellite link or a customer's network often has no public address, so nothing can connect in. The router has to dial out.

Why port forwarding and DDNS fail

Port forwarding opens a port on the router's public address. Behind CGNAT the router has none: the address on its WAN side is private or shared with other customers, and the carrier's equipment sits in front of it. A forward on the router is never reached, because the connection stops at the carrier.

Dynamic DNS does not help for the same reason. It keeps a name pointed at an address, and the address it would publish is not one anyone can reach. To check, compare the WAN address on the router's status page with your public IP from any "what is my IP" site. If they differ, or the WAN address is between 100.64.0.0 and 100.127.255.255, see SSH behind CGNAT.

Some links also give a public IPv6 address. That can work if the router's firewall allows it and the machine you connect from has IPv6 too. Many do not, so this page assumes the router has to dial out.

Three ways to dial out from a router

Reverse SSH to your own server

The router runs ssh -R to a server you rent, and you log in to that server, then to the port that leads back. autossh is in the OpenWrt package feed and redials when the link drops. Run it from a procd service so it starts at boot. A sketch, which we have not run on a router:

#!/bin/sh /etc/rc.common
START=95
USE_PROCD=1
start_service() {
  procd_open_instance
  procd_set_param command /usr/sbin/autossh -M 0 -N \
    -i /etc/tunnel_key -R 22022:localhost:22 tunnel@your-server.example
  procd_set_param respawn
  procd_close_instance
}

A VPN mesh package

WireGuard and Tailscale both have OpenWrt packages. A mesh joins the router to a network of your other machines, so you get more than a shell: any port, a web interface, device to device traffic.

A hosted relay

An agent on the router keeps one outbound HTTPS connection to the relay, and you open a shell from the browser or a CLI. You run no server. The relay is a dependency: if it is unreachable, you cannot open a shell.

The three compared goes through where each one wins. For one router and a server you already run, a reverse tunnel is fine. For a network, not a shell, use a mesh.

RescueShell on OpenWrt

Four things decide if this fits your router. This is what the product does today.

1. Check the CPU

uname -m
cat /etc/openwrt_release

The installer builds exist for amd64, arm64, armv7 and armv6, picked from uname -m. A router that reports mips or mipsel, which covers a lot of older boards, is not supported: the installer stops with unsupported CPU and installs nothing. Check first.

2. OpenSSH, not Dropbear

A shell is a session on the router's own OpenSSH server. Dropbear is not supported, and there is no password fallback. The installer never installs packages itself. It installs the agent either way and prints what to run, so you can also run it first and read the output. The commands, including moving Dropbear off port 22, are in install on a host without OpenSSH. In short:

uci set dropbear.@dropbear[0].Port='2222'
uci commit dropbear
/etc/init.d/dropbear restart
opkg update
opkg install openssh-server openssh-keygen curl ca-bundle openssl-util
/etc/init.d/sshd enable
/etc/init.d/sshd start

Do that from the serial console or a second session: restarting Dropbear can drop the one you are in. OpenSSH takes more flash than Dropbear. On x86_64 we put it at a few MB, and other architectures differ, so check df -h /overlay first. A router with very little flash may not fit it. We have no figures for the agent itself on a router.

3. Install

Create a token in the dashboard, then run this on the router as root:

curl -fsSL https://releases.rescueshell.com/latest/install.sh | sh -s -- \
  --base-url https://releases.rescueshell.com/latest --relay https://app.rescueshell.com \
  --name pump-07 --trust-keys-from pi

Two changes for OpenWrt:

The installer lists each key it will trust and asks you to confirm. Our servers cannot add a key to that list.

4. What it sets up

When the link drops, the agent retries every 60 seconds, five times, then waits 30 minutes and starts over. It needs outbound HTTPS and nothing inbound. On a mobile link, see SSH over 4G or LTE for what that costs in data.

What we tested, and what it does not do

If the shell does not open, see the shell does not open.

Try it on one router

The first device is free to try with no card, for 30 days from when it connects, not from when you sign up. Start a trial.