๐Ÿš‡

How Does ngrok Work?

Exposing Local Servers to the Internet via Reverse Tunnel

The core of ngrok is the "reverse tunnel". The ngrok agent on your PC first establishes an outbound TCP/TLS connection to ngrok cloud servers. ngrok cloud assigns a public URL (e.g., abc123.ngrok.io) and forwards incoming HTTP requests through that tunnel to your local server. This is why you can expose local services to the internet without port forwarding or firewall configuration.

Architecture Diagram

๐ŸŒ
External Client
Browser / Webhook
โ‘ฃ HTTP request
โ˜๏ธ
ngrok Cloud
abc123.ngrok.io
Public URL assigned
โ‘ค tunnel forwarding
โ‘ก outbound TLS
๐Ÿš‡ ๐Ÿ’ป
My PC (behind firewall)
ngrok agent localhost:3000
Key point: ngrok agent opens an <strong>outbound connection first</strong>, so no firewall/NAT configuration needed
Flow Description
  1. ngrok http 3000 executed
  2. Agent establishes outbound TLS tunnel to ngrok cloud
  3. Public URL (abc123.ngrok.io) assigned
  4. External traffic arrives at public URL
  5. ngrok cloud forwards to local via tunnel
  6. Local response returns to external via tunnel

How It Works

1

ngrok agent runs locally (ngrok http 3000)

2

Agent establishes outbound TLS connection to ngrok cloud (reverse tunnel)

3

ngrok cloud assigns public URL (abc123.ngrok.io)

4

External client sends HTTP request to public URL

5

ngrok cloud forwards request to local server through tunnel

6

Local server response returns to external client through tunnel

Pros

  • Works behind firewalls/NAT
  • Instant public URL generation
  • Automatic HTTPS support
  • No port forwarding needed

Cons

  • Dependency on ngrok cloud (single point of failure)
  • Free plan limitations (session time, bandwidth)
  • Additional latency (via cloud)
  • Not suitable for production use

Use Cases

Webhook local development/debugging Testing local API from mobile apps Demos/presentations Remote access to IoT devices