How to Install Ngrok in Termux?

How to Install Ngrok in Termux

Ngrok is a popular tool that creates secure tunnels from the internet to your local host. But do you know you can install it on Termux also? So, today in this article, we will learn how to install Ngrok in Termux and use it to access local servers.

What is the use of Ngrok?

1. Sharing Websites

With the help of Ngrok, you can easily share websites that are running on private networks with your colleagues or clients. You can create a secure tunnel to host your local website and can share it with others.

2. TCP Server Creation

You can use Ngrok to create TCP servers on your device. This means you can expose any network service running on a specific port to the internet, facilitating remote access and testing.

3. Port Forwarding Simplification

As we all know that port forwarding is a difficult task. With ngrok you can easily forward the ports, it implies the process of port forwarding.

4. Testing Mobile Apps

You can also use Ngrok to test mobile apps by tunneling requests from your mobile device to your local server, you can effectively test and debug your mobile app, ensuring seamless integration with your backend services.

5. Personal Cloud Services

Ngrok can be leveraged to run personal cloud services from your home network. Whether you need remote access to files, media streaming, or other cloud-based functionalities.

Prerequisites

Before you begin, make sure you have the following-

1. Firstly, you must have Termux installed on your Android device. You can download it from fdroid

2. Secondly, you  need to have a good working internet connection 

3. Lastly, an active account with Ngrok. If you do not have an account, you can create one from ngrok.

Steps to Install Ngrok in Termux

Step 1: Install Required Packages

To install Ngrok in Termux, you will need to update & install several required packages. So, Open Termux and type the following command to install the necessary packages:

apt update && apt upgrade
apt install wget unzip

Step 2: Download and Unzip Ngrok

Once the required packages have been installed, you can download Ngrok by typing the following command in Termux:

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

After the download is complete, unzip the file using the following command:

unzip ngrok-stable-linux-arm.zip 

Step 3: Make the Extracted File Executable

After unzipping ngrok, you have to give permission to read, write and execute to it. So give the following command -

chmod +x ngrok

Step 4: Connect Ngrok to Your Account

Now that Ngrok has been installed, you need to connect it to your Ngrok account. To do this, type the following command in Termux and replace the placeholders with your Ngrok authtoken:

ngrok-termux-authtoken
./ngrok authtoken <YOUR_AUTH_TOKEN>

Step 5: Create a Tunnel

With Ngrok connected to your account, you can now create a tunnel. To create a tunnel to your localhost, type the following command in Termux and replace the PORT NUMBER with the localhost port number you want to forward i.e. http 80:

./ngrok http <PORT_NUMBER>

Now, your local host will be accessible from the internet via the generated Ngrok URL.

ngrok-termux

Remember to turn on your mobile's hotspot, otherwise, ngrok will not work on your Android phone.

Read - Termux Commands List

If you want to know more about ngrok or want to troubleshoot any error, read the documentation of ngrok - https://ngrok.com/docs

How Ngrok Works?

Ngrok establishes secure tunnels by utilizing the concept of the reverse proxy. It acts as an intermediary between your local machine and the internet This enables external access to services running on your local machine. You can expose your local website to the internet with the help of Ngrok.

How to Solve Ngrok Reconnecting Error?

ngrok-reconnecting

If after installing ngrok on your Android mobile, you are getting the reconnecting error, then do not worry. It can be solved by turning on the mobile hotspot. Just turn on the mobile hotspot and see whether the reconnecting error is solved or not, if not then comment down, and I will surely provide you another solution.

Ngrok Alternatives

  • Localtunnel

The first alternative to ngrok in the list is Localtunnel. Localtunnel is a tool that allows you to expose your local web server to the internet without requiring any firewall or router configuration. It provides a public URL that can be accessed remotely. It supports both HTTP and HTTPS.

  • Serveo

The second alternative to ngrok is Serveo. It also lets you expose your local web server to the internet. It works by creating an SSH tunnel to a publicly accessible server, allowing you to forward incoming traffic to your local machine. Serveo also supports both HTTP and SSH protocols and it is very easy to set up.

  • Localtonet

Localtonet is another alternative to ngrok. This also does the same work as the above works. But the main problem is that you can not use it on Termux. So, for Termux, I suggest you to use ngrok otherwise in other cases you can go with this also. This also supports HTTP and SSH protocols. So decide accordingly.

Final Notes

So, this is how you can install Ngrok in Termux and use it to access local servers. The process is straightforward and easy to follow. With Ngrok, you can easily expose your local development environment to the internet and share it with others for testing and collaboration. If you get any error just comment down, and I will help you ASAP.

Thank you!

Additionally, you can watch video on our youtube channel for practical:

FAQ

With the help of Ngrok, you can create secure tunnels from the internet to your local host. You can use it on Termux also.

The ngrok command in Termux is ./ngrok http "Port Number".

To check your Ngrok token, go to ngrok.com and log in to your account. Click on the dashboard, scroll a little, and you will find the ngrok authtoken command. Copy that Authtoken and use it where you want to use it.