Exposing Your Localhost to the Internet Using Cloudflare Tunnel

Cloudflare Tunnel lets you securely expose your local development environment to the Internet without dealing with complicated network configurations or NAT traversal. Cloudflare Tunnel offers an elegant, secure, and free solution, whether you're showcasing your latest project, testing a webhook integration, or debugging an external API interaction.
What is Cloudflare Tunnel?
Cloudflare Tunnel (formerly known as Argo Tunnel) is a service provided by Cloudflare that allows you to expose services running on your local machine to the public internet without opening up firewall ports. Instead of hosting your app on a public-facing server, Cloudflare Tunnel establishes a secure, outbound connection from your machine to Cloudflare’s network.
Step-by-Step Guide: Exposing Your Localhost
Prerequisite
Cloudflare account
Domain registered with cloudflare
Cloudflare’s
cloudflared
CLI installed on your machine.
Install Cloudflare tunnel
Download and install the
cloudflared
binary for your operating system. You can find the latest release here.Create a tunnel
Log in to Cloudflare and navigate to Zero Trust
Go to Networks → Tunnels
Select Create a tunnel
Choose cloudflared for connector type and select Next
Enter a name for your tunnel. (for example,
main-server
).Select Save tunnel.
Next, you will need to install
cloudflared
and run it. To do so, check that the environment under Choose an environment reflects the operating system on your machine, then copy the command in the box below and paste it into a terminal window. Run the command.Next, you need to configure Routing traffic from your domain/sub-domain to your localhost:port
Once the routing traffic has been configured click on Save tunnel and, your tunnel will appear in Zero Trust.
Now, you need to test your Cloudflare-mapped subdomain or domain to ensure it is successfully tunneling traffic to your localhost.
Use Cases for Cloudflare Tunnel
Testing Webhooks: Use your localhost as the endpoint for webhook events from third-party APIs.
Demonstrating Projects: Share your in-progress application with stakeholders or collaborators without deployment.
Debugging in Real-Time: Run integrations or external API calls in your local environment.
Security Best Practices
Use HTTPS to encrypt communication with your application.
Enable authentication for sensitive routes.
Regularly review and rotate credentials.
Conclusion
Cloudflare Tunnel is a game-changer for developers seeking a seamless way to expose their localhost to the internet. Its ease of use, coupled with Cloudflare's robust security, makes it a reliable choice for testing, debugging, and sharing your projects.
Subscribe to my newsletter
Read articles from Subham Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Subham Singh
Subham Singh
Hi, I'm Subham, a software engineer, and tech enthusiast. Welcome to my developer blog. I will be talking about the fascinating world of programming and all things tech. Let's learn and grow together in this ever-evolving landscape!