Install and set up Cloudflare Tunnel (remotely-managed) on a Linux machine, without having to access Cloudflare Dashboard.
This is particularly useful for automated workflows.
- Login to your cloudflare account
- Go to API Tokens
- Create Token > Create Custom Token
- It requires permission to
Account/Cloudflare Tunnel - Edit
andZones/<yourzone>/DNS - Edit
- Enter other values as appropriate (Tip: Because the API Key is used only during installation, we strongly recommend that you set the expiration as short as possible)
- Continue to summary > Create Token, and Copy your API Key
- Go to Dashboard Home
- Go to your website(zone) page
- In the API section, copy the Zone ID and Account ID (Tip: The API section is located at the bottom right or bottom of the page)
Execute the following command:
You will be asked for API Key, Account ID, Zone ID, hostname (e.g. example.srgr0.com), and service (e.g. http://127.0.0.1:8888).
wget https://raw.githubusercontent.com/Srgr0/cloudflaretunnel_installer/main/installer.sh
sudo chmod +x ./installer.sh
sudo ./installer.sh
The difference is in how the tunnels are managed. For remotely-managed tunnels, the tunnel configuration is stored in cloudflare and can be viewed and modified from the Cloudflare Zero Trust Dashboard. For locally-managed tunnels, the tunnel configuration is stored in a file on the local server. Remotely-managed tunnel, which allows both domain and tunnel management on the Dashboard, is recommended.
The Dashboard and this script work in the same way and are not significantly different. However, while the dashboard requires manual user operation, this script can automate its execution.