Running Cloudflare Tunnel on Your Server
Introduction
Cloudflare Tunnel (formerly Argo Tunnel) is a powerful tool for creating a secure connection between your server and Cloudflare without the need to open public ports. This guide describes the steps to install and configure Cloudflare Tunnel on various operating systems.
Setup Steps
1. Installing Cloudflare Tunnel (Cloudflared)
First, you need to install cloudflared
on your server. Depending on the operating system you are using, run the following commands:
For Ubuntu/Debian:
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared-linux-amd64.deb
For CentOS/RHEL:
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.rpm
sudo rpm -ivh cloudflared-linux-amd64.rpm
For macOS:
brew install cloudflare/cloudflare/cloudflared
2. Authorization in Cloudflare
To set up the tunnel, you need to log into your Cloudflare account. Run the following command for authorization:
cloudflared login
This command will open a browser window where you can log into your Cloudflare account. After successful authorization, a configuration file with a token will be created automatically.
3. Creating the Tunnel
After authorization, you can create the tunnel:
cloudflared tunnel create <tunnel_name>
This will create a unique tunnel with the name you specify. Save the tunnel ID — you’ll need it later.
4. Configuring DNS
Now you need to set up a DNS record to link your domain with the tunnel:
cloudflared tunnel route dns <tunnel_name> example.com
Replace example.com
with your actual domain.
5. Running the Tunnel
After configuring DNS, you can start the tunnel with the following command:
cloudflared tunnel run <tunnel_name>
6. Automating Tunnel Startup
To ensure the tunnel starts automatically when the system boots, configure a systemd service.
Create a file for systemd:
sudo nano /etc/systemd/system/cloudflared.service
Add the following code to the file:
[Unit]
Description=cloudflared
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/cloudflared tunnel run <tunnel_name>
Restart=on-failure
[Install]
WantedBy=multi-user.target
Save the file and close the editor.
Enable and start the service:
sudo systemctl enable cloudflared
sudo systemctl start cloudflared
Conclusion
Now your Cloudflare Tunnel starts automatically when the server boots, protecting it from external threats. This is a great way to enhance your server’s security by leveraging Cloudflare’s infrastructure.
- Our community Openode.XYZ OpeNode.xyz
- Aeza VPS (+15% on payment) Aeza.net
- Best EU hosting (+1 month free) Kamatera.com
- VPS hosting - 4vps.su (-10% discount!) 4VPS.su
- TG Channel TG-Channel Neonode.cc