How to Install NGROK in Termux

August 5, 2023 10 min read Sandeep Tech Team

NGROK in Action

Watch this demonstration of NGROK running in Termux. The video shows the complete process from installation to creating secure tunnels. This visual guide will help you understand how to expose your local servers to the internet directly from your Android device.

NGROK is a powerful reverse proxy that creates secure tunnels to localhost, allowing you to expose local servers to the internet. This comprehensive guide will walk you through installing and using NGROK in Termux on your Android device for development, testing, and sharing purposes.

Secure
HTTPS Tunnels
Free
Plan Available
No Root
Required
Cross-Platform
Support

What is NGROK?

NGROK is a reverse proxy that creates a secure tunnel from a public endpoint to a locally running web service. It captures and analyzes all traffic over the tunnel for inspection and replay. NGROK allows you to expose a web server running on your local machine to the internet, which is particularly useful for:

  • Testing webhooks from local development
  • Demoing websites without deploying
  • Building webhook consumers on your dev machine
  • Testing mobile apps against a locally running backend
  • Securely exposing internal services to the internet

Educational Purpose Only

NGROK should only be used for legitimate purposes such as development, testing, and educational activities. Always ensure you have proper authorization before exposing any services to the internet.

Why Use NGROK in Termux?

Running NGROK in Termux offers several advantages:

  • Portability - Create secure tunnels from anywhere using your Android device
  • No Root Required - Works on non-rooted Android devices
  • Development On-the-Go - Test webhooks and APIs directly from your mobile device
  • Cost-Effective - Free plan available with basic features
  • Educational - Learn about networking and tunneling concepts on the go
  • Emergency Access - Quickly expose local services when you don't have access to a computer

Prerequisites

Before installing NGROK in Termux, make sure you have the following:

  • Termux installed on your Android device (from F-Droid)
  • Stable internet connection
  • Basic knowledge of Linux commands
  • Approximately 50MB of free storage space

Termux Updates

Ensure your Termux installation is up to date. Run pkg update && pkg upgrade before proceeding with the NGROK installation.

Installation Guide

Installing NGROK in Termux is a straightforward process. Follow these steps:

Step 1: Update Termux Packages

# Update and upgrade Termux packages pkg update && pkg upgrade -y

Step 2: Install Required Dependencies

# Install required packages pkg install wget curl unzip -y

Step 3: Download NGROK

# Download the latest NGROK binary for ARM64 (most Android devices) wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-arm64.tgz

Architecture Compatibility

If you're using a 32-bit device, use `linux-arm` instead of `linux-arm64`. Check your device architecture with uname -m and download the corresponding version from the NGROK website if needed.

Step 4: Extract NGROK

# Extract the NGROK archive tar -xvzf ngrok-v3-stable-linux-arm64.tgz

Step 5: Move NGROK to PATH

# Make NGROK executable and move to a directory in PATH chmod +x ngrok mv ngrok $PREFIX/bin/ # Verify the installation ngrok version

Getting Started with NGROK

Now that NGROK is installed, you need to connect your NGROK agent with your account.

Step 1: Get Your Authtoken

Sign up for a free account on the NGROK website. Once logged in, go to the "Your Authtoken" section on your dashboard and copy the token.

Step 2: Add Authtoken to NGROK

# Replace YOUR_AUTHTOKEN with the token from your dashboard ngrok config add-authtoken YOUR_AUTHTOKEN

Step 3: Start a Local Server and Tunnel It

First, start a simple web server in one Termux session.

# Create a simple HTML file echo "

Hello from Termux!

" > index.html # Start a simple HTTP server on port 8080 python -m http.server 8080

In a **new Termux session**, create the NGROK tunnel:

# Create an HTTP tunnel to port 8080 ngrok http 8080

NGROK will display information about the tunnel, including the public URL, which you can now access from any browser.

ngrok
$ ngrok http 8080
Session Status                online
Account                       Your Name (Plan: Free)
Version                       3.x.x
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    https://random-string.ngrok-free.app -> http://localhost:8080

Connections                   ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00
                            

Basic Usage and Commands

HTTP Tunnels

# Create an HTTP tunnel with a custom subdomain (requires paid plan) ngrok http --domain=my-custom.ngrok-free.app 80 # Create an HTTP tunnel with basic authentication ngrok http --basic-auth="user:password" 8080

TCP Tunnels (e.g., for SSH)

# Create a TCP tunnel to the SSH port ngrok tcp 8022

Advanced Features

NGROK offers several advanced features for more sophisticated use cases:

Webhook Inspection

NGROK provides a web interface for inspecting traffic. When you start a tunnel, NGROK also starts a local web interface, usually on `http://127.0.0.1:4040`. You can access this in a browser to inspect all HTTP requests made to your tunnel.

Configuration File

You can run multiple tunnels simultaneously using a configuration file:

# Create and edit the configuration file nano ~/.config/ngrok/ngrok.yml

Add your tunnels to the file:

version: "2" authtoken: YOUR_AUTHTOKEN tunnels: webapp: proto: http addr: 8080 ssh: proto: tcp addr: 8022

Then start all tunnels with one command:

ngrok start --all

Troubleshooting Common Issues

Connection Timeouts

Connection Timeout

If you're experiencing timeouts, try switching to a different NGROK region. Use the `--region` flag (e.g., `ngrok http 8080 --region eu`).

"Command Not Found"

NGROK Command Not Found

If you get a "command not found" error, ensure you moved the `ngrok` executable to `$PREFIX/bin/` and that the directory is in your shell's PATH.

Security Considerations

While NGROK is powerful, use it responsibly:

  • Authentication - Use HTTP basic authentication (`--basic-auth`) for sensitive services.
  • HTTPS - Prefer the HTTPS URL provided by NGROK for encrypted traffic.
  • Monitoring - Regularly check the NGROK web interface (`http://127.0.0.1:4040`) for suspicious activity.
  • Temporary Use - Only keep tunnels open when necessary. Close them when you're done.

Security Warning

Exposing local services to the internet carries risks. Always ensure the service you are exposing is secure and only expose what is absolutely necessary.

Interactive Demo

Try NGROK Commands

Experience the power of NGROK with our interactive command simulator. Try running some basic commands to see how they work.

ngrok
$ Type a command or click a button below

Command Reference

NGROK Commands

Command Description Example
ngrok http Create an HTTP tunnel ngrok http 8080
ngrok tcp Create a TCP tunnel ngrok tcp 22
ngrok tls Create a TLS tunnel ngrok tls 443
ngrok version Show NGROK version ngrok version
ngrok config add-authtoken Save your authtoken ngrok config add-authtoken <token>

NGROK in Termux brings the power of secure tunneling to your Android device. Whether you're a developer, a student, or just someone interested in networking, NGROK provides a simple yet powerful solution for exposing local services to the internet. Remember to always use these tools responsibly and with proper security measures in place.

Back to Blogs

Leave a Comment

Michael Johnson
August 6, 2023
This guide is amazing! I've been looking for a way to test webhooks on my Android device without having to carry my laptop everywhere. NGROK in Termux is a game-changer for mobile development.
Sarah Williams
August 7, 2023
Thank you for this detailed tutorial. I was able to set up a tunnel for my local web server in minutes. The troubleshooting section was particularly helpful when I encountered the port already in use error.