Giter Club home page Giter Club logo

cf-ddns.sh's Introduction

cf-ddns.sh

cf-ddns.sh is a minimal, easy to use DDNS client for automatically updating CloudFlare's DNS service to point to your current IP. It was written with portability in mind, so it will run in most POSIX-like shells. (BASH, BusyBox, etc.) It can even work on many embedded systems, like consumer-grade routers.

cf-ddns.sh is based on v4 of the CloudFlare API.

Prerequisites

  • POSIX-ish environment (Linux, OS X, BSD, etc.)
  • curl (requires HTTPS support)

Install

Download to your system and create a cron job to run the script with your parameters on an interval.

Usage

cf-ddns.sh [OPTION] -e=EMAIL -a=APIKEY -z=ZONENAME -r=RECORDNAME

Or:

cf-ddns.sh [OPTION] -e=EMAIL -a=APIKEY -y=ZONEID -q=RECORDID

Required parameters

-e=, --email= CloudFlare account email
-a=, --apikey= CloudFlare account API key
-z=, --zonename= Zone name in the form of subdomain.domain.tld
OR
-y=, --zoneid= CloudFlare zone ID
-r=, --recordname= Record name in the form of subdomain.domain.tld
OR
-q=, --recordid= CloudFlare record ID

Options

-f, --force Force a DNS update, even if WAN IP hasn't changed
-t, --test Test action without updating DNS record
-w=, --wan= Manually specify WAN IP address, skip detection
--use-lan-ip Use LAN IP instead of WAN, when updating
--get-wan-ip Determine the WAN IP, print it, and exit
--get-zone-id Print zone ID corresponding to zone name and exit
--get-record-id Print record ID corresponding to record name and exit
-h, --help Print this message and exit

cf-ddns.sh's People

Contributors

gstuartj avatar raduab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cf-ddns.sh's Issues

Incorrect record retrieved if nslookup is available on the system

The first time I ran the script, I got warnings about nslookup not being installed (since it wasn't). However, the result thrown back by the test was correct. Then, I installed dns-utils and reran the program, and a different IP address was retrieved by the script. This IP address was incorrect.

I am running Debian Testing.

Doesn't add record

Hi, great script thanks for writing it.
I need to automatically add dns records for new servers, but I was getting update failed error when running. Looking through the code and Cloudflares API guide it looks like the script can only update an existing record (it uses PUT), I added an if check to see if it's adding/updating then use either POST or PUT depending on the action.

I genuinely dont understand GIT to submit my changes back :) so I'll just put it below:

# Perform record update
api_dns_update=`${curl_command} -s -X PUT "${cf_api_url}/zones/${zone_id}/dns_records/${record_id}" -H "X-Auth-Email: ${cf_email}" -H "X-Auth-Key: ${cf_api_key}" -H "Content-Type: application/json" --data "{\"id\":\"${zone_id}\",\"type\":\"A\",\"name\":\"${record_name}\",\"content\":\"${WAN_addr}\"}"`

Changed to:

# Perform record update
 if [ -z $record_id ]; then
     api_dns_update=`${curl_command} -s -X POST "${cf_api_url}/zones/${zone_id}/dns_records" -H "X-Auth-Email: ${cf_email}" -H "X-Auth-Key: ${cf_api_key}" -H "Content-Type: application/json" --data "{\"id\":\"${zone_id}\",\"type\":\"A\",\"name\":\"${record_name}\",\"content\":\"${WAN_addr}\"}"`
 else
     api_dns_update=`${curl_command} -s -X PUT "${cf_api_url}/zones/${zone_id}/dns_records/${record_id}" -H "X-Auth-Email: ${cf_email}" -H "X-Auth-Key: ${cf_api_key}" -H "Content-Type: application/json" --data "{\"id\":\"${zone_id}\",\"type\":\"A\",\"name\":\"${record_name}\",\"content\":\"${WAN_addr}\"}"`
 fi

Thanks again for writing it, I hope this helps someone.

Turning off proxy

When running script it turns off Proxy (Turns cloud to grey) How can i stop this?

Thanks
dan

ifconfig.io is down

external_WAN_query='https://ifconfig.io/ip'

The site is currently down, which breaks the script.

Testing on DD-WRT v3 - some minor issues

Found that using named zone and named record generates errors.
due to curl version issue.... have no idea what version of curl is on there...
busybox ash is the cli -

due to the boxes being very small - there is not https certs installed sure that is a space issue.

so curl -k will allow the https to be insecure - not sure if there is a a work around for that.
However removing zone and record Id and only using names:

I believe its tied again to limited busybox / version of grep.

./cf-ddns.sh --get-zone-id
grep: unrecognized option: P
BusyBox v1.28.4 (2018-06-29 12:24:51 CEST) multi-call binary.

shows another issue in grep it looks like.
this simple change from -Po to -Eo doesn't work

so the regex is no bueno for busybox ash which is pretty common in most dd-wrt / router installs..

if you manually enter the records the script works great...

well except it thinks the LAN ip is the same as external... probably again due to different flavors of DD-WRT.

anyway pretty close - only issue I could find so far is that Grep is REALLY incompatible due to not being able to parse perl regex.

Add options for interface name and A vs AAAA

Hello,

it would be nice to be able to specify which interface name to get IP addresses from, and whether you want IPv4 or IPv6 (or both). For example:

  • -i=eno1
  • -t=A or -t=AAAA

I whipped up this script as a wrapper because cf-ddns.sh was getting an IPv6 address from the wrong interface (LAN) tried to update it to an A record:

#!/bin/sh

ip=`ip addr show eno1 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1`
email=""
api_key=""
zone=""
record=""

sh /usr/local/cf-ddns.sh/cf-ddns.sh    \
  -w=$ip                               \
  -e=$email                            \
  -a=$api_key                          \
  -z=$zone                             \
  -r=$record

a lot of issues ,not stable

{"success":false,"errors":[{"code":6003,"message":"Invalid request headers","error_chain":[{"code":6103,"message":"Invalid format for X-Auth-Key header"}]}],"messages":[],"result":null}

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.