/CloudFlare-DDNS-Agent

A Dynamic DNS agent for CloudFlare written in Python.

Primary LanguagePythonGNU General Public License v2.0GPL-2.0

CloudFlare logo

CloudFlare DDNS Agent

A dynamic DNS agent for the CloudFlare API. Handy for home projects, development environments, or as part of a DNS-based HA/failover solution (more to come soon, think Serf). This allows you to use the benefits of CloudFlare (Hosted DNS, Security, Universal SSL, Apps, etc) without the requirement of a single static endpoint or IP.

Installation

Prerequisites

I plan on working these dependancies in to the DEB package, but for now you'll need:

  • Python (tested on 2.7.9)
    • requests (available via pip)
    • pyyaml (available via pip)
    • netifaces (available via pip - may need python-dev package)
Debian / Ubuntu

Simply installing the DEB package (found in the deb directory of this repo) as per below will drop everything in to place and add a cron job to run every hour by default, though this can be tweaked in /etc/cron.d/cloudflare-ddns-agent.

sudo dpkg -i cloudflare-ddns-agent_<version>.deb
Alternative / Other Distros
  1. Drop /etc/cloudflare-ddns-agent/agent.py in place, found in the deb/cloudflare-ddns-agent_<version>/etc/cloudflare-ddns-agent directory of this repo.
  2. Drop in a crontab. The example below runs every hour:
0 * * * * root /etc/cloudflare-ddns-agent/agent.py --config /etc/cloudflare-ddns-agent/config.yaml

Configuration

If you installed using the DEB package, the config file can be found at /etc/cloudflare-ddns-agent/config.yaml, please edit it as commented in the file.

vim /etc/cloudflare-ddns-agent/agent.conf

If you installed manually, you should copy the example config file found at /etc/cloudflare-ddns-agent/config.yaml.example to /etc/cloudflare-ddns-agent/config.yaml as shown below and edit it as commented in the file.

cp /etc/cloudflare-ddns-agent/config.yaml.example /etc/cloudflare-ddns-agent/config.yaml
vim /etc/cloudflare-ddns-agent/agent.conf

Should you wish to move the config file, you can tweak the --config argument in the cron job seen above.

Logs

By default, the script will log to syslog. In Debian/Ubuntu-based distributions for example, you can follow the logs as per below.

tail -f /var/log/syslog

Contribute

As always, I welcome any contributions. Just open a Pull Request.