If you are working on a local project in Termux, you may need to access it from the internet. This could be for testing webhooks, sharing a demo, or checking how your app behaves outside your phone. This is where ngrok helps.
ngrok lets you expose a local server to the internet using a secure tunnel. Instead of setting up port forwarding or router rules, it gives you a public URL that points directly to your local service.
In this guide, I will show you how to install and use ngrok in Termux step by step. By the end, you will know how to start a tunnel and share your local projects safely from your Android device.
Requirements
Before we start, make sure you have the following ready. These are basic things and easy to set up.
- Android device: Any modern Android phone should work.
-
Termux installed: Make sure you are using the correct and
updated Termux version.
If you need help installing and setting it up properly, follow this guide: How to Install and Set Up Termux on Android Device . - Stable internet connection: ngrok needs an active internet connection to create tunnels.
- Free ngrok account: You need an ngrok account to get an authtoken. This token connects ngrok on your phone to your account.
Once you have these ready, you can move on to installing and setting up ngrok in Termux.
Installing ngrok in Termux
Without wasting time, below are the steps to install ngrok in Termux.
1. Update Termux Packages
Before installing ngrok, make sure your Termux packages are up to date. This helps prevent common installation errors.
Run the command below:
pkg update && pkg upgrade -y
This updates the package list and upgrades any existing packages.
2. Install Required Packages
ngrok is downloaded as a zip file, so we need a few tools to handle that. Install them using:
pkg install wget unzip -y
wgetis used to download files from the internetunzipis used to extract zip files
3. Download ngrok
Now download the ngrok binary for Android (Linux ARM architecture) using the command below:
wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-stable-linux-arm.zip
This will download the ngrok zip file into your current Termux directory.
4. Extract ngrok
After the download is finished, extract the ngrok file using:
unzip ngrok-stable-linux-arm.zip
Once extracted, you will see a file named
ngrok in your directory. This is the ngrok executable that we
will use in the next steps.
Setting Up ngrok in Termux
After installing ngrok, the next step is to set it up using an authtoken. The authtoken is a unique key that connects ngrok on your device to your account. Without it, ngrok will not work properly.
1. Create a ngrok Account
To get started, visit the official ngrok website:
Click Sign up for free and create an account using your email and password. Once the signup process is complete, log in to your account dashboard.
2. Get Your ngrok Authtoken
Once you’re logged in, open 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 the authtoken. You will need it in the next step.
3. Add the Authtoken in Termux
Now, go back 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.
If the command runs successfully, ngrok is now linked to your account and ready to use in Termux.
Using ngrok in Termux
Now that ngrok is installed and linked to your account, you can start creating secure tunnels to expose your local servers to the internet.
Start a ngrok Tunnel
To create a tunnel, run the following command in Termux:
./ngrok http 8080
This command creates an HTTP tunnel on port 8080.
Make sure your local server is already running on this port.
If your server uses a different port, replace
8080 with the correct one.
What Happens Next
Once the command runs, ngrok will connect to its servers and generate a public URL. This URL forwards traffic from the internet to your local server.
Anyone with this link can access your server while the tunnel is running.
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.
Accessing Your Server
In the Termux output, look for the Forwarding URL.
Open this URL in a browser or share it with others to access your local server from anywhere.
Troubleshooting Common Issues
1. Session Status reconnecting
If you see an error like this:
Why this happens:
This usually means ngrok cannot reach its servers. The most common reasons
are an unstable internet connection, DNS problems, or Android restricting
Termux in the background.
What to try first:
- Make sure your internet connection is active and stable
- Disable battery optimization for Termux
- Stop any running ngrok process and start again
./ngrok http 8080
About the hotspot tip:
You do not need to turn on your mobile hotspot in most
cases. ngrok works fine on normal mobile data or Wi-Fi. Toggling the
hotspot is only a last-resort workaround for some devices or mobile
networks if the tunnel keeps reconnecting.
2. DNS Resolution Errors
If ngrok fails to resolve domain names, your DNS configuration in Termux may be the problem.
Solution: Edit the DNS configuration file:
nano /data/data/com.termux/files/usr/etc/resolv.conf
# Add the following lines:
nameserver 8.8.8.8
nameserver 8.8.4.4
Save the file, close the editor, and restart ngrok.
3. IPv6 Connectivity Issues
Some mobile networks have unstable IPv6 support. If ngrok keeps failing, forcing IPv4 can help.
Solution:
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
This disables IPv6 and forces ngrok to use IPv4, which is more reliable on many networks.
Congratulations! You’ve successfully installed and configured ngrok in Termux. Now you can securely expose your local server to the internet with just a few commands. This means you can test webhooks, share your projects, or debug APIs from anywhere without complicated setup.
Remember to always keep your tunnels safe. Avoid exposing sensitive services, and only share your ngrok URLs with people you trust. If you follow the steps in this guide, you’ll be able to work confidently with ngrok on your Android device.
Don’t stop here! After setting up ngrok, you can try building some easy Termux projects on Android to practice what you’ve learned and share them online with friends using ngrok’s secure tunnels.
If this guide helped you, leave a comment below and share it with others who use Termux. Your feedback and shares help more people find and learn from this tutorial.