Cloudflare Tunnels: A Free ngrok Alternative for Exposing Localhost
Need to expose your localhost application to the internet for testing webhooks, sharing demos, or collaborating with teammates? Cloudflare Tunnels is an excellent free alternative to ngrok that gives you HTTPS-enabled public URLs with just two commands.
Why Cloudflare Tunnels?
While ngrok is popular, Cloudflare Tunnels offers several advantages:
- Completely free - No time limits or connection restrictions
- HTTPS by default - Automatic SSL/TLS encryption
- No account required for quick temporary tunnels
- Built on Cloudflare's global network - Fast and reliable
- Simple setup - Just two commands to get started
Quick Setup
Getting started is incredibly simple. Here's how:
1. Install cloudflared
On macOS using Homebrew:
brew install cloudflared
On Linux:
# Debian/Ubuntu
wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared-linux-amd64.deb
# Other distributions - download from GitHub releases
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o cloudflared
chmod +x cloudflared
sudo mv cloudflared /usr/local/bin/
On Windows:
# Using Chocolatey
choco install cloudflared
# Or download the installer from Cloudflare's GitHub releases
2. Start the Tunnel
Point it to your local application:
cloudflared tunnel --url http://localhost:6969
That's it! You'll see output like this:
2025-11-15T10:30:45Z INF +--------------------------------------------------------------------------------------------+
2025-11-15T10:30:45Z INF | Your quick Tunnel has been created! Visit it at (it may take some time to be reachable): |
2025-11-15T10:30:45Z INF | https://random-words-1234.trycloudflare.com |
2025-11-15T10:30:45Z INF +--------------------------------------------------------------------------------------------+
Your application is now accessible from anywhere via the provided HTTPS URL!
Common Use Cases
Testing Webhooks
Perfect for testing webhooks from services like GitHub, Stripe, or Twilio:
# Start your webhook receiver locally
npm run dev # Running on port 3000
# In another terminal, create the tunnel
cloudflared tunnel --url http://localhost:3000
# Use the generated URL in your webhook configuration
Sharing Development Previews
Show your work to clients or teammates without deploying:
# Your React/Vue/Angular dev server
npm run dev # localhost:5173
cloudflared tunnel --url http://localhost:5173
Mobile Device Testing
Test your web app on real mobile devices without being on the same network:
cloudflared tunnel --url http://localhost:8080
Advanced Features
Custom Domains
For persistent tunnels with custom domains, you can authenticate and configure named tunnels:
# Login to Cloudflare
cloudflared tunnel login
# Create a named tunnel
cloudflared tunnel create my-app
# Configure and route traffic
cloudflared tunnel route dns my-app myapp.example.com
# Run the tunnel
cloudflared tunnel run my-app
Configuration File
For more complex setups, create a config.yml:
tunnel: my-app-tunnel
credentials-file: /path/to/credentials.json
ingress:
- hostname: api.example.com
service: http://localhost:8080
- hostname: app.example.com
service: http://localhost:3000
- service: http_status:404
Security Considerations
- Temporary URLs are random - Quick tunnels generate random URLs that are hard to guess
- Don't expose sensitive data - Only tunnel applications you're comfortable making public
- Add authentication - Consider adding password protection or OAuth to your local app
- Monitor access logs - Keep an eye on who's accessing your tunnel
Comparison: Cloudflare vs ngrok
| Feature | Cloudflare Tunnels | ngrok (Free) |
|---|---|---|
| Price | Free | Free (with limits) |
| HTTPS | ✅ Always | ✅ Yes |
| Custom domains | ✅ Free with Cloudflare | ❌ Paid only |
| Connection time limit | ✅ Unlimited | ⚠️ 2 hour sessions |
| Bandwidth limit | ✅ Unlimited | ⚠️ Limited on free plan |
| Setup complexity | Very simple | Very simple |
Troubleshooting
Port Already in Use
Make sure your application is actually running on the port you specified:
# Check what's running on the port
lsof -i :6969 # macOS/Linux
netstat -ano | findstr :6969 # Windows
Connection Refused
Ensure your app accepts connections from all interfaces or at least localhost:
# Good - listening on all interfaces
python -m http.server 8000
# Also good - explicit localhost
node server.js --host localhost --port 3000
Slow Performance
Cloudflare routes traffic through their nearest data center. Performance is generally excellent, but if you experience issues:
- Check your local network connection
- Verify your application performance locally first
- Consider using a named tunnel for better routing
Conclusion
Cloudflare Tunnels is a powerful, free alternative to ngrok that's perfect for developers who need quick, secure access to their localhost applications. With just two commands, you can expose any local service to the internet with HTTPS enabled.
The best part? It's completely free with no arbitrary time limits or connection restrictions. Whether you're testing webhooks, sharing demos, or debugging on mobile devices, Cloudflare Tunnels has you covered.
Give it a try next time you need to expose a local service!