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!
Requirements
- An Android device
- Termux installed (download here)
- A stable internet connection
- A free ngrok account
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:
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.
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.
Here, you will find your unique authtoken under the "Your Authtoken" section.
Copy this token to your clipboard.
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
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.
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:
Access your server using the Forwarding URL.
Troubleshooting
Common Issues
1. Session Status reconnecting
If you encounter this error:
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
Check out our Termux Guide Collection for more tutorials. Have questions or tips? Share them in the comments below!