2015-02-24

Ngrok: easiest way to Tunnel to localhost

Ngrok is a tool that could help you publish your local web so it can be accessed by public. The example use case is when you want to publish your development server, so client or your boss can access it from another place. Yes, it's easy to install your web application to a VPS or hosting server or use VPN remote desktop software (Hamachi or TeamViewer), but it would took some time and probably bigger bandwidth. It's really easy to install ngrok since it's portable (built using Go programming language), in ArchLinux you can type:

yaourt --needed --noconfirm -S --force ngrok

Or you can download the binary from their website. To use ngrok, just type the program name followed with service port on your localhost that you want to publish, for example:

ngrok 8080

After running the program, there would be a link given (HTTP and HTTPS) that can be acessed by public, if people visit that link it would give the same output as http://localhost:8080.


You can view the visit log on the web interface http://127.0.0.1:4040.


If you have already registered to their website you can use subdomain feature, by adding authtoken (get it after registering) for the first time, for example:

ngrok -authtoken ndf8gus0n958t 8080

Then you can use subdomain feature for example:

ngrok -subdomain mysubdomain 8081

This would create a subdomain on Ngrok's domain, for example mysubdomain.ngrok.com that linked to your  http://localhost:8081. One more cool feature about Ngrok is you can replay the request, just press the replay button on the web interface. Minor flaw of this program, if you run multiple instance of Ngrok, only the first instance will get web interface (http://127.0.0.1:4040), the next instance would not get the web interface.