Visit Website

How to Install and Use ngrok in Termux: A Complete Guide

Learn how to install and use Ngrok in Termux, including creating tunnels and adding your authtoken for secure access. Simple, step-by-step guide.

Have you ever wanted to share your local projects with others or test webhooks directly on your Android device? ngrok makes it easy to expose your local server to the internet securely. In this guide, we’ll show you how to install and use ngrok in Termux step by step. By the end, you’ll be able to create secure tunnels and share your projects in no time!

How to install ngrok in Termux" thumbnail featuring a green and black gradient background, the ngrok terminal output interface on the right, and the "Terminal Tools" logo on the bottom left

Requirements

Step-by-Step Guide

1. Install Termux

If you don’t have Termux installed, download it from the official source. Once installed, open Termux and update it with the following command:

pkg update && pkg upgrade -y

2. Install Required Packages

ngrok needs wget and unzip to download and extract its files. Install them by running:

pkg install wget unzip -y

3. Download ngrok

Download the ngrok binary for Linux ARM using this command:

wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-stable-linux-arm.zip

4. Extract ngrok

Unzip the downloaded file using:

unzip ngrok-stable-linux-arm.zip

Setting Up Ngrok in Termux

After installing Ngrok, you’ll need to set it up by adding your Ngrok authtoken. The authtoken is a unique key that links your Ngrok installation to your account, allowing you to use Ngrok’s features.

1. Create a Ngrok Account

To get started, visit the official Ngrok website:

https://ngrok.com

Click the "Sign Up for Free" button and create an account by entering your name, email, and password. After signing up, log in to your new account.

Screenshot of the ngrok website homepage showing the headline 'All-in-one API gateway, Kubernetes Ingress, DDoS protection, firewall, and global load balancing as a service,' with a 'Sign up for free' button highlighted by an arrow.

2. Retrieve Your Ngrok Authtoken

Once you’re logged in, navigate to the dashboard by clicking on the menu (three lines) at the top left of the page.

Screenshot of the ngrok dashboard homepage with an orange arrow pointing to the hamburger menu icon on the top left.

Here, you will find your unique authtoken under the "Your Authtoken" section.

Screenshot of the ngrok dashboard showing the dropdown menu after clicking the hamburger icon, with a yellow arrow highlighting the "Setup & Installation" option under "Getting Started.

Copy this token to your clipboard.

Screenshot of the "Your Auth Token" page on the ngrok dashboard, with an orange arrow pointing to the "Copy" button next to the Auth Token.

3. Add the Authtoken in Termux

Now, return to Termux and enter the following command to set your Ngrok authtoken:

./ngrok authtoken PASTE_YOUR_AUTH_TOKEN_HERE
Info! Replace PASTE_YOUR_AUTH_TOKEN_HERE with the actual authtoken you copied from the Ngrok dashboard.

After successfully adding the authtoken, Ngrok is fully set up and ready to use in Termux.

Using Ngrok in Termux

With Ngrok installed and set up, you can now start creating secure tunnels to expose your local servers or applications to the internet. Here's how to use Ngrok in Termux:

1. Start a Ngrok Tunnel

To create a tunnel and make your local server accessible over the internet, run the following command in Termux:

./ngrok http 8080

This command starts an HTTP tunnel on port 8080. You can replace 8080 with any port number that your local server is running on. Ngrok will generate a temporary public URL that you can share with others to access your server.

Warning! Always turn on your mobile hotspot before creating a Ngrok tunnel. This ensures that your device remains connected to the internet and can maintain the tunnel.

With your tunnel running, you can now access your local server from anywhere using the generated URL. This is especially useful for testing webhooks, sharing your work with clients, or accessing your home server while on the go.

You will see output like this:

Screenshot of ngrok running in the Termux terminal. It displays session details such as account name, version (3.19.0), region (India), latency (38ms), and the forwarding URL (https://78f7-137-115-0-10.ngrok-free.app -> http://localhost:8080). The terminal also shows the web interface link and no active connections.

Access your server using the Forwarding URL.

Troubleshooting

Common Issues

1. Session Status reconnecting

If you encounter this error:

Error! Session Status reconnecting (failed to dial ngrok server with address "connect.ngrok-agent.com:443": dial tcp: lookup connect.ngrok-agent.com on [::1]:53: read udp [::1]:43475->[::1]:53: read: connection refused)

Solution: Enable your mobile hotspot to ensure active internet connectivity, then rerun the command:

./ngrok http 8080

This will resolve the issue and establish the tunnel successfully.

2. DNS Resolution Errors

If you see DNS errors, update your Termux DNS settings:


nano /data/data/com.termux/files/usr/etc/resolv.conf  
# Add the following lines:  
nameserver 8.8.8.8  
nameserver 8.8.4.4
3. IPv6 Connectivity Issues

If ngrok tries to use IPv6 and fails, disable IPv6 in Termux:


nano /data/data/com.termux/files/usr/etc/sysctl.conf  
# Add the following lines:  
net.ipv6.conf.all.disable_ipv6 = 1  
net.ipv6.conf.default.disable_ipv6 = 1  

# Apply the changes:
sysctl -p

Use Cases

ngrok is a versatile tool with many applications, including:

  • Testing webhooks with services like GitHub or Stripe
  • Sharing local projects with clients or team members
  • Debugging APIs running on your local machine
Success! Congratulations! You’ve successfully installed and configured ngrok in Termux. Now, you can securely share your local server with the internet in just a few commands. Don’t forget to explore ngrok’s advanced features for even more functionality.

Check out our Termux Guide Collection for more tutorials. Have questions or tips? Share them in the comments below!

Post a Comment

Visit Website
Visit Website