NGROK: Secure Tunnel to Localhost

Vaibhav Kumar Srivastava
5 min readFeb 26, 2021
Figure 1

Do you want to test your locally hosted web server on the Internet without buying any public IP or Domain name ? NGROK is an application that enables you to expose your localhost server as a subdomain of ngrok.com without even registering for any Domain name. In simple words you will get the URL for your local site that is accessible from any endpoint device connected locally or outside of your network. The best part about Ngrok is its lightweight feature and its support for HTTPS & HTTP endpoints. Let’s explore how Ngrok works and how you can install and run Ngrok on your system.

Who needs NGROK ?

One who wants to test the locally hosted web server or showcase the local web application to clients before actual hosting can use Ngrok with minimal effort and free of cost (Excluding subscription facilities)

How does NGROK work ?

In order to understand how NGROK works you should have an idea about how the endpoints communicate with the web application. Suppose I am having an endpoint device ex. laptop with local IP address: 192.168.1.101 and i want to open “Facebook.com” on my device. This local IP address will be unique to my network only but not globally. Therefore in order to communicate to Facebook.com (outside my network) i need a public IP which is given by the NAT (Network Address translation) router collectively for multiple endpoints together (shown in Fig 2).

Figure 2

The translation of local to global IP address and vice versa is handled by NAT router through NAT table entries to track the response for requested sites or resources. Now suppose if i have made a web application (192.168.1.101) which is running on my local server and i want someone (Example Mr. Angry with IP Address: 192.168.1.103) who is outside of my network to access my web application. Problem is whenever Mr. Angry will try to access my web application, will type the URL including my local IP address but unfortunately, he will be redirected to IP address: 192.168.1.101 in his own network which belongs to some other person say (Mr. Monkey). In order to resolve this issue we need a mediator who can expose my localhost server as public accessible domain so that Mr. Angry can access my web application. This role of mediator is done by NGROK. It provides the facility of port forwarding through which it tunnels a secure path between my localhost and NGROK server. After authentication it provides a public accessible URL as a subdomain of ngrok.com which you can advertise to Mr. Angry and he can access your web application without an issue.

How to install NGROK ?

Step 1: Visit the download section of the Ngrok (https://ngrok.com/download). Make sure you download Ngrok from the official website only (Shown in fig 3)

Figure 3

Step 2: In order to authenticate your device to Ngrok server you need to Sign Up to Ngrok which is completely free of cost. (Shown in Fig 4)

Note: You can’t skip this step because in order to authenticate your device you need an Auth token which will be only given to you only after the Sign-Up procedure.

Figure 4

Step 3: Unzip the downloaded Ngrok application, navigate to the unzipped folder and open the folder in the terminal (Shown in Fig 5)

Figure 5

Step 4: Run this command: “./ngrok authtoken <your_auth_token>” to authenticate your device with NGROK server. You will see your auth token in the dashboard (shown in Fig 6)

Figure 6

Step 5: Once you are authenticated with Ngrok server you will get the confirmation (shown in Fig 7).

Figure 7

Step 6: In order to see the commands used in NGROK, run “./ngrok help” in the terminal (Shown in Fig 8)

Figure 8

Step 7: To start a HTTP tunnel on port 80, run this command in your terminal: “./ngrok http 80” (Shown in Fig 9)

Figure 9

Step 8: Copy any of the advertised URL corresponding to the forwarding row (shown in the fig 10) and send it to the person whom you want to access your localhost server.

Figure 10

There are number of other functionalities included in NGROK like customization of URL, unlimited number of tunnels, long time connection etc (Shown in Fig 11) but the pro facilities are only available with subscription of NGROK.

Figure 11

I hope this blog has been helpful to you. Don’t forget to leave your feedback or any suggestion. If you want to watch the complete procedure of NGROK installation you can watch it on my channel: Codewithvamp (Link)

Stay Curious Stay Protected !!

--

--