cloudflared in Azure
The purpose of this guide is to walk through some best practices for accessing private resources on Azure by deploying Cloudflare’s lightweight connector,
We will walk through how to initialize a service on a Linux VM in Azure, and route to it from another VM running
cloudflared. This deployment guide does not take into account routing beyond basic security groups and default VPCs.
Create your environment
Make sure you sign up for Azure and create a new subscription.
First, create your first resource group.
In addition, create your first keypair as well. You will be using the keypair to SSH into your Virtual Machine.
Next, define your inbound and outbound ports to the VM. If these ports are not configured properly, the solution will not function as intended. For testing purposes, we will leave access open.
Create two Ubuntu 20.04 LTS VMs, and make sure you record their internal IP addresses. Azure by default uses the
SSH into your Azure instance using the command line.$ cd Downloads$ ssh -i <private key path> [email protected]
sudo suto gain full admin rights to the Virtual Machine.
cloudflaredon your instance. In this example, we are running a Debian-based instance, so use the Debian package of
$ sudo mkdir -p --mode=0755 /usr/share/keyrings$ curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
- Add Cloudflare’s package signing key:
$ echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflared.list
- Add Cloudflare’s apt repo to your apt repositories:
$ sudo apt-get update && sudo apt-get install cloudflared
- Update repositories and install cloudflared:
Run the following command to authenticate
cloudflaredwith your Cloudflare account. The command will launch a browser window where you will be prompted to log in with your Cloudflare account and pick any zone you have added to Cloudflare.$ cloudflared tunnel login
Create a tunnel.$ cloudflared tunnel create Azure-01
Complete tunnel configuration
Make a directory for your configuration file.$ mkdir /etc/cloudflared$ cd /etc/cloudflared
Build a configuration file. Before moving forward and entering vim, copy your Tunnel ID and credentials path to a notepad.$ vim config.yml
ito begin editing the file and copy-paste the following settings in it.tunnel: <Tunnel ID/name>credentials-file: /root/.cloudflared/<Tunnel ID>.jsonprotocol: quicwarp-routing:enabled: truelogfile: /var/log/cloudflared.log#cloudflared to the origin debugloglevel: debug#cloudflared to cloudflare debugtransport-loglevel: info
escand then enter
:xto save and exit.
cloudflaredas a service.
$ cloudflared service install
$ systemctl start cloudflared
$ systemctl status cloudflared