githubEdit

Cloudflare Tunnels: The Cybersecurity Pro's Secret Weapon for Secure Cloud Access

๐Ÿ”ฅ Backstory: Why I Set This Up

  • One of my internal apps was exposed on the internet despite being proxied through Cloudflare.

  • Anyone scanning the internet (like Shodan or Censys) could hit it directly, even though Cloudflare was enabled

  • Enter: Cloudflare Tunnel no exposed ports, no firewall nightmares, no BS.


Would you like me to add a little shodan.io search reference or a quote from your internal logs to give it that gritty realness?

โœจ TL;DR

Use Cloudflare Tunnel to securely expose multiple web apps (on different ports) to the internet using just one tunnel, without opening a single port on your firewall. This blog walks through:

  • Creating the tunnel

  • Mapping subdomains to services

  • Auto-starting with systemd


๐Ÿง  Why Use Cloudflare Tunnel?

  • ๐Ÿ” No port forwarding

  • ๐Ÿ’ธ Free for personal and dev use

  • ๐ŸŒ Expose multiple apps via subdomains

  • ๐Ÿ“ฆ Works great with local HTTPS and Docker


โš™๏ธ My Setup

  • OS: Ubuntu 22.04 (but any Linux works)

  • Cloudflare domain: wehost.co.in

  • Goal: Expose multiple local apps like:

    • test.wehost.co.in โ†’ localhost:8002


๐Ÿš€ Step 1: Install cloudflared

๐Ÿ” Step 2: Authenticate with Cloudflare

  • This opens a browser window. Select your domain, and Cloudflare will generate a credentials file.

๐ŸŒช๏ธ Step 3: Create the Tunnel

This creates a tunnel and saves a .json credentials file under ~/.cloudflared/.

You can confirm with:

๐Ÿ› ๏ธ Step 4: Create Config File

Create a config.yml in ~/.cloudflared/:

Replace <YOUR_TUNNEL_ID> with the one from cloudflared tunnel list.

๐ŸŒ Step 5: Route the Subdomain

This links your tunnel to the subdomain in Cloudflare DNS.

โœ… Step 6: Run the Tunnel

You should see output like:

๐Ÿ” Step 7: Auto-Start on Boot with systemd

Create the service file:

๐Ÿ”ฎ Whatโ€™s Next: Auto-Magic with CI/CD

Now that the tunnelโ€™s solid, Iโ€™m planning to take it a step further:

The next iteration of this setup will integrate with a CI/CD pipeline so every time I deploy a new app or update port mappings, the pipeline will:

  • Automatically update the config.yml

  • Push it to the server

  • Restart the Cloudflare tunnel service

  • Route any new subdomains on the fly

Think: zero-touch deployments with automatic subdomain provisioning. No more manual edits, no more downtime just ship and forget.

Stay tuned โ€” that oneโ€™s gonna be fun. ๐Ÿ”ง๐Ÿš€

Last updated