Discover how to configure Cloudflare Tunnel on Ubuntu 24.04. Our CloudFlare Support team is ready to assist.
Step-by-Step: Configure Cloudflare Tunnel on Ubuntu 24.04
Managing secure access to web services hosted on private servers is a complex task. Traditional solutions often require exposing our server to the internet via public IPs and configuring complex reverse proxies or firewall rules.
Fortunately, Cloudflare Tunnels simplifies this process by creating a secure, encrypted outbound connection between our server and Cloudflare’s global network. This eliminates the need to open ports or expose our infrastructure.
Today, we will walk through what Cloudflare Tunnels are, their benefits, and how to set one up on an Ubuntu 24.04 LTS server.
An Overview:
What Is a Cloudflare Tunnel?
Cloudflare Tunnel establishes a secure, outbound-only connection from the origin server to the Cloudflare network using the `cloudflared` daemon. This setup eliminates the need for public IP addresses or traditional port forwarding, reducing attack surfaces and streamlining deployment.
If you’re working with Cloudflare Access and encounter issues like inactive status, check out this article for a detailed troubleshooting guide.
How it works: The server initiates the connection to Cloudflare’s edge network via `cloudflared`, securely tunneling incoming HTTP/HTTPS traffic directly to our internal services.
Key Benefits
- Eliminates the need to open ports on your server.
- The origin server remains invisible to the public internet, protecting it from DDoS, port scanning, and other attacks.
- Avoids the complexity of reverse proxies and manual firewall configurations.
- All requests are routed through Cloudflare’s secure edge network.
- Combine tunnels with Cloudflare Access for user-level authentication.
Want to enhance performance further? Learn how to set up Cloudflare CDN with Magento 2 for faster global content delivery.
Use Case: Running on Ubuntu 24.04 LTS
For those running applications on Ubuntu 24.04 LTS, Cloudflare Tunnel provides enterprise-grade security with minimal configuration.
Prerequisites
Before setting up Cloudflare Tunnel, we need:
- A server running Ubuntu 24.04 LTS
- Administrative (sudo) access
- A Cloudflare account
- A domain registered and configured in Cloudflare
Also, update the system with this command:
sudo apt update && sudo apt upgrade -y
Step-by-Step: Installing and Configuring Cloudflare Tunnel
- First, download and install the latest `cloudflared` binary:
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared-linux-amd64.deb - Then, authenticate `cloudflared` with the Cloudflare account:
cloudflared tunnel login
We will receive a URL. Open it in a browser, log in to our Cloudflare account, and authorize the tunnel.A certificate file will be downloaded to /root/.cloudflared/cert.pem .
- Next, create a named tunnel:
cloudflared tunnel create ourtunnelname
A credentials file (JSON) will be saved in the same directory.
- Then, create and edit the configuration file:
nano /root/.cloudflared/config.yml
- Now, add the following configuration, replacing with the actual tunnel ID and credentials file:
tunnel: b8294c45-9cd1-40fe-b8f1-519da5d8dfd9
credentials-file: /root/.cloudflared/b8294c45-9cd1-40fe-b8f1-519da5d8dfd9.json
ingress:
- hostname: test.ourdomain.com
service: http://localhost:80
- service: http_status:404
If you’re implementing tunnels with HTTPS, you may also need to configure SSL certificates. This article explains how to effectively manage SSL for Argo Tunnels.
- Then, create a CNAME record that maps the domain to the tunnel:
cloudflared tunnel route dns b8294c45-9cd1-40fe-b8f1-519da5d8dfd9 test.ourdomain.com
- Now, move the config file to the default service directory:
sudo mkdir /etc/cloudflared/
sudo mv /root/.cloudflared/config.yml /etc/cloudflared/ - Next, install and run the tunnel as a systemd service:
cloudflared service install
sudo systemctl start cloudflared
sudo systemctl enable cloudflared
- Finally, verify the service is running:
sudo systemctl status cloudflared
We should see output indicating the tunnel is active and running.
Bonus: Host Multiple Services
If we want to route multiple domains through the same tunnel, create additional CNAME records and update the config:
cloudflared tunnel route dns test2.ourdomain.com
Then, update the `config.yml` file:
ingress:
- hostname: test.yourdomain.com
service: http://localhost:80
- hostname: test2.yourdomain.com
service: http://localhost:8080
- service: http_status:404
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
By following this guide, we can install, configure, and run Cloudflare Tunnel on Ubuntu 24.04 LTS.
In short, our Support Engineers demonstrated how to configure Cloudflare Tunnel on Ubuntu 24.04.
0 Comments