Git Product home page Git Product logo

oznu / docker-cloudflare-ddns Goto Github PK

View Code? Open in Web Editor NEW
1.0K 25.0 204.0 87 KB

A small amd64/ARM/ARM64 Docker image that allows you to use CloudFlare as a DDNS / DynDNS Provider.

Home Page: https://hub.docker.com/r/oznu/cloudflare-ddns/

License: GNU General Public License v3.0

Shell 93.56% Dockerfile 6.44%
docker ddns dyndns cloudflare alpine-linux-image raspberry-pi arm amd64 arm64 aarch64 x86-64

docker-cloudflare-ddns's Introduction

Travis Docker Pulls

Docker CloudFlare DDNS

This small Alpine Linux based Docker image will allow you to use the free CloudFlare DNS Service as a Dynamic DNS Provider (DDNS).

This is a multi-arch image and will run on amd64, aarch64, and armhf devices, including the Raspberry Pi.

Image Variants

Image Tag Architecture OS Size
latest x64 Alpine Linux
armhf arm32v6 Alpine Linux
aarch64 arm64 Alpine Linux

Usage

Quick Setup:

docker run \
  -e API_KEY=xxxxxxx \
  -e ZONE=example.com \
  -e SUBDOMAIN=subdomain \
  oznu/cloudflare-ddns

Parameters

  • --restart=always - ensure the container restarts automatically after host reboot.
  • -e API_KEY - Your CloudFlare scoped API token. See the Creating a Cloudflare API token below. Required
    • API_KEY_FILE - Path to load your CloudFlare scoped API token from (e.g. a Docker secret). If both API_KEY_FILE and API_KEY are specified, API_KEY_FILE takes precedence.
  • -e ZONE - The DNS zone that DDNS updates should be applied to. Required
    • ZONE_FILE - Path to load your CloudFlare DNS Zone from (e.g. a Docker secret). If both ZONE_FILE and ZONE are specified, ZONE_FILE takes precedence.
  • -e SUBDOMAIN - A subdomain of the ZONE to write DNS changes to. If this is not supplied the root zone will be used.
    • SUBDOMAIN_FILE - Path to load your CloudFlare DNS Subdomain from (e.g. a Docker secret). If both SUBDOMAIN_FILE and SUBDOMAIN are specified, SUBDOMAIN_FILE takes precedence.

Optional Parameters

  • -e PROXIED - Set to true to make traffic go through the CloudFlare CDN. Defaults to false.
  • -e RRTYPE=A - Set to AAAA to use set IPv6 records instead of IPv4 records. Defaults to A for IPv4 records.
  • -e DELETE_ON_STOP - Set to true to have the dns record deleted when the container is stopped. Defaults to false.
  • -e INTERFACE=tun0 - Set to tun0 to have the IP pulled from a network interface named tun0. If this is not supplied the public IP will be used instead. Requires --network host run argument.
  • -e CUSTOM_LOOKUP_CMD="echo '1.1.1.1'" - Set to any shell command to run them and have the IP pulled from the standard output. Leave unset to use default IP address detection methods.
  • -e DNS_SERVER=10.0.0.2 - Set to the IP address of the DNS server you would like to use. Defaults to 1.1.1.1 otherwise.
  • -e CRON="@daily" - Set your own custom CRON value before the exec portion. Defaults to every 5 minutes - */5 * * * *.

Depreciated Parameters

  • -e EMAIL - Your CloudFlare email address when using an Account-level token. This variable MUST NOT be set when using a scoped API token.

Creating a Cloudflare API token

To create a CloudFlare API token for your DNS zone go to https://dash.cloudflare.com/profile/api-tokens and follow these steps:

  1. Click Create Token
  2. Provide the token a name, for example, cloudflare-ddns
  3. Grant the token the following permissions:
    • Zone - Zone Settings - Read
    • Zone - Zone - Read
    • Zone - DNS - Edit
  4. Set the zone resources to:
    • Include - All zones
  5. Complete the wizard and copy the generated token into the API_KEY variable for the container

Multiple Domains

If you need multiple records pointing to your public IP address you can create CNAME records in CloudFlare.

IPv6

If you're wanting to set IPv6 records set the envrionment variable RRTYPE=AAAA. You will also need to run docker with IPv6 support, or run the container with host networking enabled.

