ngrok Step-by-Step Guide: Easily Share Your Local Server

Craig Buckler
Share

This tutorial demonstrates a way to share your localhost server with anyone, anywhere, using ngrok to create a secure tunnel to your local development server.

Demonstrating your application’s latest features to project managers or clients isn’t easy unless they’re sitting a few desks away. It may be possible to commit the changes and deploy to a public staging server, but that process can be impractical if you’re just seeking an opinion about a widget color or demonstrating the futility of their ridiculous suggestion!

Ideally, you need some way to share access to your localhost server. ngrok provides that solution for sharing your local web server. We’ll show you how to set it up for any purpose, and leave you with the best ngrok alternatives (just in case).

What is ngrok?

Your development machine may be connected to a secure network behind a firewall. To work around access restrictions, ngrok runs a small client process on your machine which creates a private connection tunnel to the cloud service. Your localhost development server is mapped to an ngrok.io sub-domain, which a remote user can then access. There’s no need to expose ports, set up forwarding, or make other network changes.

The ngrok client software is available for Windows, macOS, and Linux.

Is Local Tunneling Secure?

The connection tunnel established by ngrok is secure and can only transmit data to the localhost port you have open. It would be difficult to do any damage, but it’s only as secure as the application you’re testing.

In most cases, you’ll use ngrok to temporarily grant access to someone by issuing them with a randomly generated URL. It’s best to assume that anyone could access your app while the tunnel is open. You may want to disable that “delete all files” option while your tunnel is active!

What Does the Service Cost?

The basic ngrok service is free and permits up to four tunnels and 40 connections per minute. Commercial options start from $5 per month, providing further connections and custom domains.

Get the ngrok Download

To start, open ngrok.com in your browser and click Sign up to register. A Google or GitHub account is easiest, but you can choose standard registration with an email address and password. An email verification link will be sent to you.

After login, you’ll be directed to the ngrok dashboard where you can download the client for your operating system.

ngrok dashboard

Download and extract the file, following any specific instructions for your OS. It’s then necessary to add your authentication token by running the command shown in the Connect your account section a little further down the page.

ngrok configure

./ngrok authtoken <token>

Note: Windows users will enter ./ngrok.exe.

How to Use ngrok to Share Access to Your Local Web Server

Launch your web application using its normal start command, then note the port and whether it’s running on http or https. To start a new tunnel, run:

./ngrok <protocol> <port>

For example, if your site is served on http://localhost:8888, enter the following into the command line:

./ngrok http 8888

The terminal will clear and show the status with two Forwarding http and https addresses, such as http://123456789.ngrok.io/. You can pass either ngrok URL to another person so they can access your application from anywhere. The terminal shows a log of requests while ngrok is active.

checking terminal status

The ngrok status panel panel at dashboard.ngrok.com/endpoints/status also shows a list of currently active URLs and client IP addresses. (You may need to refresh the browser to update it.)

ngrok status

Once you’ve finished, quit ngrok by pressing Ctrl | Cmd + C in your terminal. Further help and options are available by entering:

./ngrok help

ngrok Alternatives

ngrok is possibly the easiest and most well-known localhost tunneling service, but alternative options include:

  • LocalXpose: a commercial service with free options. Signup is required, but terminal-based and Graphical User Interface clients are available.
  • localhost.run: a free service which works via SSH so no client or signup is necessary.
  • localtunnel: an open-source Node.js client. No signup is necessary.
  • JPRQ: an open-source Python client. No signup is necessary.
  • sish: an open-source, Docker-based container client. No signup is required.

ngrok and similar secure tunnel services can revolutionize how you demonstrate web apps to other remote workers. It will help testing and reduce frustrating feedback delays.

FAQs about ngrok

What is ngrok?

Ngrok is a cross-platform tool that creates secure tunnels between your local development server and the internet, allowing you to expose locally hosted services to the web. It’s often used for testing and development purposes.

Why would I need ngrok?

Ngrok is useful when you’re developing web applications or APIs locally and need to share them with others or access them from external devices for testing and debugging.

How does ngrok work?

Ngrok establishes a secure tunnel to its servers, and traffic sent to a public URL generated by ngrok is forwarded through the tunnel to a specific port on your local machine.

Is ngrok open source?

No, ngrok is not open source. The tool has a paid business model, and while there is a free version, the full source code is not available.

How do I install ngrok?

To install ngrok, you need to download the appropriate binary for your operating system from the ngrok website. Then, you can unzip it and place the binary in a directory included in your system’s PATH.

Can I use ngrok in production environments?

ngrok is primarily designed for development and testing, it’s not recommended for production use due to potential performance and security considerations.

Is ngrok secure?

Ngrok uses secure tunnels (HTTPS) to transfer data between your local machine and the internet. However, keep in mind that data passing through ngrok’s servers is decrypted at their end before being sent to your local machine.

Can I use ngrok with Docker containers?

Yes, you can use ngrok with Docker containers to expose services running within the containers to the internet, similar to exposing local services.

Can I use ngrok without installing it locally?

Yes, ngrok provides a web-based version called ngrok web interface, which allows you to create tunnels without installing the ngrok binary on your local machine.

What are ngrok authtokens?

An ngrok authtoken is a unique token associated with your ngrok account. It’s used to authenticate your usage of ngrok and to access features available to registered users.

Can I use ngrok for TCP or UDP tunnels?

Yes, ngrok supports creating tunnels for TCP and UDP protocols, in addition to HTTP and HTTPS. This can be useful for exposing services that don’t use the HTTP protocol.

Can I specify a custom subdomain with ngrok?

Yes, if you have an ngrok account, you can use a custom subdomain by adding it to your ngrok configuration and then using the ngrok http command with the --subdomain flag.

How do I expose a local server using ngrok?

After installing ngrok, run the command ngrok http [port] in your terminal, replacing [port] with the port number your local server is running on. Ngrok will provide a public ngrok URL that points to your local server.