DDNS on a Raspberry Pi using the Cloudflare API (Dynamic DNS)

About this video

This is a step-by-step tutorial on setting up Dynamic DNS for a home lab using a Raspberry Pi (or any Linux machine inside the home network) and the Cloudflare API. The problem is that most home public IP addresses are dynamic and change, so a domain pointed at the home network breaks unless DNS is updated manually. The solution is a script on the Pi that automatically updates Cloudflare. Requirements are a regular domain name (the creator notes Cloudflare’s API will not work with Freenom top-level domains like .tk or .ga), a free Cloudflare account with the domain’s nameservers pointed to Cloudflare, and the Linux machine. The walkthrough SSHs into the Pi, becomes root, installs git, clones the Cloudflare DDNS updater repository linked in the description, copies cloudflare-template.sh to cloudflare.sh to preserve the template, and edits it in nano. Fields filled from Cloudflare are the account authentication email, the Global API Key (viewed under API Tokens), the Zone ID from the domain overview page, and the record name — the root domain or a subdomain to point home. To test, he first points that DNS record at 8.8.8.8 in Cloudflare’s DNS page, makes the script executable with chmod +x, runs ./cloudflare.sh, and confirms on refresh that the record changed to his public IP. Automation is done with crontab -e, adding a line to run the bash script every minute (*/1 followed by asterisks for hour, day, month and weekday), then reloading the cron service. For multiple subdomains, he shows adding the extra names as CNAME records pointing at the one updated record, rather than changing the script. A sponsored segment for Private Internet Access is included mid-video.

Key takeaways

  • Dynamic DNS solves the problem of a changing home public IP breaking a domain pointed at a home lab
  • You need a regular domain on Cloudflare, a free Cloudflare account, and a Linux machine inside the home network
  • Edit a copy of the template script with your auth email, Global API Key, Zone ID and record name
  • Test by pointing the record at 8.8.8.8 first, then confirm the script replaces it with your public IP
  • Automate with crontab every minute; add extra subdomains as CNAMEs to the updated record

Episode details: published July 14, 2021 · 11:44 long. Summary written by Self Growth Videos from the episode itself. Business results and any income figures mentioned are NetworkChuck’s own claims, shared for education — they are not typical or guaranteed.


← Previous: how to get remote access to your hacking targets // reverse shells with netcat (Windows and Linux!!) · Next: i built a Raspberry Pi SUPER COMPUTER!! // ft. Kubernetes (k3s cluster w/ Rancher) →

All NetworkChuck videos · NetworkChuck profile · NetworkChuck on YouTube

Sister brand · Vacation Club Promo

All-inclusive resort stays from $435

Qualified couples: promotional Mexico and Caribbean packages at real resorts. Short presentation during your stay — enjoy the rest of the trip.

Qualifications apply · presentation during stay · no purchase required

Subscribe YouTube Suggest