Pages

Monday, June 10, 2019

Ngrok - Secure Tunneling

One of the biggest problem for every developer is that we cant access resources or sites locally hosted on your development machine from a public address. For example when developing real application we tend to run into certain road blocks such as
Testing webhooks locally
Locally hosted applications on a public address

Ngrok helps us in this way. Ngrok is one of the most popular tunnel service platform through which you can easily expose your local servers which are behind firewalls to the public internet over secure tunnels. Once the local service is exposed through the tunnel, we can access the service from anywhere.

Ngrok is a free tool that we can download and run on our development or local  machine. They describe themselves as a secure tunnel to localhost. All we need to do is to run the ngrok service on a port. Once the ngrok service is up and running, it registers a public url for the local service running on our local machine. When we access the public Url, the request goes to the ngrok cloud service which accepts the traffic and then relays that traffic through to the ngrok process running on our local machine and then to the local service running on that specific port.

Some of the features of Ngrok include :
We can create public HTTP/HTTPS Urls for a website running locally on our machine
These tunnels are very fast and works on HTTP/2 protocol which basically faster the loading
These tunnels can be protected using HTTP basic authentication
Multiple simultaneous tunnels can be created
Websockets are also available
We can even expose our network service to the internet with the help of tcp tunneling

In this article we will see how we can download and run ngrok and access a local service as a public service.

1. Create a free account in the ngrok over here

2. Download the ngrok package based on your platform from here.

3. Once you login using the account you created, we can see the dashboard as below,
4. Under the Auth , We can see a authtoken created. Copy the token.

5. On your local machine , go to location where your ngrok is downloaded.

6. Run the command “ngrok authtoken <token Copied from Auth page>. Copy the command and run in your console. This will store the auth token in the local machine.

7. Once the auth token is saved, we then run the ngrok by passing the port that we want to expose. In my case, i want to expose a tomcat server that is running on the port 18080. For this i will run the command as “ngrok http 18080”

8. Once the ngrok command is ran, we can see tunneling as below,

We can that a public url for both http and https are created and requests are being forwarded to the localhost:18080.

9. Now if you access “http://7dde9905.ngrok.io” we can see our tomcat page running.

10. These tunnel information will also be available on the status page in the Ngrok dashboard.
Tunnels will be shown on the dashboard
This is how we can expose our local machine service to the public Url using ngrok.
More to Come. Happy learning :-)

No comments :

Post a Comment