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
- Log in to Cloudflare
- Go to My Profile โ API Tokens
- 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