DEV Community

Sh Raj
Sh Raj

Posted on

How to Install and Configure Cloudflared on Linux

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Step 3: Install the Package

Install the downloaded package using the dpkg command:

sudo dpkg -i cloudflared-linux-amd64.deb
Enter fullscreen mode Exit fullscreen mode

If there are any missing dependencies, fix them with:

sudo apt-get install -f
Enter fullscreen mode Exit fullscreen mode

Step 4: Verify the Installation

Check if cloudflared is installed correctly by running:

cloudflared --version
Enter fullscreen mode Exit fullscreen mode

Optional: Configuring Cloudflared as a Service

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

  1. Create a configuration file:

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

   sudo mkdir -p /etc/cloudflared
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. Enable and Start the Service:

Enable the service so that it starts on boot:

   sudo systemctl enable cloudflared
Enter fullscreen mode Exit fullscreen mode

Start the service:

   sudo systemctl start cloudflared
Enter fullscreen mode Exit fullscreen mode
  1. Check the Service Status:

Verify that the service is running correctly:

   sudo systemctl status cloudflared
Enter fullscreen mode Exit fullscreen mode

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

Top comments (1)

Collapse
 
zxxngod profile image
Zan XX

Thank you you’re the best πŸ–€πŸŒŒπŸ†•πŸ†’β™ΎοΈ