From localhost to instant DNS

Often, especially when working with other people or when developing integrations with online services, we have to make our computer accessible from the Internet. This information could be obtained from our trusty router, but wouldn't it be easier if we just had a tool that makes our computer port publicly accessible?

Luckily for us there is such a tool!

Meet ngrok, the versatile one line command that makes you forget about router configuration and continuous redeploys. Ngrok is a simple tool that exposes a port from our computer to a unique domain name publicly available on the Internet.

How does it do it?

Well, let's see it in action!

Go to the website, click on the Download button, and choose your destiny. In our case, our destiny is the Linux package in 64-bit. Next, go to the terminal, unzip the file, and copy its contents to the bin folder:

Now do a rehash and type the following:

ngrok http 80
From localhost to instant DNS

We can see that port forwarding for ports 80 and 443 is running on our local 80 port, at a custom ngrok subdomain name. We can also see the region of the server, which by default is located in the US. If we are in a different region we can set this with the following:

ngrok http 80 --region eu

The ngrok server is located in Europe. In order to test our ngrok server, let's use our trusty Python server to show a simple HTML page:

python -m SimpleHTTPServer
From localhost to instant DNS

Then restart ngrok with the HTTP traffic forwarded from port 8000, the default Python web server port:

ngrok http 8000 --region eu
From localhost to instant DNS

Click on the link provided by ngrok, and we will see our web page accessible to the Internet.

That's it. No configuration, no account, no headaches. Just a simple one line command that we can run from anywhere. The subdomain provided by ngrok is a generated one and will change every time we restart ngrok. We have the option of using our custom domain name like Linux https://ngrok.com/, but only after acquiring a paid account.

The ngrok also has a web interface at http://127.0.0.1:4040 where we can see statistics and logs.

Power comes from ease of use and ngrok provides us with that power:

From localhost to instant DNS

Here are some specific scenarios for using this powerful tool: