Code Monkey home page Code Monkey logo

cloudflare-ddns's Introduction

cloudflare-ddns

Deprecated: Since I no longer use this I don't have much motivation to deal with issues/PRs. Feel free to check out Ethaligan's fork.

Introduction

A script for dynamically updating a CloudFlare DNS record. I use CloudFlare to host DNS for a domain and I wanted to point an A record in that domain to a host who's IP address changes occasionally. CloudFlare has an API to do this, so this happened.

Dependencies

You'll need a python interpreter and the following libraries:

You can install them with pip :

pip install -r requirements.txt

Usage

First, a few assumptions:

  • You have a CloudFlare account.
  • You're using CloudFlare to host DNS for a domain you own.
  • You have an A record in CloudFlare you intend to dynamically update.

To use this utility, create a copy of the config.yaml.template file (and remove .template from the filename). Create one template per each record / domain pair you intend to update. For example, I might have two configuration files: site_naked.yaml that updates the A record for the naked (no www prefix) domain site.not, and a second config, site_www.yaml that updates the A record for www.site.not.

To do a one-off update of your DNS record, simply run python cloudflare_ddns.py config_file_name.yaml from your terminal. The script will determine your public IP address and automatically update the CloudFlare DNS record along with it.

If the program encounters an issue while attempting to update CloudFlare's records, it will print the failure response CloudFlare returns. Check your configuration file for accurate information and try again.

Because dynamic IPs can change regularly, it's recommended that you run this utility periodically in the background to keep the CloudFlare record up-to-date.

Just add a line to your crontab and let cron run it for you at a regular interval.

# Every 15 minutes, check the current public IP, and update the A record on CloudFlare.
*/15 * * * * /path/to/code/cloudflare_ddns.py /path/to/code/config.yaml >> /var/log/cloudflare_ddns.log

This example will update the record every 15 minutes. You'll want to be sure that you insert the correct paths to reflect were the codebase is located. The redirection (>>) to append to a log file is optional, but handy for debugging if you notice the DNS record is not staying up-to-date. The script tries to print something useful to stdout any time it runs. If you find the "unchanged" messages too chatty, set quiet to true in the config and stdout will only get messages when the IP actually changed, or when there's an error.

If you want to learn more about the CloudFlare API, you can read on here.

Credits and Thanks

  • CloudFlare for having an API and otherwise generally being cool.
  • icanhazip.com for making grabbing your public IP from a script super easy.

cloudflare-ddns's People

Contributors

adrienbrignon avatar davejm avatar gazzer82 avatar jenswbe avatar kahn avatar pierrelvx avatar stephandollberg avatar sullivanmatt avatar thatjpk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.