Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aaqibb13/2f57ca46974a80178d50dd1f7ef920ff to your computer and use it in GitHub Desktop.

Select an option

Save aaqibb13/2f57ca46974a80178d50dd1f7ef920ff to your computer and use it in GitHub Desktop.
Opening multiple tunnels with ngrok simultaneously

WHAT IS THIS GIST ABOUT?

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
    
  2. 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 kindda 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
  1. Scroll a bit down to Deploy your app online section
Screenshot 2024-08-13 at 3 19 58 PM
  1. 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
    

References:

Footnotes

  1. Ngrok Agent Config

  2. Ngrok dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment