Connect to Cloudflare using DoH clients on Ubuntu

Last Updated on January 20, 2023 by Pupli

Download and install the cloudflared daemon

Or Download and install cloudflared via the Cloudflare Package Repository.

Ubuntu 20.04 LTS (Focal Fossa)

# Add cloudflare gpg key
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null

# Add this repo to your apt repositories
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] focal main' | sudo tee /etc/apt/sources.list.d/cloudflared.list

# install cloudflared
sudo apt-get update && sudo apt-get install cloudflared
cloudflared --version

Run without systemd

cloudflared proxy-dns
#cloudflared proxy-dns --port 5553

Run with systemd

sudo tee /etc/systemd/system/cloudflared-proxy-dns.service >/dev/null <<EOF
Description=DNS over HTTPS (DoH) proxy client

ExecStart=/usr/local/bin/cloudflared proxy-dns

sudo systemctl enable --now cloudflared-proxy-dns
sudo rm -f /etc/resolv.conf
echo nameserver | sudo tee /etc/resolv.conf >/dev/null

Finally, verify it locally with:

dig +short @ AAAA

Update cloudflared

cloudflared update