Knowledge

Exposing localhost to the internet with a reverse tunnel: how it works, when to use it and how to stay safe

Updated 2026-11-30 · Present

  • localhost only points back at the machine running the app, so nobody else can open it; a reverse tunnel gives you a public HTTPS address that forwards requests to a port on your machine.
  • Use it for quick demos, testing a page on a phone, or receiving webhooks; it does not replace a proper deployment.
  • The examples use Tunelo: install, sign in, tunelo http 3000, lock it with Basic Auth and shut it down when done.

Why others cannot open your localhost

localhost is the name of the loopback address (127.0.0.1 for IPv4, ::1 for IPv6): packets sent there never leave the machine. When a dev server says "running at http://localhost:3000", only a browser on that same machine can open it. A colleague typing the same address makes their browser look for port 3000 on their own machine.

Even if the app listens on every network interface, your machine usually sits behind your router's NAT and a firewall, has no public IP address and accepts no incoming connections from the internet. Opening a port on the router is a hassle and exposes the whole machine.

How a reverse tunnel works

The way around it is to flip the direction of the connection:

  1. A program on your machine opens an outbound connection to a tunnel server. Outbound connections almost always get through NAT and firewalls.
  2. The tunnel server hands out a public name, usually a subdomain under a wildcard domain that already has a TLS certificate, for example https://your-name.tunnel.example.
  3. Viewers call that address; the tunnel server terminates HTTPS and passes the request through the open connection back to the program on your machine.
  4. That program sends the request to localhost:<port> and returns the response the same way.

In essence the tunnel server does a reverse proxy's job, except that the "upstream" sits at the far end of a connection the client opened. Reverse proxying and the X-Forwarded-* headers are explained in nginx as a reverse proxy for an app: proxy_pass, X-Forwarded-* headers and timeouts; why the browser trusts the public address's certificate is covered in TLS handshakes and certificate chains: how a client comes to trust a server.

The idea matches SSH remote port forwarding (ssh -R 8080:localhost:3000 user@server), but with SSH you need your own server, your own domain and certificate, and by default sshd only opens that port on the server's loopback unless GatewayPorts is enabled. A tunnel service packages those parts for you.

When to use it

A tunnel is a temporary bridge between your machine and the viewer. A site that serves users long term still needs a proper deployment with its own domain, TLS and monitoring.

Hands-on with Tunelo

Tunelo is an HTTPS tunnel service that uses a Hoandat account. The tunelo program installs with one command:

# macOS and Linux (x86_64, arm64)
curl -fsSL https://chat.hoandat.com/agent/install.sh | sh
# Windows PowerShell
irm https://chat.hoandat.com/agent/install.ps1 | iex

The script downloads a pinned release, checks its SHA-256, installs tunelo and runs tunelo login: a browser opens a consent page, and once you approve, the machine is signed in with a background service running. Installing over SSH or on a machine without a browser, open the link printed in the terminal on another device and enter the code shown. tunelo status shows the account and the tunnels that are running.

Open a tunnel to an app running on port 3000:

tunelo http 3000

The command prints an address of the form https://<name>.tunnel.hoandat.com. A few common variants (see them all with tunelo http --help):

tunelo http 3000 -s demo-shop        # ask for a fixed subdomain
tunelo http 3000 -a guest:password   # make viewers enter Basic Auth
tunelo tcp 7000                      # a TCP service instead of HTTP

While the tunnel runs, the request inspector at http://127.0.0.1:4040 lists every request that passes through, which is handy when debugging webhooks. Press Ctrl+C to stop; for a tunnel running in another window use tunelo kill <subdomain> or tunelo kill all.

Before sending the link, open it yourself on a phone using mobile data (not the same Wi-Fi) to be sure outsiders can reach it.

Sharing safely

While the tunnel runs, anyone with the URL can reach the app on your machine.