Skip to content

A Bash script for automatic updating of Cloudflare DNS records with current public IPv4 and IPv6 addresses. Supports multiple domains, custom TTL and proxy settings, and optional Telegram notifications.

License

Notifications You must be signed in to change notification settings

Ate329/cloudflare-DDNS-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cloudflare DDNS Script

cloudflare-DDNS-script is a Bash script that automatically updates Cloudflare DNS records with your current external IP address. It supports both IPv4 and IPv6, and can update multiple domains simultaneously. This script is particularly useful for any user who has a dynamic IP address and wants to keep their Cloudflare DNS records up to date without having an additional DDNS provider.

Features

  • Updates both A (IPv4) and AAAA (IPv6) records
  • Supports multiple domains
  • Uses multiple sources to reliably fetch public IP addresses
  • Configurable Time To Live (TTL) and proxy settings
  • Optional Telegram notifications for successful updates
  • Detailed logging for easy troubleshooting (including API responses)

Prerequisites

  • Bash shell
  • curl command-line tool
  • A Cloudflare account with the domain(s) you want to update
  • Cloudflare API token with the necessary permissions

Installation

  1. Clone this repository:

    git clone https://github.com/Ate329/cloudflare-DDNS-script.git
    cd cloudflare-DDNS-script
  2. Make the script executable:

    chmod +x cloudflare-dns-update.sh
  3. Change the configurations in the configuration file named cloudflare-dns-update.conf in the same directory as the script based on your needs (see Configuration section below).

Configuration

The configuration is in a file named cloudflare-dns-update.conf with the following content:

zoneid="your_cloudflare_zone_id"
cloudflare_zone_api_token="your_cloudflare_api_token"
dns_record="example.com,subdomain.example.com"  # Comma-separated list of domains
ttl=1  # Or any value between 120 and 7200 (1 for automatic)
proxied=false  # Or true
notify_me_telegram="no"  # Or "yes"
telegram_bot_API_Token="your_telegram_bot_token"  # If using Telegram notifications
telegram_chat_id="your_telegram_chat_id"  # If using Telegram notifications

Replace the placeholder values with your actual Cloudflare and Telegram (if used) credentials.

This is where you can get your API Tokens: https://dash.cloudflare.com/profile/api-tokens
You should get the API Tokens by clicking the "Create Token" button instead of the API Keys.
(API Tokens and keys are DIFFERENT)

Usage

Run the script manually:

./cloudflare-dns-update.sh

For automatic updates, you can set up a cron job. For example, to run the script every 5 minutes:

Run the command:

crontab -e

And add the following (it means running the config once per 5 minutes):

*/5 * * * * /path/to/cloudflare-dns-update.sh

For NixOS

It's a better idea to do this declaratively in NixOS.

In your configuration.nix (the default configuration file for NixOS):

  services.cron = {
    enable = true;
    systemCronJobs = [
        
      "* * * * *   [username]   /your/path/to/cloudflare-dns-update.sh"
    ];
  };

Example:

  services.cron = {
    enable = true;
    systemCronJobs = [
        
      "* * * * *   guest   /home/guest/cloudflare-DDNS-script/cloudflare-dns-update.sh"
    ];
  };

And you might need to install cron as well:

  environment.systemPackages = [
    pkgs.cron
  ];

Tested on my raspberrypi 4 with NixOS installed and it was working perfectly.

Logging

The script creates a log file named cloudflare-dns-update.log in the same directory. This log file contains information about each run of the script, including any errors encountered.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This script is provided as-is, without any warranties. Always test thoroughly before using in a production environment.

Acknowledgments

  • Thanks to Cloudflare for providing a robust API.
  • Thanks to various public IP services for enabling reliable IP address retrieval.
  • Thanks to ChatGPT for generating this README as well.
  • Motivated by DDNS-Cloudflare-Bash

About

A Bash script for automatic updating of Cloudflare DNS records with current public IPv4 and IPv6 addresses. Supports multiple domains, custom TTL and proxy settings, and optional Telegram notifications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages