Using cloudflare command line interface

You can easily change anything in your Cloudflare dashboard from the linux command line.

Install the cli

npm install -g cloudflare-cli

By default cfcli will look for “.cfcli.yml” in your home directory (you can also pass in a config file with -c). So create this:

emacs ~/.cfcli.yml
defaults:
    token: fcbe3cbb2894cb5f1871c89222851bf1
    email: [email protected]
    domain: oneofyourdomains.com

The token is actually the Cloudflare Global API key which you can retrieve from My Settings>Account>API Key menu.
All options:

NAME
    cfcli - Interact with cloudflare from the command line
 
SYNOPSIS
    cfcli [options] command [parameters]
 
OPTIONS:
    -c  --config    Path to yml file with config defaults (defaults to ~/.cfcli.yml
    -e  --email     Email of your cloudflare account
    -k  --token     Token for your cloudflare account
    -u  --account   Choose one of your named cloudflare accounts from .cfcli.yml
    -d  --domain    Domain to operate on
    -a  --activate  Activate cloudflare after creating record (for addrecord)
    -f  --format    Format when printing records (csv or table)
    -t  --type      Type of record (for dns record functions)
    -p  --priority  Set priority when adding a record (MX or SRV)
    -l  --ttl       Set ttl on add or edit (120 - 86400 seconds, or 1 for auto)
    -h  --help      Display help
 
COMMANDS:
    add <name> <content>
        Add a DNS record. Use -a to activate cf after creation
    devmode on|off
        Toggle development mode on/off
    disable <name> [content]
        Disable cloudflare caching for given record and optionally specific value
    edit <name> <content>
        Edit a DNS record.
    enable <name> [content]
        Enable cloudflare caching for given record and optionally specific value
    find <name> [content]
        Find a record with given name and optionally specific value
    ls
        List dns records for the domain
    purge [url]
        Purge file at given url or all files if no url given
    rm <name> [content]
        Remove record with given name and optionally specific value
    zones
        List domains in your cloudflare account

Provided examples:

Add a new A record (mail) and activate cloudflare (-a)

cfcli -a -t A add mail 8.8.8.8 
Edit a record (mail) and set the TTL

cfcli --ttl 120 edit  mail 8.8.8.8
Add an SRV record (then 3 numbers are priority, weight and port respectively)

cfcli -t SRV add _sip._tcp.example.com 1 1 1 example.com
Remove all records with the name test

cfcli rm test
Remove record with name test and value 1.1.1.1

cfcli rm test 1.1.1.1
Enable cloudflare for any records that match test

cfcli enable test
Enable cloudflare for a record test with the value test.com

cfcli enable test test.com
Export domain records for test.com to csv

cfcli -d test.com -f csv listrecords > test.csv
Purge a single file from cache

cfcli -d test.com purge http://test.com/script.js
Enable dev mode for test.com domain

cfcli -d test.com devmode on

My examples:

cfcli zones
┌──────────────────────────────────────────────────┬────────────────────┬──────────┬────────────────────────────────────────┐
│ Name                                             │ Plan               │ Active   │ ID                                     │
├──────────────────────────────────────────────────┼────────────────────┼──────────┼────────────────────────────────────────┤
│ mysite.com                                       │ Free Website       │ active   │ f81d72ad7d2a4af5e50060148389ede8       │
├──────────────────────────────────────────────────┼────────────────────┼──────────┼────────────────────────────────────────┤

Adding a CNAME record

cfcli -d eyrie.in -a -t CNAME add testrecord "joomla.com"
Explanation
-d : Work on this domain
-a : Activate the record
-t : type of DNS record
add : Add this record

Output:

Added CNAME record testrecord.eyrie.in -> joomla.com

Editing a DNS record:

cfcli -d eyrie.in -a -t CNAME edit testrecord "joomla.com"

List cloudflare records for a domain:

cfcli -d eyrie.in ls

Listing in comma seperated value (CSV) format:

cfcli -d eyrie.in ls -f csv

To export to text file:

cfcli -d eyrie.in ls -f csv > eyrie.in.csv