Automatic dynamic DNS update with Cloudflare

I recently changed my ISP. Although I'm very happy now, there is one major drawback : I don't have any static IP anymore. Which is quite a pain, as I sometimes want to access some services running on my NAS, when I'm at work for example (subsonic, sabnzbd, gitlab, etc...)

I investigated some solutions which propose dynamic DNS, like, or OVH. But I was told on twitter than I could do such a thing, for free, with Cloudflare. As I already own an account on Cloudflare, it was the easy choice. And I don't regret I chose that path, as it was extremely easy to setup.

Here's how...

The process requires 2 scripts. I won't explain in detail, as I think they are self-explanatory by themselves, and the is well documented too.

The first script is a bash script, which is run on a Linux computer in my home network, scheduled using cron to be run every 30 minutes. This script calls a second script, in PHP, located on an online server, on which this blog is hosted.

Here is the bash script:

As you can see, I just reach the second script, using CURL. And the second script just gets the IP address of the caller, and updates the cloudflare DNS record if needed:


Hope this helps 🙂

Happy coding !