title: Setting up Cloudflare DDNS on Ubuntu using cloudflare-ddns-updater date: 2026-03-20 draft: false tags:

  • cloudflare
  • ddns
  • homelab
  • ubuntu
  • automation

๐Ÿงฉ Problem

My home network uses a dynamic public IP address, which changes periodically. This breaks remote access to my self-hosted services.


๐Ÿ› ๏ธ Solution Overview

I used an open-source tool (cloudflare-ddns-updater) to automatically update my Cloudflare DNS records whenever my public IP changes.


๐Ÿ”ง Environment

  • Ubuntu Server (DDNS host)
  • Cloudflare domain
  • API Token with DNS edit permissions
  • Git installed

๐Ÿš€ Step 1: Create Cloudflare API Token

  1. Log in to Cloudflare
  2. Go to My Profile โ†’ API Tokens
  3. Create a token with:
    • Zone โ†’ DNS โ†’ Edit
    • Zone Resources โ†’ Specific Zone (your domain)

Save the token securely.


๐ŸŒ Step 2: Get Required IDs

You need:

  • Zone ID
  • DNS Record ID

You can find these from:

  • Cloudflare dashboard
  • Or via API calls

๐Ÿ“ฆ Step 3: Clone the Repository

sudo apt update
sudo apt install git -y

git clone https://github.com/K0p1-Git/cloudflare-ddns-updater.git
cd cloudflare-ddns-updater

โš™๏ธ Step 4: Configure the Script

Edit the configuration file:

nano cloudflare-template.sh

Update the following values:

CF_API_TOKEN=your_api_token
CF_ZONE_ID=your_zone_id
CF_RECORD_ID=your_record_id
CF_RECORD_NAME=home.yourdomain.com

๐Ÿงช Step 5: Run the Script Manually

bash update.sh

This will:

  • Check your current public IP
  • Compare with Cloudflare DNS
  • Update if there is a change

โฑ๏ธ Step 6: Automate with Cron

Edit crontab:

crontab -e

Add:

*/1 * * * * cd /home/youruser/cloudflare-ddns-updater && bash update.sh >> ddns.log 2>&1

๐Ÿ” Step 7: Verify Updates

Check logs:

cat ddns.log

Or verify DNS:

dig home.yourdomain.com

๐Ÿ“Š Result

  • DNS automatically updates when IP changes
  • Stable domain access to homelab services
  • Fully automated with minimal overhead

โš ๏ธ Challenges Faced

  • Incorrect API token permissions
  • Wrong Zone ID / Record ID
  • Script path issues in cron
  • Logs not generating initially

๐Ÿง  What I Learned

  • Practical use of APIs for automation
  • How DNS updates work behind the scenes
  • Importance of logging in automation scripts

๐Ÿš€ Future Improvements

  • Use Cloudflare Tunnel (no port forwarding required)
  • Add alerting (email/Discord) on IP change
  • Run script as a systemd service instead of cron