Docker Compose

If you prefer to use Docker Compose:

version: '2'
services:
  cloudflare-ddns:
    image: oznu/cloudflare-ddns:latest
    restart: always
    environment:
      - API_KEY=xxxxxxx
      - ZONE=example.com
      - SUBDOMAIN=subdomain
      - PROXIED=false

License

Copyright (C) 2017-2020 oznu

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

docker-cloudflare-ddns's People

Contributors

bmweller avatar dulanic avatar gamerlv avatar henrikbacher avatar jakewharton avatar jamct avatar johnluetke avatar omrishiv avatar oznu avatar purerosefallen avatar slothcroissant avatar tomaswarynyca avatar turowicz avatar zh99998 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-cloudflare-ddns's Issues

Does this change the IPv4 or IPv6 record?

I have a DS-Lite (dual stack) connection so that the IPv4 can't be used since I can't open IPv4 ports. How can I configure that this docker image only updates the IPv6 record in cloudflare?

Usage with several subdomains

I have tried using it with several subdomain, adding the "SUBDOMAIN" environment variable for each one, but it does only update one of them. Is this even a possibility? is it planned? if not I strongly suggest it.

Idea: Multi-arch images

I would suggest to switch to multi-arch docker images. They contain a manifest and can contain images for multiple architectures and the docker daemon will pull the correct one. With multi-arch you do not have to specify a tag like armhf.

could not resolve host: api.cloudflare.com

Hi,
i'm trying to set up the cf-ddns, but i get the following error message:

cf-ddns | curl: (6) Could not resolve host: api.cloudflare.com
cf-ddns | ----------------------------------------------------------------
cf-ddns | ERROR: Invalid CloudFlare Credentials - 000
cf-ddns | ----------------------------------------------------------------
cf-ddns | Make sure the API_KEY is correct.

docker-compose:

  cf-ddns:
    container_name: cf-ddns
    image: oznu/cloudflare-ddns:latest
    restart: unless-stopped
    environment:
      - API_KEY=$CLOUDFLARE_ZONE_API_TOKEN
      - ZONE=$DOMAINNAME_DEV
      - PROXIED=true
      - RRTYPE=A
      - DELETE_ON_STOP=false
      - DNS_SERVER=1.1.1.1

i've followed the tutorial and created the zone api token, then added that to the .env file. Any ideas as to why i could be getting this error? I can ping the url from my server

Add 2 zone

if i have 2 domain on cloudflare so can I add 2 zone?

ERROR: Failed To Get Public IPv4 Address

Hi, I'm running into the error message ERROR: Failed To Get Public IPv4 Address and I'm failing to find the reason why this is happening.

When I run the command used to get the IP address dig +short @resolver1.opendns.com myip.opendns.com A manually on the terminal, it works fine.

I'm running the container on a Ubuntu Server 18.04. I have tried setting the network mode to "host", as well using the default, but in both cases I get the same problem.

Any idea on how to debug this?

Multiple subdomains

Love the application! But how do i use it for multiple subdomains?

Comma separated doesn't seem to work :-)

Help with this error

Hello, I am trying to use this script but i always get error:
cloudflare-ddns_1 | ERROR: Failed to update CloudFlare DNS record example.ml from Y.Y.Y.Y to X.X.X.X

cloudflare-ddns_1 | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
cloudflare-ddns_1 | [s6-init] ensuring user provided files have correct perms...exited 0.
cloudflare-ddns_1 | [fix-attrs.d] applying ownership & permissions fixes...
cloudflare-ddns_1 | [fix-attrs.d] done.
cloudflare-ddns_1 | [cont-init.d] executing container initialization scripts...
cloudflare-ddns_1 | [cont-init.d] 30-cloudflare-setup: executing...
cloudflare-ddns_1 | DNS Zone: example.ml (189a359456502834321a727pxksl3h2s)
cloudflare-ddns_1 | DNS Record: example.ml (a97ba1f2d4161afc8f22c18a198kj12m)
cloudflare-ddns_1 | [cont-init.d] 30-cloudflare-setup: exited 0.
cloudflare-ddns_1 | [cont-init.d] 50-ddns: executing...
cloudflare-ddns_1 | Updating CloudFlare DNS record example.ml from Y.Y.Y.Y to X.X.X.X...
cloudflare-ddns_1 | ERROR: Failed to update CloudFlare DNS record example.ml from Y.Y.Y.Y to X.X.X.X
cloudflare-ddns_1 | [cont-init.d] 50-ddns: exited 0.
cloudflare-ddns_1 | [cont-init.d] done.
cloudflare-ddns_1 | [services.d] starting services
cloudflare-ddns_1 | Starting crond...
cloudflare-ddns_1 | crond: crond (busybox 1.31.1) started, log level 6
cloudflare-ddns_1 | [services.d] done.

multiple subdomains?

Love this container - was using a different one, was unaware of the new scoped API keys, got frustrated, found yours, setup was 30 seconds -- thank you.

Not necessary for me at the moment, but if you could consider making it possible to update multiple subdomains, I would appreciate it.

Add Support for Multiple Sub Domains

I understand the documentation and previously opened issues mention to use CNAME records, which works for most scenarios, however, there are restrictions with using them:

"MX and NS records cannot point to a CNAME record; they have to point to an A record (for IPv4) or an AAAA record (for IPv6)."

Adding the ability to A) recursively update all A records in a zone or B) specify more than one sub-domain (comma delimited) would help with this restriction versus the need to run multiple containers to stay in compliance.

Unraid email address field is mandatory

While there is a warning about NOT FILLING the email when using a scoped API in the documentation, the email field remains mandatory making it impossible to use it in Unraid with a scoped API.

What made me guess this is the problem on my setup was this message:

ERROR: Invalid CloudFlare Credentials - 400

Make sure the EMAIL and API_KEY variables are correct. You can
get your CloudFlare API Key here:
https://www.cloudflare.com/a/profile

If you are using a zone token please remove the EMAIL variable
from this container.

Consider change ipinfo.io

ipinfo.io is slow sometimes.

Consider change it to other api or provide an env for user to override is by assign env.

Zone not found in Cloudflare Acount

Hello,

i would setup Dyndns for my homeserver. But download your Setup and create an API Token and add a subdomain to the DNS List, but get this Error:


ERROR: Zone for domain.tld was not found in your CloudFlare Account

Make sure the ZONE variable is correct and the domain exists
in your CloudFlare account. You can add a new domain here:

https://www.cloudflare.com/a/add-site

the Docker command looks like

docker run
-e API_KEY=xxxxxxxxx
-e ZONE=domain.tld
-e SUBDOMAIN=daheim
oznu/cloudflare-ddns

whats wrong?

i hope you can help me

Rpi3: Dig not working

Hi,

Thanks for building this, however I don't get any IP back when running on RPI 3?

dig @resolver1.opendns.com myip.opendns.com A

yields nothing inside the container.

So i get all these lines:

Updating CloudFlare DNS recordmy.domain.com from XX.XXX.XXX.XX to ...
ERROR: Failed to update CloudFlare DNS record recordmy.domain.com from XX.XXX.XXX.XX to

Is it a bug in the Rpi 3 image?

multiple subdomains

many homelab use a reserve proxy to proxy local apps at home. For that, they will need multiple domains to update to the same home ip.

are you open to accept such merge request?

i was thinking maybe use SUBDOMAIN with comma separated?

-e SUBDOMAIN=subdomain1,subdomain2,subdomain3 \

Using CNAMEs for multiple domains

Hello, sorry for the repeated question, but I was hoping someone might be able to elaborate on how to use CNAMEs to make multiple domains work? I didn't have an issue adding several subdomains to my cloudflare account and managing them through nginx proxy manager, but when I make the secondary domain that I want to forward to the same IP as the first point at the first domain as a CNAME, I get a redirected too many times error. Does anything look off about my configuration?
nginxproxysettings
cfsettings2
cfsettings
(Just realized I switched the domain and site wording in one of the screenshots, hoping that doesn't make it too confusing to understand)
Any ideas would be greatly appreciated, thank you!

Explain cron option

It is not entirely clear from the documentation how the CRON-option is used.
I have tried - CRON="@hourly" in my docker-compose.yml (doesn't work and gives no error message) and I've tried -CRON="*/20 * * * *" which fails with a parsing error.

Any hints?

Specify different IP

I'd like to use a VPN IP instead of the public one. Could there be a config for interface name?

Proxied IP instead correct Ip

Good morning,
i'm trying to set it up on raspberry pi4, but it update the A record with the proxied ip instead the reeal wan ip. How do i solved it?

Thanks in advance
Shark

Invalid CloudFlare Credentials - 400

I am following the instructions perfectly, I had it working but then had to rebuild the container.

I have created a new API_KEY, pasted that in env using the variable "CLOUDFLAREAPIKEY" and yet I am still getting the above error. I have tried both creating a new token as well as using the global, and even changed the global with neither working.

I am at a loss as to what is going on.

Running in compose.

Support .cf, .ga, .gq, .ml, or .tk TLD (top-level domain)

When trying to run the API manually - I'm getting

{
  "error": "You cannot use this API for domains with a .cf, .ga, .gq, .ml, or .tk TLD (top-level domain). To configure the DNS settings for this domain, use the Cloudflare Dashboard."
}

And indeed i'm using a tk domain.

Is there any way to make this work?

Multiple zones?

Hi,

Is it possible to update multiple zones (Domains) with a single cloudflare-ddns instance?
At the moment I'm running multiple containers, 1 for each domain, which feels like a lot of overhead.

Is this something that could be added?

Fails to find correct IP address on BT (UK ISP)

Hi there, just recently this has started to fail for me. I've tracked it down to the following:

In app/clouflare.sh it tries a couple of methods. The first one:
dig +short @1.1.1.1 ch txt whoami.cloudflare | tr -d '"'
gives a response of "212.127.0.xxx" - which is a BT proxy, and not my own IP.
Obviously it 'succeeds' so it uses that IP to update Cloudflare DNS. which then fails as BT don't forward it on to me.

The other method:
curl -sf4 https://ipinfo.io | jq -r '.ip'
gives the true IP address of my internet connection (86.155.76.xxx)

The same is true of the IPv6 checks, as far as I can tell.

Obviously your script is just responding to what Cloudflare themselves send back, but is there any way to resolve this?

Multiple subdomains do not update

I have added multiple subdomains in unraid to this container, only the domain and last listed subdomain actually update.

I have added the subdomains as additional optional entries in unraid.

Is this a known issue or am I perhaps doing it wrong?

Thanks

Please add license

I was going to copy the cron setup for another container I'm building but without a license I cannot use your code. Not a huge problem since there's a million cron-y containers to copy from, but it's still nice to have a license so people know their rights to this work.

update period/conditions

not really an issue ...
could You please describe in the readme what is the dns update period / conditions?

Help troubleshooting this error

How can I fix this? I have been hardening Cloudflare condiguration, the firewall is not blocking anything but is possible that some setting (TLS 1.3, HTTPS force...) is breaking the IP sync?

[cont-init.d] 50-ddns: exited 0.
[cont-init.d] done.
[services.d] starting services
Starting crond...
crond: crond (busybox 1.31.1) started, log level 6
[services.d] done.
crond: USER root pid 248 cmd /etc/cont-init.d/50-ddns
Updating CloudFlare DNS record XXXX.from XXXXX to ;; connection timed out; no servers could be reached...
Updating CloudFlare DNS record XXXXXX from XXXXXXX to ;; connection timed out; no servers could be reached...
ERROR: Failed to update CloudFlare DNS record XXXXXXXX from XXXXXto ;; connection timed out; no servers could be reached

Add date and time

Adding date and time that the IP address changes would be a nice feature. Just for the times it changes.

Cloudflare API limitation when using .cf, .ga, .gq, .ml, or .tk TLDs

I just opened this issue to point out this limitation of the Cloudflare API:

https://support.cloudflare.com/hc/en-us/articles/360020296512-DNS-Troubleshooting-FAQ#h_84167303211544035341531

It's therefore impossible to use your scripts when using those TLDs.

Just discovered all of this after I extracted your script and understood how to run them on Postman. Then I got the real error message that was "blocking" your script (might be interesting to log that when the script fail).

I think it might be useful to put a disclaimer somewhere for people trying to setup something fast and using those TLDs

Updating AAAA record: "connection timed out; no servers could be reached"

I get the following error from my container designated to update my IPv6 with cloudflare: ERROR: Failed to update CloudFlare DNS record rhprivate.de from 2000:16b8:55e4:1300:4972:6e17:cb16:5dd3 to ;; connection timed out; no servers could be reached.

The container is created in docker-compose using the following config:

cloudflare_ddns_v6:
  container_name: cloudflare_ddns_v6
  image: oznu/cloudflare-ddns:latest
  restart: always
  network_mode: host
  environment:
    - ZONE=example.com
    - API_KEY=abcdefghijklmnopqrstuvwxyz
    - PROXIED=TRUE
    - RRTYPE=AAAA

I have a container using a nearly identical configuration for IPv4 updates that works mostly flawlessly; it's only problem: despite of the flag PROXIED=TRUE it always changes the A record to be unproxied.

Support Docker Secrets

In addition to passing the Cloudflare API key via an environment variable, it also should be able to be specified via a docker secret

(I plan on opening a PR for this change in due time)

release diifferent arch in same tag

could you release all arch in latest tag ?
docker support multiple arch in same tag. client can choose correct one automaticly.

release them in same tag makes deploy easier. I can use exact same config to deploy to all my nodes whatever its arch.

per-arch tags may still be kept for backwards compatibility

DNS record for XYZ.cf was not found in XYZ.cf zone. creating now... ERROR

I use unraid and installed the Cloudflare-ddns docker, but i am getting this error message.
I created a custo API Token, and pasted it in the config. Got the first error message, was asked to removed the email record, done that and this is the new error message I get in the log.
PS I replaced my actual address with XYZ

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 30-cloudflare-setup: executing...
DNS Zone: XYZ.cf (lotsofnumbers)
DNS record for 'XYZ.cf' was not found in XYZ.cf zone. Creating now...

ERROR: Failed to create DNS record 'XYZ.cf'


[cont-init.d] 30-cloudflare-setup: exited 1.
[cont-finish.d] executing container finish scripts...
[cont-finish.d] 50-remove-record: executing...
[cont-finish.d] 50-remove-record: exited 0.
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.

Not working when delete the record from the webUI after the docker initializing

This repo current work flow (maybe) is

  1. get the CF_RECORD_ID in the initial process.
  2. add the "ddns" cron task which use CF_RECORD_ID in the .conf file
    Let's think of this scenario :
    someone delete the record from the webUI or somewhere else ,
    then the ddns task just give a error while never refresh the CF_RECORD_ID.
    Is this a feature or a bug?

Cannot pull image

When trying to make the container through Docker Compose it gives an error when it tries to pull the image:
ERROR: pull access denied for onzu/cloudflare-ddns, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

I have used the 'docker login' command and logged in successfully and the image page is normally accessible on Docker Hub but I still get this error.

I can attach my docker-compose.yaml if you'd like but I doubt that the problem lies there.

Any help would be appreciated. Thanks in advance!

Docker secrets not working?

I could not pass Cloudflare api token via Docker secrets. With .env variables, this image works perfectly. With secrets, I get:

cf-ddns             | 2020-07-20T21:37:59.573918296Z ----------------------------------------------------------------
cf-ddns             | 2020-07-20T21:37:59.573951022Z ERROR: Invalid CloudFlare Credentials - 400
cf-ddns             | 2020-07-20T21:37:59.573958485Z ----------------------------------------------------------------
cf-ddns             | 2020-07-20T21:37:59.573964225Z Make sure the API_KEY is correct. You can

Here is my Docker Compose:

secrets:
  cloudflare_api_token:
    file: $SECRETSDIR/cloudflare_api_token

services:
  cf-ddns:
    container_name: cf-ddns
    image: oznu/cloudflare-ddns:latest
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    environment: 
      API_KEY_FILE: /run/secrets/cloudflare_api_token
      ZONE: $DOMAINNAME
      PROXIED: "true"
      RRTYPE: A
      DELETE_ON_STOP: "false"
      DNS_SERVER: 1.1.1.1
    secrets: # not working
      - cloudflare_api_token

Any help would be much appreciated.

Update subdomain only

It would be useful if an ability to only update a subdomain was made available. I didn't see any manner in which to not update the primary record/root domain.

Req: Add env variable to set A Record TTL

Hi

It looks like the TTL is always set to 3hrs, even if I manually set this in the Cloudflare Web UI to 2 minutes, the script resets it to 3hrs each time it updates.

Could you add an environmental variable, so we can specify what the TTL should be set too?

Thanks

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.