Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ate329/cloudflare-ddns-script
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.
https://github.com/ate329/cloudflare-ddns-script
bash-script cloudflare cloudflare-api cloudflare-dns cloudflare-dns-records ddns ddns-script ddns-updater dns-record linux linux-scripts nixos raspberry-pi raspberrypi
Last synced: 3 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/ate329/cloudflare-ddns-script
- Owner: Ate329
- License: mit
- Created: 2024-07-18T16:33:23.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-09-09T14:43:06.000Z (5 months ago)
- Last Synced: 2024-10-11T23:22:29.345Z (4 months ago)
- Topics: bash-script, cloudflare, cloudflare-api, cloudflare-dns, cloudflare-dns-records, ddns, ddns-script, ddns-updater, dns-record, linux, linux-scripts, nixos, raspberry-pi, raspberrypi
- Language: Shell
- Homepage:
- Size: 40 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```bash
git clone https://github.com/Ate329/cloudflare-DDNS-script.git
cd cloudflare-DDNS-script
```2. Make the script executable:
```bash
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:
```bash
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:
```bash
./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:
```bash
crontab -e
```And add the following (it means running the config once per 5 minutes):
```bash
*/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):
```nix
services.cron = {
enable = true;
systemCronJobs = [
"* * * * * [username] /your/path/to/cloudflare-dns-update.sh"
];
};
```Example:
```nix
services.cron = {
enable = true;
systemCronJobs = [
"* * * * * guest /home/guest/cloudflare-DDNS-script/cloudflare-dns-update.sh"
];
};
```And you might need to install cron as well:
```nix
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](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](https://github.com/fire1ce/DDNS-Cloudflare-Bash)