DEV Community

Cover image for Secure Tunneling Explained: Ngrok vs Cloudflared
Aryan Dev Shourie
Aryan Dev Shourie

Posted on

Secure Tunneling Explained: Ngrok vs Cloudflared

Problem Statement

In development, testing, or remote collaboration, developers often need to expose a locally hosted web service to the Internet. Whether it is a Webhook testing endpoint, a locally running admin dashboard, or a demo site for a client, making a local server publicly accessible is not straightforward. Following the traditional approaches requires configuring firewalls, setting up ports and deploying to different servers. All of these things can be complex, insecure and time consuming.

Tunneling

For the above problem statement, the solution is Tunneling. It refers to creating a secure pathway between two endpoints - in this context, between a public URL and a local server by encapsulating the network traffic. This process allows a remote client to access a local service as if it were hosted on a public server, all while bypassing NAT, firewalls and complex DNS setups.

Following are the advantages of Tunneling:

  1. It enables you to test integrations locally.
  2. It helps in client demos without deploying code.
  3. It facilitates remote development and debugging.

In this article, we will discuss the two widely used tools for Tunneling: Ngrok and Cloudflared Tunnel.

Ngrok

Ngrok is a popular tunneling tool that provides public URLs to your locally running applications, commonly used for testing webhooks and showcasing work in-progress.

Example usage of Ngrok
Step 1: Install Ngrok

# macOS brew install ngrok # or download from https://ngrok.com/download 
Enter fullscreen mode Exit fullscreen mode

Step 2: Start a local server

python3 -m http.server 8000 
Enter fullscreen mode Exit fullscreen mode

Step 3: Expose the server via Ngrok

ngrok http 8000 
Enter fullscreen mode Exit fullscreen mode

Output:

Forwarding https://abcd1234.ngrok.io -> http://localhost:8000 
Enter fullscreen mode Exit fullscreen mode

You can now access your local server from anywhere using https://abcd1234.ngrok.io

Advantages of using Ngrok:

  • Very easy to setup and use.

  • Supports both HTTP and TCP tunnels.

  • Provides a real-time web UI for inspecting traffic.

  • Secure and encrypted connections.

Disadvantages of using Ngrok:

  • The free version has usage limits. (example: 1 tunnel, random subdomains)

  • Requires signup and token for full functionality.

  • Not open-source.

Cloudflared Tunnel

It is a service by Cloudflare that exposes your local server securely through the Cloudflare network, eliminating the need to open firewall ports or configure DNS.

Example usage of Cloudflared Tunnel
Step 1: Install Cloudflared

# macOS brew install cloudflared # or download from https://developers.cloudflare.com/cloudflared 
Enter fullscreen mode Exit fullscreen mode

Step 2: Authenticate with Cloudflare

cloudflared login 
Enter fullscreen mode Exit fullscreen mode

This opens a browser and asks you to select the domain you want to use.

Step 3: Create and run a tunnel

cloudflared tunnel --url http://localhost:8000 
Enter fullscreen mode Exit fullscreen mode

Output:

https://random-string.trycloudflare.com -> http://localhost:8000 
Enter fullscreen mode Exit fullscreen mode

You can now access your local server from anywhere using https://random-string.trycloudflare.com

Advantages of using Cloudflared Tunnel:

  • Free and unlimited usage.

  • Integrates directly with Cloudflare for DNS and security.

  • Uses your own domain.

  • High reliability via Cloudflare's network.

Disadvantages of using Cloudflare Tunnel:

  • Required Cloudflare-managed domain for advanced usage.

  • Setup for persistent tunnels is more involved than Ngrok.

Conclusion

Tunneling tools like Ngrok and Cloudflared Tunnel have become essential in modern development workflows.

  • Use Ngrok for its simplicity and powerful dev tooling features.

  • Use Cloudflared Tunnel for more permanent, secure and production-grade tunnels.

Both are effective - choose based on your specific needs: simplicity or scalability.

And that's it! This was just a quick overview about the secure tunneling tools like Ngrok and Cloudflared Tunnel.

Connect with me on LinkedIn :- Linkedin

Do check out my GitHub for amazing projects :- Github

Top comments (0)