Skip to content

Instantly share code, notes, and snippets.

@mitanshu7
Last active July 30, 2025 18:19
Show Gist options
  • Save mitanshu7/fbee7bbd03ac30653a9fc1e81b1daa21 to your computer and use it in GitHub Desktop.
Save mitanshu7/fbee7bbd03ac30653a9fc1e81b1daa21 to your computer and use it in GitHub Desktop.

Install cloudflared:

In Termux, issue:

pkg upgrade
pkg install cloudflared

Creating a Cloudflare Tunnel

After installing Cloudflared, you need to create a Cloudflare tunnel.

  1. Visit https://one.dash.cloudflare.com.

  2. Navigate to Networks -> Tunnels -> Create a tunnel.

  3. Fill in a name you like and save the tunnel.

  4. Find the code block below: OR run the tunnel manually in your current terminal session only:

  5. Make note of the your <TOKEN> which comes after cloudflared tunnel run --token

Service Setup

Log Directory

  1. Create a folder for logging:
mkdir -p $PREFIX/var/service/cloudflared/log
  1. Symlink logger:
ln -sf $PREFIX/share/termux-services/svlogger $PREFIX/var/service/cloudflared/log/run

Service file

  1. Create the run file:
nano $PREFIX/var/service/cloudflared/run
  1. With the following contens:
#!/bin/bash
exec cloudflared tunnel run --token TOKEN

where TOKEN is from tunnel setup.

  1. Make it executable:
chmod +x $PREFIX/var/service/cloudflared/run

Start

  1. Start the Service:
sv up cloudflared
  1. You can also check the status with:
sv status cloudflared
  1. And enable service with:
sv-enable cloudflared

Start on Boot

Follow simple instructions provided on:

Termux:Boot

References

https://wiki.termux.com/wiki/Termux-services

https://smarden.org/runit/runscripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment