Dynamic DNS on Cloudflare in 5 Minutes

Image credit: Unsplash

You will need the following to get dynamic DNS working on Cloudflare:

  • Cloudflare as your DNS provider. Migrating from your current DNS provider over to Cloudflare is easy and free whether you are using Godaddy, Namecheap or another one.

  • Get API token set up on Cloudflare.

  • Install cloudflare-cli.

Cloudflare API token

Cloudflare Token is preferred way over API key as token enables added security by allowing to specify access level with permissions and resources.

Token can be disabled when not in use.

When those are met, a one-liner like the following will update A record api.davidxiao.me with your public internet IP.

NOTE: If you are only using DDNS on Cloudflare and not using its CDN, remove --activate from the command below.

    $ env CF_API_KEY='your-own-cloudflare-token-NOT-api-key' \
        CF_API_DOMAIN='your-own-TLD-such-as-davidxiao.me' \
        cfcli --activate --type A edit your-subdomain-such-as-api.davidxiao.me \
        `curl -s 'https://ip.seeip.org/'` ;

Finally, put the code it into crontab will automate the process.


Related