You want to expose your laptop’s localhost (like a web app running on http://127.0.0.1:3000
or http://localhost:8000
) to the internet using Cloudflare, right?
The easiest and most secure way is using Cloudflare Tunnel (Cloudflared).
🔹 Steps to expose localhost with Cloudflare
-
-
On Linux/macOS:
-
On Windows:
Download from Cloudflared GitHub releases and install.
-
-
This opens a browser, asks you to log in to your Cloudflare account, and select a domain you own.
-
- Configure Tunnel to expose localhost
Example: expose
http://localhost:8000
Create a config file:-
Route traffic
Point your Cloudflare DNS hostname (app.yourdomain.com
) to the tunnel: -
Now your localhost app is available on the internet at
👉 https://app.yourdomain.com
🔹 If you don’t own a domain
Cloudflare Tunnel can still give you a random .trycloudflare.com
URL:
It will output something like:
Share that link and people can access your local app.
If you start with the random .trycloudflare.com
URL now, you can later switch to your own domain without problems.
Here’s how it works:
-
Random mode (
cloudflared tunnel --url http://localhost:8000
)-
No domain required.
-
You instantly get a temporary link like
https://xyz123.trycloudflare.com
. -
Great for testing or quick sharing.
-
The link changes every time you restart.
-
-
Domain mode (with your Cloudflare-managed domain)
-
Permanent link like
https://app.yourdomain.com
. -
Requires creating a named tunnel + DNS record.
-
You can later “upgrade” your setup by creating a tunnel and pointing it to your domain, without changing your app.
Suppose you want:
-
main.sumanadhikary.com.np
→ your local website on port 80 -
blog.sumanadhikary.com.np
→ your local app on port 8080 -
test.sumanadhikary.com.np
→ your local service on port 10000
🔹 Config file (~/.cloudflared/config.yml
)
🔹 Steps
-
Login once (to get cert.pem):
-
Create a tunnel:
-
Add DNS records (in Cloudflare dashboard or via command):
(This automatically creates CNAME records pointing to your tunnel.)
-
Run the tunnel:
✅ Now:
-
https://main.sumanadhikary.com.np
→localhost:80
-
https://blog.sumanadhikary.com.np
→localhost:8080
-
https://test.sumanadhikary.com.np
→localhost:10000
the software just uses the IP 192.168.19.15
, and you don’t know which port it’s running on. That’s common with proprietary intranet apps. No problem — here’s how you can find it:
Step 1: Check if it’s a browser-based app
-
On your office laptop, open a browser and type:
or
-
If it loads, the port is default:
-
http
→ port 80 -
https
→ port 443
-
Step 2: Scan the server for open ports
If it doesn’t load in a browser:
Option A: On office laptop (Windows)
-
Open CMD as Administrator
-
Run:
-
This lists all ports the software/server is listening on.
-
Look for
LISTENING
entries on that IP.
Option B: On office laptop (Linux)
-
Shows which ports are active and which program uses them.
Step 3: Test the port
Once you find a port (e.g., 5000
):
-
Cloudflare will give you a public URL.
-
Open that URL from home to access the intranet software fast, no AnyDesk lag.
For windows
Here’s a step-by-step guide to install and use it:
🔹 1. Download Cloudflared for Windows
-
Go to the official release page: Cloudflared GitHub Releases.
-
Download the latest
cloudflared-windows-amd64.exe
(if your system is 64-bit). -
Rename it to
cloudflared.exe
for convenience. -
Move it to a folder like:
-
C:\Program Files\cloudflared\
-
or add it directly into a folder already in your PATH (like
C:\Windows\System32
).
-
🔹 2. Add to PATH (optional but recommended)
-
Press
Win + R
→ typesysdm.cpl
→ Enter. -
Go to Advanced → Environment Variables.
-
Under System variables, find
Path
→ Edit → Add new entry: -
Click OK → OK.
Now you can run cloudflared
from any terminal (PowerShell or Command Prompt).
🔹 3. Basic Commands
-
Check installation:
-
Run a tunnel to a local web server (example on port 80):
→ This gives you a temporary Cloudflare URL to access your local server.
-
Login to Cloudflare (for persistent tunnels):
→ This opens your browser to authenticate with your Cloudflare account.
-
Create a named tunnel:
-
Route a domain (requires Cloudflare-managed domain):
-
Run tunnel (persistent):
🔹 4. Run as a Service (Windows)
To make the tunnel always run in background:
This installs it as a Windows Service.
if you already own your domain (and it’s managed through Cloudflare DNS), then you can make cloudflared
serve your site securely under your own domain instead of the temporary trycloudflare.com
links.
Here’s how you’d do it:
🔹 1. Prerequisites
-
Your domain must be added to Cloudflare (via their dashboard).
-
DNS must be managed by Cloudflare (nameservers pointing to Cloudflare).
-
cloudflared
installed on Windows (as I showed earlier).
🔹 2. Authenticate cloudflared
Run:
-
A browser window will open → login with your Cloudflare account.
-
Select the domain you want to use.
-
A certificate will be downloaded to
C:\Users\<You>\.cloudflared\
.
🔹 3. Create a Tunnel
-
This creates a new tunnel ID.
-
Config file and credentials will be stored under
C:\Users\<You>\.cloudflared\
.
🔹 4. Configure Tunnel (config.yml)
Make a file at:
Example:
👉 Replace:
-
app.yourdomain.com
with your real subdomain. -
http://localhost:8080
with whatever service/port you’re running.
🔹 5. Connect Domain to Tunnel
Run:
-
This automatically creates a CNAME record in Cloudflare DNS that points to the tunnel.
🔹 6. Run the Tunnel
Now start the tunnel:
or install it as a service: