Git Product home page Git Product logo

ddns-cloudflare-bash-documentation's Introduction

Overview:

This document explains how to use the DDNS-Cloudflare-bash script to dynamically update DDNS with CloudFlare using API keys. I am using a bash script from this public Github repository DDNS-Cloudflare-Bash. This repository is simply the documentation of how to use the script in the DDNS-Cloudflare-Bash repository.

I am using this script to update a FQDN DNS record automagically through crontab on multiple Linux virtual private servers in different cloud regions.

Warning

I am using a TTL of 120 seconds on the FQDN record. You might see this TTL value as low. Feel free to change it when modifying the script variables.

Technical procedure:

Get an API token from Cloudflare:

Login to your Cloudflare account and navigate to the home page (websites tab):

Pasted image 20240406161905

Navigate to the DNS zone records:

Pasted image 20240406162027

Create the record you wish to modify with DDNS (the record must exist before using it with the script):

Note

You can add an invalid IP or a documentation IP in the type A record. Example: 198.51.100.1 (documentation range IP). Tip: Do not try to resolve the record before it updates.

Pasted image 20240406162203

Get the zone id from cloudflare:

Pasted image 20240406162737

Navigate to your profile to create an API key for the script:

Pasted image 20240406162939

Pasted image 20240406163000

Create a new API token:

Pasted image 20240406163034

Pasted image 20240406163100

Change the name of the token to something you will recognize in the future in case you need to create more tokens:

Pasted image 20240406163157 It should look similar to this at the end:

Pasted image 20240406163515

Create the token:

Pasted image 20240406163603 Make sure to copy the API token as you won't be able to view it again when you go to API tokens in your account:

Pasted image 20240406163700

Modify the variables in the script:

Add a user for the script (non-privileged user):

sudo adduser --disabled-password --gecos "" cloudflare-ddns

Switch to the new user:

sudo su cloudflare-ddns

Install the script in the non-privileged user directory:

mkdir $HOME/cloudflare-ddns/; cd $HOME/cloudflare-ddns/; \
wget https://raw.githubusercontent.com/fire1ce/DDNS-Cloudflare-Bash/main/update-cloudflare-dns.sh; \
wget https://raw.githubusercontent.com/fire1ce/DDNS-Cloudflare-Bash/main/update-cloudflare-dns.conf; \
chown $USER:$USER -R $HOME/cloudflare-ddns; chmod 600 update-cloudflare-dns.conf; \
chmod 700 update-cloudflare-dns.sh

Edit the config file to add your parameters to it:

nano $HOME/cloudflare-ddns/update-cloudflare-dns.conf

Modify the variables in the config file:

Important

You only need to modify the following variables:

  • dns_record: The fully qualified domain name of the record the script should update in your DNS zone (example: test.mydomain.com)
  • zoneid: The Zone ID you copied in the previous section.
  • cloudflare_zone_api_token: The API token you generated in the previous section.
  • proxied: Keep set to false if you need this record to be a DNS only record without Cloudflare proxy.
  • ttl: This is the Time To Live (TTL) for your DNS record. The minimum allowed by this script is 120 seconds (2 minutes).

Pasted image 20240406165642

run the script to test it:

./update-cloudflare-dns.sh ./update-cloudflare-dns.conf

If you do not get any errors proceed to adding a crontab for this script:

Important

Do not run this command with sudo. The whole point of creating a new user for the script is so that it runs as an unprivileged user.

crontab -e

Add the following line to the bottom of the user crontab:

* * * * * $HOME/cloudflare-ddns/update-cloudflare-dns.sh update-cloudflare-dns.conf

Save the crontab and exit from the user account:

exit

References:

Github DDNS-Cloudflare-Bash

ddns-cloudflare-bash-documentation's People

Contributors

diyaa59 avatar

Watchers

 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.