Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tunnel into my machine

Ever had a moment where something ran on your machine and you wanted to quickly share it with your friends?
It could be an ElasticSearch instance, a Kafka observability page or, if you’re like thy precious, a game. Let’s go with a game.

This repo has a lot of games. All playable over browser with http server. An everyday Joe would use their web interface but we are no ordinary people. We have linux and willingness to display free will. We shall clone 2 gigs to play a 17mb game.

git clone https://github.com/qz-games/Games01  
cd Games01/SNIPER

All that we now need to play it is an active http server. Let’s use python to spin up a quick webserver. We will be using PORT=8000:

python3 -m http.server 8000

Now the webserver is hosting whatever is inside the $(PWD).

This is fun. But what if you want to share this with your friends? Would they still be your friends if you told them to clone 2 gigs of repo with 20 games when you only want them to try one? This is where cloudflare helps us (for free).

Installing cloudflared

Stop. Searching for cloudflared directly with your package manager wouldn’t yield any result. Companies like Cloudflare likes to manage their own distributions. They can’t wait for Ubuntu or Debian maintainers to test and approve them for the “official” OS list. Hence we first need to convince our machine to trust cloudflare and then look for updates not only from default places but also from freshly added list. The commands for your distribution can be looked up on cloudflare packages website. For ubuntu 24, these will do:

# Add cloudflare gpg key
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null

# Add this repo to your apt repositories
# Stable
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared noble main' | sudo tee /etc/apt/sources.list.d/cloudflared.list

# install cloudflared
sudo apt-get update && sudo apt-get install cloudflared

Make a tunnel from your machine to the internet

Verify that 8000 is occupied in your terminal with lsof.

lsof -i :8000
COMMAND   PID       USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
python3 23001 curiouscat    3u  IPv4  90173      0t0  TCP *:8000 (LISTEN)

All that this locahost process needs to do to be accessible from anywhere on the internet is

cloudflared tunnel --url http://localhost:8000
# look out for a a link of type https://random-words.trycloudflare.com
Welcome to the internet

Congratulations. You’ve made the process on your local machine accessible to the world wide web. Share your friends a link and they can have a quick look.