Setup Cloudflare Tunnels to your home server

March 30, 2023

Setup Cloudflare Tunnels to your home serve

Everything you need to know to get securely connect to your locally hosted application over the internet in under 30 mins.

At the high level, I’m running a SimpleHTTPServer locally, that i want to access over the internet from https://home.mydomainname.com

Secondly, I’ll lock down the access to this URL to whitelisted email addresses.

Prerequisites

Before you start, make sure you:

Local

  • in this POC i’m running a SimpleHTTPServer to surface the Director listing of a folder
  • python2 -m SimpleHTTPServer 65000

Setup cloudflared

Download

wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb

install

dpkg -i cloudflared-linux-amd64.deb

Authenticate

cloudflared tunnel login

Setup tunnel

create credential file

cloudflared tunnel create <NAME> this will spit out a <UUID>.json file in your ~/.clouflared DIR

create config.yml

tunnel: <Tunnel-UUID>
credentials-file: /root/.cloudflared/<Tunnel-UUID>.json

ingress:
  - hostname: home.mydomainname.com
    service: http://localhost:65000
  - service: http_status:400

Add DNS to route traffic to tunnel

  • cloudflared tunnel route dns 856e737a-1b47-4037-9e3c-1f1c7a18eeab robinvarghese.com
  • cloudflared tunnel run

run the tunnel

cloudflared tunnel run <UUID or NAME>

verify

visiting the URL now should route traffic to your local service

Note:

Secure you application

Cloudflare Access determines who can reach your application by applying the Access policies you configure.

Cloudflare Zero Trust integrates with your organization’s identity provider to apply Zero Trust and Secure Web Gateway policies.

In this example, I’m using As an alternative to configuring an identity provider, Cloudflare Zero Trust can send a one-time PIN (OTP) to approved email addresses.

Create Access Group

A group is a set of rules that can be configured once and then quickly applied across many Access applications

Create Access Policy

An Access policy consists of an Action as well as rules which determine the scope of the action.

Verify

visiting the URL now should present you with a login page

Security Monitoring

You can monitor traffic in Analytics & Logs from the Cloudflare dashboard.

Additional Resources

Build with Hugo and other OSS