Skip to main content

Command Palette

Search for a command to run...

From Closet to Cloud: How I Made My Raspberry Pi 5 Accessible from Anywhere

Turning that unused Pi into a web server you can access from anywhere on the internet

Published
7 min read
From Closet to Cloud: How I Made My Raspberry Pi 5 Accessible from Anywhere

The Weekend Project That Actually Worked

I had a Raspberry Pi 5 sitting on my desk, and I wanted to host some side projects on it. Simple enough, right?

Wrong. The moment you try to make your home device accessible from the internet, you hit a wall of networking complexity.

Your Pi sits behind your home router. Your router sits behind your ISP. Your ISP probably puts you behind something called CGNAT. It's like being in a room, inside a building, inside a walled city.

So I spent a weekend figuring out how to punch through all these barriers. Turns out there are two reliable approaches that actually work.

The Two Paths: Port Forwarding vs Tunneling

After testing different approaches, there are two methods that reliably work:

Approach 1: Port Forwarding (direct network access) Approach 2: Tunneling (bypass all the networking complexity)

Let me walk you through both, so you can pick what works for your setup.

Approach 1: Port Forwarding (When Your ISP Cooperates)

Port forwarding is the traditional way to expose local services to the internet.

How it works: Your router creates a direct pathway from the internet to your Pi. When someone visits your-ip:8080, your router forwards that request to your Pi's port 8080.

When this works:

  • Your ISP gives you a real public IP address
  • Your router supports port forwarding configuration
  • You're okay managing dynamic IP changes

Quick Setup Steps:

Step 1: Check if you have a public IP

# On your Pi, check what the internet sees
curl ifconfig.me

# Compare with your router's WAN IP in admin panel
# If they match, you have a public IP!

Step 2: Configure your router

  • Access router admin (usually 192.168.1.1)
  • Find "Port Forwarding" or "Virtual Server" section
  • Add rule: External Port 8080 → Your Pi's IP → Internal Port 8080

Step 3: Test it

# Start a simple server on your Pi
python3 -m http.server 8080

# Test from outside your network
curl http://YOUR-PUBLIC-IP:8080

The Reality Check: This used to work reliably, but many modern ISPs use something called CGNAT (Carrier-Grade NAT). This means multiple customers share the same public IP address, making port forwarding impossible.

Signs you're behind CGNAT:

  • Router shows different IP than curl ifconfig.me
  • Port forwarding rules don't work from external networks

If port forwarding doesn't work for you, tunneling is the solution.

Approach 2: Tunneling (The Universal Solution)

What is Tunneling?

Think of tunneling like this: instead of trying to punch a hole through all the firewalls to reach your Pi, your Pi creates an outbound connection to a server on the internet. When someone wants to access your Pi, they connect to that server, which forwards the request through the existing connection.

Internet User → Tunnel Server → (Existing Connection) → Your Pi

The key insight: outbound connections (Pi → Internet) almost always work, even behind complex firewalls. Inbound connections (Internet → Pi) are what get blocked.

Why tunneling works everywhere:

  • Your Pi initiates the connection (outbound = allowed)
  • No port forwarding needed
  • Works behind any firewall/NAT
  • Tunnel server handles the public internet part

There are several good tunneling solutions:

Cloudflare Tunnel (Free)

  • Best for: Custom domains, reliable service
  • Pros: Free, HTTPS automatic, very stable
  • Cons: Requires Cloudflare account

Tailscale Funnel (Free)

  • Best for: Quick testing, simple setup
  • Pros: Zero configuration, works instantly
  • Cons: URLs are auto-generated

ngrok (Free tier available)

  • Best for: Development, temporary sharing
  • Pros: Simple command, great for demos
  • Cons: Free tier has limitations

Pinggy (Free tier available)

  • Best for: Alternative to ngrok
  • Pros: No account needed for basic use
  • Cons: Limited free usage

For this guide, I'll show you Cloudflare Tunnel because it's free, reliable, and works great for side projects.

Setting Up Cloudflare Tunnel

This works the same whether you're using a Raspberry Pi , or even an old laptop.

Install cloudflared

For Raspberry Pi 5/4 (ARM64):

wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64
sudo mv cloudflared-linux-arm64 /usr/local/bin/cloudflared
sudo chmod +x /usr/local/bin/cloudflared

For old laptops (x86_64):

wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64
sudo mv cloudflared-linux-amd64 /usr/local/bin/cloudflared
sudo chmod +x /usr/local/bin/cloudflared

Verify installation:

cloudflared --version

Option 1: Quick Anonymous Tunnel (No Domain Required)

The fastest way to get started - no authentication, no domain setup required!

Start Your Local Service

# Create a test page
echo "<h1>Hello from my Pi 5!</h1><p>This is accessible from anywhere!</p>" > index.html

# Start simple server
python3 -m http.server 3000

Create Instant Tunnel

# One command to expose your local server
cloudflared tunnel --url http://localhost:3000

That's it! You'll see output like:

+--------------------------------------------------------------------------------------------+
|  Your quick Tunnel has been created! Visit it at (it may take some time to be reachable):  |
|  https://random-words-123.trycloudflare.com                                                |
+--------------------------------------------------------------------------------------------+

Your local server is now accessible from anywhere with automatic HTTPS! Share the URL with anyone - they can access your Pi from anywhere in the world.

Perfect for:

  • Quick demos and testing
  • Sharing work-in-progress with friends
  • Development and prototyping
  • When you don't have a domain

Option 2: Custom Domain Setup (For Your Own Domain)

If you have your own domain managed by Cloudflare, you can create permanent tunnels with custom subdomains.

Step 1: Authenticate with Cloudflare

# This will open a browser for login
cloudflared tunnel login

If you're using SSH (headless setup): The command will show you a URL. Copy it and open it on any device where you're logged into Cloudflare. The authentication will complete automatically on your Pi.

Step 2: Create Your Tunnel

# Create a named tunnel for your projects
cloudflared tunnel create my-home-server

# Note the tunnel ID that appears - save it!

Step 3: Configure DNS Routing

# Connect your domain to the tunnel (replace with your domain)
cloudflared tunnel route dns my-home-server projects.yourdomain.com

Step 4: Create Configuration

Create the tunnel configuration file:

nano ~/.cloudflared/config.yml

Add this configuration:

tunnel: YOUR-TUNNEL-ID-HERE
credentials-file: /home/pi/.cloudflared/YOUR-TUNNEL-ID.json

ingress:
  - hostname: projects.yourdomain.com
    service: http://localhost:3000
  - service: http_status:404

Step 5: Run Your Named Tunnel

cloudflared tunnel run my-home-server

Now visit https://projects.yourdomain.com - you should see your Pi's webpage!

Step 6: Multiple Services

You can host multiple projects on different subdomains:

tunnel: YOUR-TUNNEL-ID-HERE
credentials-file: /home/pi/.cloudflared/YOUR-TUNNEL-ID.json

ingress:
  - hostname: api.yourdomain.com
    service: http://localhost:3001
  - hostname: blog.yourdomain.com
    service: http://localhost:3002
  - hostname: files.yourdomain.com
    service: http://localhost:3003
  - service: http_status:404

Step 7: Auto-Start on Boot

Make your tunnel start automatically:

# Install as system service
sudo cloudflared service install --config ~/.cloudflared/config.yml

# Enable auto-start
sudo systemctl enable cloudflared
sudo systemctl start cloudflared

# Check status
sudo systemctl status cloudflared

Quick Start for Beginners

Want to try this right now? Here's the fastest way:

1. Get your device ready

# Update everything (works on Pi or laptop)
sudo apt update && sudo apt upgrade -y

# Install basics
sudo apt install curl python3 -y

2. Install cloudflared

# Choose the right version for your device
# ARM64 for Pi 5/4, amd64 for laptops
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64
sudo mv cloudflared-linux-arm64 /usr/local/bin/cloudflared
sudo chmod +x /usr/local/bin/cloudflared

3. Create something to host

mkdir ~/my-website && cd ~/my-website
echo "<h1>My First Pi Website!</h1>" > index.html
python3 -m http.server 8000

4. Create instant tunnel

cloudflared tunnel --url http://localhost:8000

5. Share your creation Your website is now accessible at the random URL from anywhere in the world!

The Bottom Line

A couple months ago, I wanted to host some side projects but didn't want to pay for cloud hosting or deal with complex networking. Today, I'm running multiple web services from my Pi 5 that are accessible from anywhere.

The tunneling approach solved every networking challenge. No complex router configuration, no ISP limitations, no monthly hosting fees. Traditional hosting costs $5-10/month, while this setup costs basically nothing after the initial Pi purchase ($80 one-time).

Key takeaways:

  • Modern networking makes direct connections difficult
  • Tunneling bypasses all these limitations reliably
  • Works on Pi or any old laptop
  • Start with anonymous tunnels (one command!)
  • Upgrade to custom domains when you're ready
  • Perfect for side projects and learning
  • Costs basically nothing after initial hardware

When it makes sense:

  • Personal projects and experiments
  • Learning web development
  • Sharing projects with friends
  • Development and testing environments

Give it a try! Worst case, you spend a weekend learning about networking and hosting. Best case, you never pay for basic web hosting again.

Questions? Hit me up on Twitter or LinkedIn. I'd love to see what you build!