Skip to main content
This guide shows you how to expose your MQTT server to the internet using ngrok. It covers setting up a local MQTT server, creating an ngrok TCP tunnel, and connecting to it using MQTT Explorer.

What you’ll need

1

Start an MQTT server

This guide uses Eclipse Mosquitto as the MQTT server. Follow the Mosquitto download and install instructions for your operating system, then start the server:
Mosquitto listens on port 1883 by default and starts in local-only mode, so connections are only possible from the same machine until you expose it. For listener and authentication options, see the Mosquitto documentation.
2

Launch ngrok

With your MQTT server running on localhost, put it online with an ngrok TCP endpoint.If you haven’t already, add your authtoken from the ngrok dashboard:
Start a TCP endpoint that forwards to Mosquitto’s port:
ngrok displays a tcp:// forwarding address where your server is exposed to the internet. Copy this address for use with MQTT Explorer.
3

Connect with MQTT Explorer

Open MQTT Explorer and click the plus sign to create a new MQTT connection. Enter the TCP address from the last step and click Connect.You’ll see a few new lines in your MQTT server logs:
MQTT Explorer is now connected to your server over the public internet. To get messages from the client, subscribe to a topic. In your terminal, open a tab and enter:
Back in MQTT Explorer, publish a message to example/topic.You’ll see the message in the terminal tab where you subscribed to the topic: