Introduction

Imagine a use-case where you’re already testing a service using ngrok and you want to spin up a different service and test that service on a different port. Tricky situation, right? That’s where ngrok’s power to run multiple tunnels simultaneously comes into the picture.

How?

ngrok Agent configuration file: The ngrok agent supports an optional, YAML configuration file which provides you with the power to run multiple tunnels simultaneously as well as to tweak some of its more advanced settings.

Wondering where the Agent Configuration file is?

  1. So, the default location of the ngrok agent configuration depends on your operating system. So, you can simply write:
ngrok config check

This will validate and print the location of the configuration file. For the main operating systems, their default file locations are:

Linux: ~/.config/ngrok/ngrok.yml

MacOS (Darwin): ~/Library/Application Support/ngrok/ngrok.yml

Windows: "%HOMEPATH%\AppData\Local\ngrok\ngrok.yml"

  1. Open the config file and replace the file with the following contents:
version: "2"
authtoken: 2aC32ipSr9Q9jGkNRAlgq8MnKtD_3DtHjjhsgdgsnTE6feu   # add your auth token you got from ngrok dashboard
tunnels:
  default-server:
    proto: http
    addr: 8000
    domain: supposedly-choice-monkey.ngrok-free.app # insert your static domain that you claimed from ngrok dashboard
  second-server:
    proto: http
    addr: 3000
  1. After you’ve saved the file. You can try spinning multiple tunnels with a single command:
 ngrok start --all
  1. You should be able to see something like:
Screenshot 2024-08-13 at 3 00 29 PM

Voila! You can clearly see two tunnels running simultaneously. If you want to tweak around a bit. You can refer to the official documentation 1

A kind of an Easter Egg 😛

Rather than using an automatically generated uuid like url ( https://b341-122-161-241-254.ngrok-free.app) everytime you spin up ngrok, you can actually claim your own static domain name on ngrok dashboard.

  1. Go to your ngrok dashboard 2

    Screenshot 2024-08-13 at 3 06 32 PM
  2. Scroll a bit down to Deploy your app online section:

    Screenshot 2024-08-13 at 3 19 58 PM
  3. Click on Static Domain to claim your free static domain. and you’re done. You can spin up the ngrok with the static domain (supposedly-choice-monkey.ngrok-free.app in my case) via the following command:

ngrok http --domain=supposedly-choice-monkey.ngrok-free.app 3000

Footnotes

  1. Ngrok Agent Config ↩

  2. Ngrok dashboard ↩