How to expose Local host using Cloudflare tunnels ?

Arun PandeyArun Pandey
3 min read

For Debian based systems:

Manual Installation as followed:

Download the latest release:

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

Move the binary to a system directory:

sudo mv cloudflared /usr/local/bin/

Make it executable:

sudo chmod +x /usr/local/bin/cloudflared

Verify the installation:

cloudflared --version

Verify Installation:

cloudflared --version
# Test if cloudflare is working:
cloudflared tunnel --help

To remove warnings during installation:

# Possible warning:
# WRN The user running cloudflared process has a GID (group ID) 
# that is not within ping_group_range. You might need to add that user 
# to a group within that range, or instead update the range to encompass 
# a group the user is already in
# by modifying /proc/sys/net/ipv4/ping_group_range. 
# Otherwise cloudflared will not be able to ping 
# this network error="Group ID 1000 is not between ping group 1 to 0" 

The log output you're seeing from cloudflared indicates a couple of warnings and issues that need attention.
Let's break them down:

To modify the ping_group_range, run:

sudo sysctl -w net.ipv4.ping_group_range="0 65535"

To persist this change after a reboot, add it to the /etc/sysctl.conf file:

echo "net.ipv4.ping_group_range=0 65535" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

To create and manage tunnels on the Cloudflare dashboard, you need to follow these steps:

  1. Create a Cloudflare account

  2. Go to Dashboard > Websites

  3. Add your domain (domain is required for cloudflare to route its traffic from the localhost to a certain domain)

  4. If you do not have a domain ,You can buy a domain from Cloudflare itself or other DNS platforms such as GoDaddy, Google, Hostinger etc for less than 3$ for the first year

  5. Once you have a domain:

  6. Add the domain > Follow the guided steps to add Cloudflare as your Nameserver

  7. For adding Nameserver , go to your domain registrar (the platform from which you bought the domain)

  8. Remove the default nameserver and add the cloudflare’s nameserver as provided.

  9. In a few seconds the changes will be verified by Cloudflare account and you are set to go !!!


Creating a Cloudflare Tunnel : Step-wise Process

Prerequisite : Cloudflare should be installed on your system.

  1. Dashboard > Zero Trust

  2. For first Timers : you may need to create a Zero Trust Group for 0$( I mean free haha!!) by just entering your card and billing address details. Note this is just a formalty . No worries!

  3. Zero Trust > Networks > Tunnels > Create a Tunnel

  4. Choose tunnel type : Cloudflared / Warp Connector : Clouflared recommended

  5. Save > Configure:

  6. Choose environment : Windows/Mac/Debian/RedHat/Docker and Architecture:

    64bit/32bit .etc

Install and run Connector:

# If you already have cloudflared installed on your machine:
#This key is not complete for privacy purposes :Similar key wil be provided
sudo cloudflared service install eyJhIjoiNDExNGUyMzQ3ZDAwMTJlMWNjY
  1. Once your system is Connected : Congrats , your tunnel is Healthy and running !
# TO TRY AND TEST CLOUDFLARE:
cloudflared tunnel --url http://localhost:8080

Last Step: Create public host-name for your tunnel !

  1. You will be either directly prompted for public hostname or you can go to (3-dots) > Configure > Public Hostname and enter details:

Add :

1: Add domain
2: Add sub-domain
3: Type: https://
4: Route: localhost:8080

        • YOU ARE GOOD TO GO !!

0
Subscribe to my newsletter

Read articles from Arun Pandey directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arun Pandey
Arun Pandey