A CLI tool to use Cloudflare as a DDNS provider
Project description
cloudflareddns
A tiny command line utility for implementing DDNS with Cloudflare.
- Supports virtually any server that is capable of running Python
- Synology DiskStations supported
- Quick to install using
yum/dnf
orpip
Synopsis
Update DNS A record for foo.example.com
to 1.2.3.4
cloudflareddns --hostname foo.example.com --ip 1.2.3.4
Likewise, for an AAAA record:
cloudflareddns --hostname foo.example.com --ip 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Get all options by simply running cloudflareddns -h
:
usage: cloudflareddns [-h] [--email EMAIL] [--key KEY] [--hostname HOSTNAME]
[--ip IP] [--ttl TTL] [--verbose] [--version]
Update DDNS in Cloudflare.
optional arguments:
-h, --help show this help message and exit
--email EMAIL Cloudflare account email (omit if using API tokens)
--key KEY Cloudflare API key or token
--hostname HOSTNAME Hostname to set IP for
--ip IP The IP address
--ttl TTL TTL in seconds
--verbose
--version show program's version number and exit
When invoked without any options, cloudflareddns
will try to point the
FQDN (aka <hostname>.<domain-name>
of the machine it runs on to its public IP address (auto-detected).
Install and use with Synology DiskStations
You can configure a Synology DiskStation with CloudFlare DDNS.
It's worth noting that if your Synology DSM is recent enough, you can simply use Synology's own DDNS service, then create a CNAME
record at your domain that points to it. The downside to this solution, however, is extra DNS lookup required to resolve domain to IP.
Alternative solution is to use cloudflaredns
which ships with the necessary CLI interface for Synology compatibility: cloudflareddns-syno
.
Step 1. Access Synology via SSH
- Login to your DSM
- Go to Control Panel > Terminal & SNMP > Enable SSH service
- Use your client or commandline to access Synology. If you don't have any, I recommend you try out Putty for Windows.
- Use your Synology admin account to connect.
Step 2. Install cloudflareddns
If you're not a lazy man, checkout instructions on installing using virtualenv for this step. For quick setup instead:
curl https://bootstrap.pypa.io/get-pip.py | python
pip install cloudflareddns
Run the following command to add new DDNS provider:
cat >> /etc/ddns_provider.conf << 'EOF'
[USER_Cloudflare]
modulepath=/bin/cloudflareddns-syno
queryurl=https://www.cloudflare.com/
EOF
Step 3. Get Cloudflare parameters
It is recommended to use a Cloudflare API token. Check the wiki page for instructions on how to get an API token with the most secure permissions.
Alternatively, you can get Cloudflare global API key in your account settings.
Step 4. Setup DDNS
- Login to your DSM
- Go to Control Panel > External Access > DDNS > Add
- Select Cloudflare as service provider
- Enter your domain as hostname
- If using token authentication: enter
x
in the Username/Email, and API token as Password/Key. The requirement to putx
is due to Synology GUI's constraints not allowing for an empty field - If using global API key: enter your Cloudflare account as Username/Email, and API key as Password/Key
Installation for CentOS/RHEL 7, 8
sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm
sudo yum install cloudflareddns
Installation for other systems
Installing with pip
is easiest:
pip install cloudflareddns
Usage in Python scripts
from cloudflareddns import cloudflareddns
hostname = 'foo.example.com'
ip = '1.2.3.4'
if cloudflareddns.updateRecord(hostname, ip):
print('Record is OK')
...
Requires using environment variables (see tips below).
Specifying Cloudflare credentials
In non-Synology systems, you can store Cloudflare credentials in either environment variables or a configuration file.
Via configuration file
Create ~/.cloudflare/cloudflare.cfg
and put:
[CloudFlare]
email = user@example.com # Do not set if using an API Token
token = xxxxxxxxxxxxxxxxxxxxxxxxxxx
Via environment variables
You can put your Cloudflare credentials into the ~/.bashrc
file:
export CF_API_EMAIL="user@example.com" # Do not set if using an API Token
export CF_API_KEY="xxxxxx"
Don't forget to source ~/.bashrc
if you have just put credentials in there.
The cloudflareddns
will pick those up, so no need to pass --email
or --key
every time.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cloudflareddns-0.0.8.tar.gz
.
File metadata
- Download URL: cloudflareddns-0.0.8.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.2.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8406fa657c568b8d1df8afcadfffcff510751724506468d8fbe9b05053868aa3 |
|
MD5 | b2e959f69e8a963068871b9b1e4290e3 |
|
BLAKE2b-256 | 4d1b851f8fde1f0eda5b929cf55cb504eb2e04fe03bca491e5bbf068f24d03d2 |
File details
Details for the file cloudflareddns-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: cloudflareddns-0.0.8-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.2.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26676e4c5df6e8a761bc6590340ad279f96a42ac16959158df7a30ca07ceadae |
|
MD5 | 710843afd5197939dbe7c18bdd5b4c00 |
|
BLAKE2b-256 | fe66e100c272c8dfb757db09844da92873f7acefd9470ee2e2b94de61b557c93 |