May 18, 2018

Updating Cloudflare DNS entries programmatically

Using the cloudflare API and some code written by LINKIWI, we can update the DNS pointers on Cloudflare automatically. I am launching a separate container for this, just because I can.
NOTE: The python script only works with python 2

Install required software

sudo apt update && \
## Install build tools, python/pip
sudo apt install -y build-essential python-minimal python-pip && \
## Clean any leftover apps
sudo apt autoremove -y && \
## Upgrade pip, -H sets current users home as path
sudo -H pip install --upgrade pip &&\
# Clone repo and install
git clone && \
cd cloudflare-ddns-client && \
sudo make install && \
# Configure
cloudflare-ddns --configure

Follow the prompts to add your Cloudflare email and SECRET API key.

Test with an update

cloudflare-ddns --update-now

Schedule automatic updates

Using cron:
crontab -e
Add a line:
0 0 * * * /usr/local/bin/cloudflare-ddns --update-now > /dev/null 2>&1