Skip to content

Instantly share code, notes, and snippets.

@shrmnk
Created July 6, 2023 16:36
Show Gist options
  • Save shrmnk/16d1cf21c78f7d81fb2a9ff329120f3d to your computer and use it in GitHub Desktop.
Save shrmnk/16d1cf21c78f7d81fb2a9ff329120f3d to your computer and use it in GitHub Desktop.
Running multiple cloudflared tunnels with token

Running multiple Cloudflare Tunnel services

This is a simple guide to setting up multiple cloudflared services (via systemctl). Useful if you have to run tunnels authenticated by different accounts and want to let each account handle their tunneling configurations via the Dashboard/UI.

  1. (optional, so its easy to clone the service definition file) Setup your first tunnel using the standard sudo cloudflared service install <token> command
  2. cd into the folder containing the cloudflared.service definition (usually /etc/systemd/system or /usr/lib/systemd/system
  3. Duplicate the existing cloudflared.service into another file with a unique name e.g. sudo cp cloudflared.service cloudflared-b.service
  4. Open up your new service cloudflared-b.service in your favorite text editor
  5. Change the token within the ExecStart= line to match your second tunnel
  6. Change the service Description= to match your service filename
  7. Save your changes
  8. Start the new service with sudo systemctl start cloudflared-b
  9. Check that the service is all-ok with sudo systemctl status cloudflared-b
  10. You are good to go (rinse and repeat for more tunnels)

Sample cloudflared.service file:

(In case you want to create each service definition by hand)

[Unit]
Description=cloudflared
After=network.target

[Service]
TimeoutStartSec=0
Type=notify
ExecStart=/usr/bin/cloudflared --no-autoupdate tunnel run --token TOKEN_HERE
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment