SSH Reverse Tunnels vs Agent Tunnels: How They Work
How ssh -R remote forwarding and agent-based relay tunnels expose localhost, covering keepalives, TLS, UDP limits, and Localtonet's tunnel lifecycle.
In this article 10 sections


Two architectures, one goal: reach a service behind NAT without opening a single inbound port
There are two common ways to put a local service on the public internet without touching your router. The first is SSH remote port forwarding, the ssh -R model that zero-install tunnel services build on. The second is a dedicated client agent that keeps an outbound connection to a relay, which is how our Localtonet client works. This guide explains what each model does on the wire: how a remote port gets bound, why idle SSH sessions die behind NAT, where TLS terminates, and why UDP cannot ride a standard SSH forward. It then maps those tradeoffs to the documented Localtonet model so you can choose based on how the system actually works.
📋 What's in this guide
Why outbound tunnels solve the localhost problem
A development laptop, a home server, or a Raspberry Pi almost never has a publicly routable address of its own. It sits behind a home router performing Network Address Translation, often behind a second layer of carrier-grade NAT, and behind host and network firewalls that drop unsolicited inbound connections. When you start a web server on localhost:8080, it is reachable from that machine (and perhaps the LAN), but a webhook sender, a teammate on another network, or a mobile app in the field has no path to it.
The traditional fix is inbound: configure port forwarding on the router, add a firewall rule, and set up dynamic DNS because the public IP changes. That approach fails completely when you do not control the router, when the ISP uses carrier-grade NAT, or when you are on a corporate, hotel, or mobile network.
Every tunneling architecture discussed here flips the direction. The machine behind NAT opens an outbound connection to a server that does have a public address. NAT devices and most firewalls permit outbound connections and track them so replies can flow back. Once that long-lived connection exists, the public server can accept traffic from the internet and push it back down the established connection to the local service. Nothing on the router changes, and the local machine never accepts an unsolicited inbound connection.
Both SSH reverse tunnels and agent-based tunnels follow this pattern. Where they differ is in what protocol carries the traffic, what software runs on each end, how the public side decides which tunnel a request belongs to, how identity works, and what happens when the outbound connection breaks. Those differences are what you feel day to day as reliability, protocol support, and control.
How ssh -R remote port forwarding binds a port on the remote side

OpenSSH ships with three forwarding modes. Local forwarding (-L) makes a port on your machine reach something through the server. Dynamic forwarding (-D) turns your machine into a SOCKS proxy that exits at the server. Remote forwarding (-R) is the reverse: it asks the server to listen on a port and send every connection it accepts back through the SSH session to a destination reachable from the client. Remote forwarding is the one that exposes localhost.
Reading the -R syntax correctly
The general form is -R [bind_address:]port:host:hostport. A minimal example:
ssh -N -R 8080:localhost:3000 user@public-server.example.com
This means: on public-server.example.com, listen on port 8080. When something connects there, open a channel back through this SSH session, and have the client connect to localhost:3000. The detail people most often get wrong is that localhost in that spec is resolved on the client, not on the server. You can also point it at another machine on your LAN, for example -R 8080:192.168.1.50:80, and the client will connect there on the server's behalf.
The -N flag tells SSH not to run a remote command, which is what you want for a forwarding-only session. Without it you get an interactive shell, and closing that shell closes the tunnel.
What happens on the wire
After authentication, the client sends a global request named tcpip-forward asking the server to bind the address and port. If the server accepts, it starts listening. Each time a remote user connects to that port, the server opens a new forwarded-tcpip channel inside the existing encrypted SSH connection. The client receives the channel, opens a regular TCP connection to the destination (localhost:3000), and copies bytes in both directions. Many simultaneous public connections become many channels multiplexed over one TCP connection between client and server.
Two consequences follow. First, SSH forwarding is a byte stream relay: it does not understand HTTP, it just shuttles TCP payload. Second, everything shares one TCP connection, so a single lost packet on that connection stalls all channels until it is retransmitted (head-of-line blocking), and if the connection dies, every forwarded session dies with it.
GatewayPorts: who can actually reach the forwarded port
On a standard OpenSSH server, a remote forward binds to the loopback interface by default. That means -R 8080:localhost:3000 creates a listener that only processes on the server itself can reach. To make it reachable from the internet, the server's sshd_config must allow it through the GatewayPorts option:
| GatewayPorts value | Effect on remote forwards | Typical use |
|---|---|---|
no (default) |
Forwarded ports bind to loopback only, regardless of what bind address the client requests. | Server-local access, or putting a reverse proxy on the server in front of the loopback port. |
yes |
Forwarded ports bind to all interfaces (wildcard address). | Simple public exposure, with no client choice over the bind address. |
clientspecified |
The client chooses the bind address in the -R spec, such as 0.0.0.0:8080 or a specific interface IP. |
Controlled exposure where different users bind different addresses. |
With GatewayPorts clientspecified, the client would request a public bind explicitly:
ssh -N -R 0.0.0.0:8080:localhost:3000 user@public-server.example.com
Hosted zero-install tunnel services do not usually run a stock sshd with these settings. They run custom SSH server implementations that receive the tcpip-forward request and interpret it their own way. When such a service tells you to run something like ssh -R 80:localhost:8080 ..., port 80 is not literally bound for you on a shared host. The service treats it as "I want HTTP," assigns a hostname, and routes matching requests to your session. The SSH protocol is the transport, and the routing logic is the service's own.
Other server-side controls that affect -R
AllowTcpForwarding: acceptsyes,no,local,remote, orall. Settingremotepermits-Rbut not-L.PermitListen: in OpenSSH 7.8 and later, restricts which addresses and ports a client may request for remote forwards.- Privileged ports: on typical Unix servers, a non-root user cannot bind ports below 1024, so
-R 80:...against a stock server as a normal user fails. - Dynamic allocation: requesting port
0(for example-R 0:localhost:3000) asks the server to choose a free port, and the client prints the allocated port.
Newer OpenSSH versions (7.6 and later) also accept -R with only a port and no destination, which turns the forward into a reverse SOCKS proxy. That is a different use case from exposing one service and is not covered further here.
Why SSH tunnels keep disconnecting: keepalives and NAT idle timeouts

The most common complaint about SSH reverse tunnels is that they work for a while, then silently stop. The usual cause is not SSH itself but the stateful devices between client and server.
NAT mappings expire when traffic stops
A NAT router remembers each outbound connection in a translation table so it knows where to deliver replies. Those entries are not kept forever. If no packets cross the mapping for a while, the device drops it. Timeouts vary widely by device and network: home routers, corporate firewalls, cloud load balancers, and mobile carrier NAT all choose their own values, and some are short enough to cut an idle session within minutes. Once the mapping is gone, packets from the server for that connection have nowhere to go.
The nasty part is that neither end is told. The client still believes the TCP connection is open. The server still believes it is open. A tunnel that receives no public traffic for a while looks healthy from your terminal, and the first visitor after the gap gets a timeout. The client may only notice when it next tries to send data and TCP retransmissions eventually give up, which can take a long time.
ServerAliveInterval and ServerAliveCountMax
OpenSSH's client has an application-level keepalive designed for exactly this:
ServerAliveInterval: if no data has been received from the server for this many seconds, the client sends a message through the encrypted channel requesting a response. The default is0, meaning disabled.ServerAliveCountMax: how many of those requests may go unanswered before the client gives up and disconnects. The default is3.
These do two jobs. The periodic messages generate traffic, which keeps NAT mappings fresh. And if the path is genuinely dead, the client detects it after roughly ServerAliveInterval × ServerAliveCountMax seconds and exits with a "Timeout, server not responding" style message instead of hanging indefinitely. A typical setting:
ssh -N \
-o ServerAliveInterval=30 \
-o ServerAliveCountMax=3 \
-o ExitOnForwardFailure=yes \
-R 8080:localhost:3000 user@public-server.example.com
With these values the client sends a probe after 30 seconds of silence and gives up after about 90 seconds without answers. ExitOnForwardFailure=yes matters for automation: by default, if the server refuses the remote forward (for example because the port is still in use), ssh stays connected without a working tunnel. With this option it exits, so whatever supervises it can retry.
The same settings can live in ~/.ssh/config so you do not repeat them:
Host tunnel-box
HostName public-server.example.com
User user
ServerAliveInterval 30
ServerAliveCountMax 3
ExitOnForwardFailure yes
RemoteForward 8080 localhost:3000
Then ssh -N tunnel-box brings the tunnel up.
TCPKeepAlive is not the same thing
TCPKeepAlive (enabled by default) uses operating system TCP keepalive packets. They are sent outside the encrypted SSH channel, their timing depends on OS settings that are often measured in hours, and they can be spoofed. For keeping NAT mappings warm and detecting dead paths quickly, ServerAliveInterval is the dependable control.
The server side: ClientAliveInterval and stale bindings
On a self-managed server, sshd_config has the mirror settings ClientAliveInterval and ClientAliveCountMax. They matter for a subtle reconnection problem. When a client's connection dies silently, the server may keep the old session, and its bound port, open. The client reconnects, requests the same remote port, and the server refuses because the stale session still owns it. You see "remote port forwarding failed for listen port 8080". Enabling client-alive probes on the server lets it reap dead sessions and release the port sooner.
ServerAliveInterval detects failure and exits; it does not bring the tunnel back. Plain ssh has no built-in reconnect loop. For a long-lived reverse tunnel you need an external supervisor such as a shell loop, a systemd service with a restart policy, or a dedicated tool like autossh that restarts sessions for you.
Supervising ssh -R with systemd
On a Linux client, a common pattern is a systemd unit that restarts the tunnel whenever ssh exits. This example assumes key-based authentication is already set up for a dedicated user and the host key is already trusted:
[Unit]
Description=Reverse SSH tunnel for local app on port 3000
After=network-online.target
Wants=network-online.target
[Service]
User=tunnel
ExecStart=/usr/bin/ssh -N \
-o ServerAliveInterval=30 \
-o ServerAliveCountMax=3 \
-o ExitOnForwardFailure=yes \
-o BatchMode=yes \
-R 8080:localhost:3000 tunnel@public-server.example.com
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
BatchMode=yes prevents SSH from waiting on a password or host key prompt that nobody will answer. The path to ssh can differ by distribution, so confirm it with command -v ssh. This gives you reconnection, but you have now written and must maintain your own tunnel agent: a supervisor, credentials, server configuration, and monitoring. That is the point where the agent-based model starts to look attractive.
HTTP Host-based routing vs raw TCP forwarding, and where TLS terminates

Whatever carries the tunnel, the public side has to answer one question for every inbound connection: which tunnel does this belong to? The answer depends on the protocol, and it determines whether a service can share a public port with thousands of others.
Raw TCP: one public port per tunnel
A raw TCP connection carries no name. When a client connects to public-server:8080, the server knows only the destination IP and port. So each raw TCP tunnel needs its own public port, which is exactly what a stock ssh -R does. This works for any TCP protocol (SSH, databases, game servers, MQTT, RDP), but public ports are a finite, shared resource on a relay, and clients must be told the port number.
HTTP: many tunnels on one port via the Host header
HTTP requests include a Host header naming the site the client wants, such as myapp.example.net. A relay can listen on ports 80 and 443 once, read the Host header of each request, and look up which tunnel owns that hostname. Thousands of tunnels share the same public port, each with its own subdomain. This is why HTTP tunnels give you a URL while TCP tunnels give you a host and port.
For HTTPS there is a catch: the Host header is encrypted inside TLS. The relay has two options:
- Terminate TLS at the edge. The relay holds a certificate for the hostname, decrypts the request, reads the Host header, and forwards the HTTP request down the tunnel. The browser's TLS session ends at the relay. This allows automatic certificates and HTTPS URLs for a local app that only speaks plain HTTP.
- Route by SNI and pass TLS through. The TLS ClientHello includes the Server Name Indication in clear text. A relay can read SNI, pick the tunnel, and forward the still-encrypted stream so TLS terminates at your local service, which must then hold its own certificate.
TLS in the SSH model
With a stock ssh -R, the SSH session encrypts traffic between client and server, but that is not end-to-end for the public visitor. A visitor connecting to the forwarded port on the server talks plain TCP to that port unless your local service speaks TLS itself. Hosted SSH-based HTTP services typically terminate HTTPS at their edge using their own certificate, decrypt the request, and send it through the SSH channel to your local plain HTTP port. The segment from the edge into the SSH tunnel is protected by SSH, but the provider's edge sees the decrypted request.
TLS in the agent model
Agent-based platforms make the same architectural choices, usually per tunnel type. HTTP-style tunnels commonly terminate TLS at the edge to provide automatic HTTPS hostnames, while raw TCP or TLS-oriented tunnel types can carry traffic that your own service encrypts. The useful question for any tunnel, SSH or agent, is: where does the visitor's TLS session end, and who can see the plaintext there?
| Forwarding style | How the public side identifies the tunnel | Where visitor TLS ends | Shares a public port? |
|---|---|---|---|
| Raw TCP (stock ssh -R or a TCP tunnel) | Public port number | At your local service, if it speaks TLS; otherwise there is no visitor TLS | No, one port per tunnel |
| HTTP with edge TLS termination | Host header after decryption | At the relay or edge | Yes, many hostnames on 443 |
| TLS passthrough by SNI | SNI in the ClientHello | At your local service | Yes, many hostnames on 443 |
How agent-based relay tunnels work
An agent-based tunnel replaces the general-purpose SSH client with a purpose-built client application. The agent authenticates to a relay service, keeps an outbound control connection open, and receives instructions about which tunnels it should serve. When a visitor reaches a public URL or port on the relay, the relay hands the connection to the right agent over the outbound connection, and the agent connects to the configured local target.
Structurally this is the same trick as ssh -R. The differences come from the agent being designed for the job rather than borrowed from a remote shell tool:
The price is an install step. You download and run the agent instead of using the SSH client already on your system. Whether that tradeoff is worth it depends on how long the tunnel needs to live, which protocols you need, and how many people or devices are involved.
Operational tradeoffs: reconnection, protocols, identity, and lifecycle
Both architectures expose localhost successfully. The practical differences show up after the first five minutes.
Reconnection behavior
A plain ssh -R session is a single process with no reconnect logic. When the network changes (laptop sleeps, Wi-Fi switches, VPN toggles, NAT mapping expires), the session dies or hangs, and you must restart it manually or wrap it in a supervisor. On reconnect, a hosted service may assign a different hostname unless you have arranged a fixed one, and a self-hosted server may still be holding the old port.
A dedicated agent is a long-running program built for one job, so reconnection handling lives inside it rather than in your scripts. The precise retry timing of any given agent is an implementation detail worth checking in its documentation. Architecturally, separating tunnel configuration from the running session means the tunnel's identity and public address are defined on the platform, so they do not depend on what you typed into a terminal last time.
Multi-protocol needs: why UDP cannot ride ssh -R
SSH port forwarding is TCP-only. The tcpip-forward and forwarded-tcpip mechanisms carry TCP streams, and there is no UDP equivalent for -R or -L. This rules out a standard SSH forward for DNS servers, many game servers, VoIP and WebRTC media, WireGuard, QUIC-based services, and a lot of IoT and telemetry protocols.
The usual workarounds are awkward:
- UDP-to-TCP shims: tools like
socaton both ends convert datagrams into a TCP stream and back. This loses datagram boundaries unless the shim frames messages, adds TCP head-of-line blocking to a protocol that chose UDP to avoid it, and breaks anything sensitive to latency or reordering. - SSH tun/tap devices: OpenSSH's
-woption can create a layer-3 or layer-2 tunnel device, which can carry UDP. It requiresPermitTunnelon the server, usually root privileges on both sides, and manual IP addressing and routing. At that point you are building a VPN on top of TCP, with the performance problems that implies.
An agent-based platform can implement UDP as its own tunnel type, relaying datagrams rather than tunneling them inside a TCP byte stream between public visitors and the relay. For any workload that needs UDP, this is often the deciding factor.
Identity: SSH keys vs device tokens
In the SSH model, identity is an SSH key pair (or, for some hosted services, no identity at all). On a self-hosted server, each authorized key is a credential that can open a shell unless you restrict it. Rotating access means editing authorized_keys on the server. Anonymous hosted services trade identity for convenience: anyone can create a tunnel, and you get whatever hostname the service assigns.
In the agent model, identity is a token issued by the platform and tied to a device. Revoking or rotating it happens on the platform, and the token grants tunnel access rather than shell access to a server. The token is still a secret: anyone who has it can act as that device.
Lifecycle control
With ssh -R, the tunnel exists exactly as long as the process. "Is the tunnel running?" means "is that terminal still open, or is that service unit active?" There is no inventory of which tunnels exist, who started them, or what they expose, unless you build one.
Agent platforms typically separate defining a tunnel from running it. A tunnel can exist in configuration while stopped, be started when needed, and be removed explicitly. That separation gives you an inventory and an off switch that does not require shell access to the machine running the agent.
| Concern | SSH reverse tunnel (ssh -R) | Agent-based relay tunnel |
|---|---|---|
| Software on the local machine | OpenSSH client, usually preinstalled on macOS, Linux, and current Windows | A dedicated client application |
| Protocols | TCP streams only for port forwarding; UDP needs shims or tun devices | Defined by the platform's tunnel types, which can include UDP |
| Public routing | Port binding on the server; hosted services add their own hostname logic | Platform-managed hostnames and ports per tunnel type |
| Idle disconnects | Requires ServerAliveInterval and often server-side ClientAliveInterval |
Connection maintenance handled inside the agent |
| Reconnection | External supervisor needed | Part of the agent's job; check agent docs for specifics |
| Identity | SSH keys, or anonymous on some hosted services | Platform-issued device token |
| Lifecycle and inventory | Process lifetime only | Tunnels defined, started, stopped, and deleted on the platform |
| Monitoring | Build your own from logs or process state | Platform-level status, often with API or notifications |
Neither column is universally better. For a one-off demo from a laptop that already has SSH, a quick ssh -R to a hosted service or your own VPS is hard to beat. For anything that must stay up, carry UDP, serve several devices, or be visible to a team, the agent model removes a lot of infrastructure you would otherwise build yourself.
How the Localtonet tunnel lifecycle maps to these tradeoffs
Localtonet is an agent-based platform. Our client application runs on the device that can reach your local service and establishes an outbound connection to a Localtonet relay server. The resulting tunnel provides a public URL or public host and port, with no inbound router port forwarding, firewall changes, VPN setup, or public IP address. Here is how each architectural concern from the previous sections maps to our documented model.
Device token instead of SSH keys
Each client device is identified by an auth token. Tokens are device-specific, so the token tells our platform which device should serve a tunnel. Treat it like a private key: do not paste it into shared scripts, screenshots, public repositories, or chat. Unlike an SSH key on a self-hosted server, the token is not a login to a shell on any machine; it identifies the device that runs your tunnels.
Relay server selection
In the SSH model you pick the server by hostname. With Localtonet, you select a relay server (server code or region) when you create the tunnel. Available servers come from the current dashboard rather than a fixed list, so we do not hardcode values here; choose one from the options shown for your account.
Tunnel types instead of "everything is TCP"
Our documented tunnel categories are HTTP/s, TCP, UDP, TLS, combined UDP/TCP, File Server, Proxy Server (HTTP and SOCKS5), and VPN Manager. This addresses the two biggest limits of ssh -R:
- HTTP/s tunnels point at a local IP and port and are served at a public HTTPS address. The Process Type controls the hostname: Random Sub Domain, Custom Sub Domain, or Custom Domain. All three serve the same content; the difference is only the address. Custom domains involve DNS configuration, so follow the current documentation for those exact steps.
- TCP tunnels give a public host and port for raw TCP services, matching the one-port-per-tunnel model described earlier.
- UDP and combined UDP/TCP tunnels carry protocols that a standard SSH forward cannot.
- TLS tunnels point at a local IP and port as well. For exactly how certificates and termination are handled for this type, check the current tunnel documentation rather than assuming behavior.
- File Server publishes a local folder path instead of an IP and port, and has Default (browser file manager), SFTP, and WebDAV sub-types. For File Server, TLS is terminated at the tunnel edge.
- Proxy Server types make the connected device the proxy exit node rather than forwarding to a local service.
HTTP, TCP, UDP, TLS, and File Server tunnels publish specific services; they are not a VPN. If you need a private mesh network between devices with firewall rules, that is what our VPN Manager private mesh network is for. Also check which tunnel types and options are available on your plan before planning around them.
Explicit Start, Stop, and Delete
This is the lifecycle separation described in the tradeoffs section. Creating a Localtonet tunnel does not mean it is running. You press Start to bring it up, Stop to take it offline, and Delete to remove the definition. The tunnel is reachable only while the selected client device is connected and the tunnel is running. If the device is powered off or the client is not connected, the public address does not serve traffic, which mirrors the SSH rule that the endpoint only works while the outbound connection lives.
Dashboard and REST API management
Tunnels are managed from a single dashboard or through our REST API, which gives you the inventory that ssh -R lacks: you can see what exists and what it points at without logging into the machine. If you work with AI coding assistants, the Localtonet MCP Server lets assistants such as Claude Code create, start, and stop tunnels directly.
Creating and starting a tunnel
Our general workflow for any tunnel follows the same sequence:
Install and run the Localtonet client
Install the client on the device that can reach the local service, which may be the same machine or another machine on the same network.
Authenticate the device with its token
Use the device's auth token so our platform knows which device will run the tunnel. Keep the token private.
Select a relay server
Choose an available relay server or region from the options shown in the dashboard.
Create the tunnel configuration
Pick the tunnel type (HTTP, TCP, UDP, TLS, combined UDP/TCP, File Server, proxy, or VPN) and enter its target, such as a local IP and port or a folder path.
Start the tunnel and use its public address
Press Start, then use the assigned public URL or host and port to reach the service.
Stop or delete it when finished
Stop the tunnel to take it offline, or delete it when you no longer need the configuration.
For HTTP specifics, see the Localtonet HTTP tunnel documentation. For folders, the File Server documentation covers selecting the Process Type, AuthToken, server, and local folder path before pressing Start. The full set of tunnel guides is in our documentation.
Monitoring with Token and Tunnel webhooks
In the SSH model, finding out that a tunnel dropped usually means a visitor reporting an error. With Localtonet, platform-wide webhooks fire when a token or tunnel in a selected Token Group changes to Connected or Disconnected. We POST a WebHookRequest JSON body to your endpoint with these fields:
| Field | Meaning |
|---|---|
Id |
The tunnel id or the authtoken the event refers to |
ActionDate |
When the status change happened |
Type |
"Token" or "Tunnel" |
Status |
"Connected" or "Disconnected" |
A receiver can alert on Disconnected events for production tunnels, record uptime, or trigger a check on the device. Because Id can contain an authtoken for Token events, treat webhook payloads and logs as sensitive and do not post them to public channels. Configuration details are in the Localtonet webhook documentation. These platform webhooks are separate from File Server's own file-event webhooks (upload, delete, rename, move), which support HMAC signing and serve a different purpose.
Scoping exposure and authenticating the local service
A tunnel, of any architecture, takes something that was only reachable on your machine and makes it reachable by the whole internet. It does not add authentication to your application, and it does not bypass or replace your security controls. Treat every exposed endpoint as public.
Random hostnames are not secrets. Hostnames can appear in certificate transparency logs, browser history, referrer headers, chat previews, and scanner results. Never expose an admin panel, database, or development server with debug features enabled unless it requires authentication of its own.
For SSH reverse tunnels on your own server
- Use a dedicated, restricted account. Do not reuse your admin key for tunnels.
- Restrict what the key can do. In
authorized_keys, options such asrestrictdisable shells, agent forwarding, and X11 by default, and in OpenSSH 7.8 and laterpermitlisten="..."limits which remote ports that key may bind. - Keep
GatewayPortsat its default unless you truly need public binding, and preferclientspecifiedwithPermitListenover a blanketyes. - Put a reverse proxy in front of loopback-bound forwards on the server if you want TLS, authentication, or rate limiting at the edge.
A scoped server-side configuration for a tunnel-only user might look like this:
Match User tunnel
AllowTcpForwarding remote
GatewayPorts clientspecified
PermitListen 0.0.0.0:8080
X11Forwarding no
PermitTTY no
ClientAliveInterval 30
ClientAliveCountMax 3
Test changes with sshd -t before reloading the service, and keep an existing session open while you do so you cannot lock yourself out. Also remember to open the forwarded port in the server's firewall or cloud security group; sshd binding the port does not make it reachable if the host firewall drops traffic to it.
For agent-based tunnels with Localtonet
- Protect the device token as you would a private key, and keep it out of repositories and shared screenshots.
- Expose the narrowest target. Point a tunnel at the single port of the single service you need, not at a broad internal gateway.
- Authenticate the local service. Add login, API keys, or signature verification to the application itself. For webhook receivers, verify the sender's signature.
- Use the lifecycle. Stop tunnels you are not actively using and delete ones you no longer need, so the inventory reflects what is actually exposed.
- For File Server, use the permission flags, per-path overrides, and share link expiry or passwords that the Default file manager provides.
- Monitor status changes with Token and Tunnel webhooks so unexpected Connected events on a sensitive tunnel are visible.
Troubleshooting: SSH tunnels that drop and endpoints that do not respond
Most tunnel failures fall into a small set of patterns. The SSH ones are worth knowing even if you use an agent, because the underlying network behavior is the same.
"The tunnel works, then stops after idle periods"
Classic NAT or firewall idle timeout. Add ServerAliveInterval (for example 30 seconds) and keep ServerAliveCountMax at a small value. If the server is yours, also set ClientAliveInterval. Run with -v to see keepalive messages and the reason for disconnection.
"Warning: remote port forwarding failed for listen port"
The server refused the bind. Common causes: another process or a stale SSH session already holds the port, the port is below 1024 and the user is not privileged, AllowTcpForwarding forbids remote forwards, or PermitListen does not allow that port. Check with ss -tlnp on the server, enable ClientAliveInterval to reap stale sessions, and use ExitOnForwardFailure=yes on the client so a failed bind does not leave a useless connected session.
"The port is bound, but nobody outside can connect"
On a stock server this is almost always GatewayPorts no, which binds to loopback. Check whether the listener shows 127.0.0.1:8080 or 0.0.0.0:8080. If it is public, check the server's host firewall and any cloud security group.
"Connection reaches the server, then fails with connect refused"
The SSH client received the channel but could not reach the destination. Confirm the local service is running and listening on the host and port in your -R spec, and remember that the destination is resolved on the client. An app bound only to IPv6 ::1 while the spec says 127.0.0.1, or the reverse, is a frequent mismatch. Test locally first with curl http://localhost:3000.
"My UDP service does not work through the SSH tunnel"
Expected: SSH port forwarding carries TCP only. Use a tunnel architecture with native UDP support, such as a Localtonet UDP or combined UDP/TCP tunnel, rather than layering shims.
Agent-based tunnel checklist
- Is the tunnel started? A created tunnel is not running until you press Start.
- Is the right device connected? The tunnel only works while the selected client device is connected. Check the device's status in the dashboard or watch for Token Disconnected webhooks.
- Is the local target reachable from the client device? Verify the IP and port with a local request on that device. If the target is another LAN machine, test from the client device, not from your laptop.
- Is the tunnel type correct? A UDP service behind a TCP tunnel, or a non-HTTP protocol behind an HTTP tunnel, will fail even though the tunnel shows as running.
- Custom domain not resolving? Recheck DNS against the current Localtonet documentation for custom domains.
Frequently asked questions
What does ssh -R actually do?
It asks the SSH server to listen on a port and forward every connection it receives back through your existing SSH session to a host and port reachable from your client. In -R 8080:localhost:3000, the server listens on 8080 and your client connects to its own localhost:3000 for each incoming connection. On a stock OpenSSH server the listener binds to loopback unless GatewayPorts allows otherwise.
Why does my SSH reverse tunnel keep disconnecting?
Usually a NAT or firewall drops the idle connection's mapping, and neither end notices until data is sent. Set ServerAliveInterval (it is disabled by default) so the client sends encrypted keepalives and detects dead paths after about ServerAliveInterval × ServerAliveCountMax seconds. Because ssh does not reconnect on its own, also run it under a supervisor such as systemd or autossh.
Can I tunnel UDP over SSH?
Not with standard port forwarding, which carries TCP only. Workarounds include converting UDP to TCP with tools like socat, or using SSH tun devices with -w, which needs PermitTunnel, typically root, and manual routing. Both add latency and complexity. A tunnel platform with native UDP tunnel types, such as Localtonet's UDP and combined UDP/TCP tunnels, avoids these workarounds.
Is an SSH tunnel end-to-end encrypted for visitors?
SSH encrypts the segment between your client and the SSH server. The visitor's connection to the forwarded port is separate: it is plain TCP unless your service speaks TLS, or unless a hosted service terminates HTTPS at its edge, in which case the edge sees decrypted traffic. The same question applies to any tunnel: identify where the visitor's TLS session ends.
When should I use ssh -R instead of an agent-based tunnel?
SSH is a good fit for short-lived TCP or HTTP exposure from a machine that already has OpenSSH, especially if you control a server and are comfortable configuring sshd. An agent-based tunnel fits better when the tunnel must stay up, needs UDP or other tunnel types, spans several devices, or needs an inventory, an API, and status notifications.
Does creating a Localtonet tunnel make my service public immediately?
No. Creating a tunnel defines it; you must press Start to run it. It then serves traffic only while the selected client device is connected and the tunnel is running. Stop takes it offline and Delete removes it.
How do I get notified when a Localtonet tunnel goes down?
Configure platform webhooks for a Token Group. When a token or tunnel in that group changes to Connected or Disconnected, we POST a WebHookRequest JSON body with Id, ActionDate, Type (Token or Tunnel), and Status. Your receiver can alert on Disconnected events.
Is a Localtonet HTTP or TCP tunnel a VPN?
No. HTTP, TCP, UDP, TLS, and File Server tunnels publish specific services at public addresses. Our VPN Manager is the separate feature that provides a private mesh network with firewall rules between devices.
Run tunnels with an explicit lifecycle
Skip the keepalive tuning, supervisor scripts, and TCP-only limits. Install the Localtonet client, authenticate your device, choose a relay server, and start an HTTP, TCP, UDP, or TLS tunnel you can stop, delete, and monitor from one dashboard or API.
Get Started Free →Localtonet is a secure multi-protocol tunneling and proxy platform designed to expose localhost, devices, private services, and AI agents to the public internet supporting HTTP/HTTPS tunnels, TCP/UDP forwarding, mobile proxy infrastructure, file server publishing, latency-optimized game connectivity, and developer-ready AI agent endpoint exposure from a single unified control plane.