Lesson 5 of 6

A tunnel from your laptop

About 12 minutesGive a server on your own computer a public address, until you close the lid.

In lesson 4 you uploaded a folder. But the server.js you wrote in lesson 2 isn't a folder of files: it's a program that has to run. The simplest place to run it is the computer you already have. A Cloudflare Tunnel gives that program on your laptop a real public address, without uploading anything and without touching your router.

How a tunnel works

Normally nobody on the internet can reach your laptop: your home router and Wi-Fi keep it hidden, and that's a good thing. A tunnel turns the connection around. A small program, cloudflared, runs on your laptop and calls out to Cloudflare, then keeps that line open. When someone visits your address, Cloudflare sends the request down the open line, cloudflared hands it to localhost:3000, and the answer goes back the same way.

Here is that loop as a machine you can poke. The dotted line is a visitor asking Cloudflare for your page; the green tube is the line cloudflared keeps open. Click the laptop to close its lid.

1. Install cloudflared

Mac (with Homebrew)
$ brew install cloudflared
Windows (PowerShell)
$ winget install --id Cloudflare.cloudflared
Linux (Debian or Ubuntu)
$ curl -L -o cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
$ sudo dpkg -i cloudflared.deb

Then open a new terminal and check it's there. Other systems: see Cloudflare's downloads page.

Terminal
$ cloudflared --version
cloudflared version 2026.x.x

2. Start your server

Use the server from lesson 2, or any program that answers on a port. Leave this terminal running.

Terminal
$ cd ~/hello
$ node server.js
open http://localhost:3000

3. Open a quick tunnel

In a second terminal (the first one is busy running your server):

Second terminal
$ cloudflared tunnel --url http://localhost:3000
Your quick Tunnel has been created! Visit it at:
https://some-random-words.trycloudflare.com

Open that address on your phone, with Wi-Fi switched off so it really comes over the internet. That page is coming from your laptop. No account, no upload, no settings file.

Quick tunnel or named tunnel

Quick tunnelNamed tunnel
Commandcloudflared tunnel --url …cloudflared tunnel create, then run
AddressRandom trycloudflare.com name, new every timeYour own name, like app.yourname.com
Account neededNoYes, and a domain in Cloudflare
Good forShowing someone something todaySomething you keep running

A named tunnel is the same idea set up to last. You'll recognise every step now; you don't need to run them today.

Named tunnel, for later
$ cloudflared tunnel login
$ cloudflared tunnel create hello
$ cloudflared tunnel route dns hello hello.yourname.com
$ cloudflared tunnel run --url http://localhost:3000 hello

Now close the lid

Here's the catch, and it's the whole point of this lesson. The tunnel reaches your laptop. Press Ctrl C in either terminal, close the lid, let the battery run out, or walk out of Wi-Fi, and the address stops working. Visitors get a Cloudflare error page instead of your site.

For a demo, that's fine. For a bot that should answer at 3 a.m., or a site your friends use every day, it isn't. You need the same setup on a computer that is always on and online. That is a server you rent, and it's the next lesson.

HomeworkSmall and free: no account and no payment needed.
You're sharing your laptopAnyone with the address can reach whatever is on that port while the tunnel runs. Tunnel only the server you mean to share, never a folder of private files, and stop the tunnel when you're done.

Why can a visitor reach your laptop through a tunnel when your router normally blocks them?

The connection starts from your laptop, going out, which routers allow. Nothing is uploaded and no port is opened. That's also why it stops the moment cloudflared stops.

Your tunnel site works. You close the laptop and go to sleep. What does a visitor see at 3 a.m.?

A tunnel has no copy of anything. It only forwards to your machine, so when your machine sleeps, so does the site. Lesson 6 moves the same setup to a computer that never sleeps.

Remember
  • A tunnel gives a program on your laptop a public address: cloudflared tunnel --url http://localhost:3000.
  • cloudflared calls out to Cloudflare, so no router settings and no upload.
  • Quick tunnels are random and temporary; named tunnels use your own domain.
  • Laptop off = site off. Something that must stay up needs a computer that stays up.