How to Install and Configure Cloudflared on Linux

RMAG news

To install the cloudflared package on a Linux system, follow these steps:

Step 1: Update Your Package List

First, make sure your package list is up to date:

sudo apt-get update

Step 2: Download the Cloudflared Package

Go to the Cloudflare download page to get the latest version of cloudflared for your architecture. Alternatively, you can use the following command to download it directly (assuming you are using a 64-bit system):

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

Step 3: Install the Package

Install the downloaded package using the dpkg command:

sudo dpkg -i cloudflared-linux-amd64.deb

If there are any missing dependencies, fix them with:

sudo apt-get install -f

Step 4: Verify the Installation

Check if cloudflared is installed correctly by running:

cloudflared –version

Optional: Configuring Cloudflared as a Service

To set up cloudflared as a system service, follow these steps:

Create a configuration file:

Create a directory for the configuration file if it doesn’t exist:

sudo mkdir -p /etc/cloudflared

Create a configuration file /etc/cloudflared/config.yml with your desired settings. For example:

tunnel: your-tunnel-id
credentials-file: /path/to/your/credentials-file.json

ingress:
hostname: example.com
service: http://localhost:8000
service: http_status:404

Create a systemd Service Unit File:

Create a file at /etc/systemd/system/cloudflared.service with the following content:

[Unit]
Description=cloudflared Tunnel
After=network.target

[Service]
TimeoutStartSec=0
Type=notify
ExecStart=/usr/local/bin/cloudflared –config /etc/cloudflared/config.yml run
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

Enable and Start the Service:

Enable the service so that it starts on boot:

sudo systemctl enable cloudflared

Start the service:

sudo systemctl start cloudflared

Check the Service Status:

Verify that the service is running correctly:

sudo systemctl status cloudflared

This setup should ensure that cloudflared is installed and running on your Linux system.