Configure Secure Access to Remote IoT Devices
ngrok is a universal gateway, which means it allows you to create secure ingress to any app, IoT device, or service without networking expertise.
This guide will walk you through an example scenario using ngrok to set up a secure, controlled remote access solution for IoT devices. The solution will enable you to grant trusted parties access to critical systems without exposing those systems to the public internet or relying on complex VPN setups.
What you'll need
- An ngrok account. If you don't have one, sign up.
- An ngrok agent configured on your local machine. See the getting started guide for instructions on how to install the ngrok agent.
- An ngrok API Key. You'll need an account first.
Example scenario
Consider a situation where a network of smart factories is coming online, each with IoT-connected machines, telemetry sensors, and a real-time monitoring dashboard.
In this scenario, each factory's network blocks inbound connections, but the technicians need temporary access to the dashboard. The telemetry API and sensor database must remain permanently accessible from the company's cloud, and access to the dashboard must be authenticated via Microsoft Entra ID.
Each factory would only need one ngrok agent running.
Why only one ngrok agent per factory?
Traditionally, you might assume that every device inside the factory needs its own ngrok agent, but this isn't necessary. A single ngrok agent is installed on a network-accessible machine inside the factory, and it:
- Acts as a central gateway (jumpbox) that can reach any machine on the local network, eliminating the need for multiple agents.
- Creates Internal Endpoints so that each API, database, and dashboard is securely exposed inside ngrok, never publicly visible.
- Uses Cloud Endpoints for controlled access, where external cloud apps can access only what they need, and the dashboard is only started when requested.
- Runs as a background service configured to automatically start on boot, restart after crashes, and log events.
- Dynamically manages tunnels, as The agent API can start and stop tunnels as needed.
This setup minimizes security risks, simplifies deployment, and ensures continuous uptime for mission-critical services.
Understanding cloud and internal endpoints
An internal endpoint enables a service inside the factory network to be reachable within ngrok, without being publicly exposed. They can:
- Only receive traffic from cloud endpoints or internal services that explicitly route traffic to them.
- Not be accessed directly from the internet.
- Be used for telemetry APIs, databases, and dashboards.
Here's an example: The factory's telemetry API runs on a local server (192.168.1.100:8080). Instead of exposing it publicly, you can create an internal endpoint:
Loading…
Now this API is only accessible inside ngrok's private network.
A cloud endpoint is a permanent, externally accessible entry point into the factory network that's also:
- Managed centrally via the ngrok API or dashboard.
- Always on, not tied to the lifecycle of the agent.
- Does not forward traffic to the agent by default—it must be configured to route traffic to internal endpoints.
- Used for exposing services to external cloud apps securely.
For example, the factory's telemetry API is accessible via https://factory.example.com/api, but instead of exposing the API directly, a cloud endpoint forwards traffic to its internal endpoint:
Loading…
Define internal endpoints in ngrok.yaml
After installing the ngrok agent, define all required internal endpoints inside the ngrok configuration file,
which is at /etc/ngrok.yml
on Linux or C:\ngrok\ngrok.yml
on Windows.
Loading…
Install ngrok as a background service
Now, install and start the service
Loading…
In most cases, installing ngrok as a service requires administrator privileges.
This will start all tunnels defined in the configuration file, ensure ngrok runs persistently in the background, and integrate with native OS service tooling.
Reserve a TCP address for your TCP-based cloud endpoint
When you reserve a TCP Address, you can create a TCP cloud endpoint that binds to that domain. Reserved TCP addresses are available on ngrok's pay-as-you-go plan.
Loading…
Reserve a custom wildcard domain
Creating a custom wildcard domain will allow you to create endpoints and receive traffic on any subdomain of your domain. Wildcard domains are available on ngrok pay-as-you-go-plans when you verify with support. It can be helpful to create a separate subdomain for each factory you wish to connect to.
Loading…