Skip to content

Repository files navigation

Cloudflare DNS Updater

A Bash-based script to automatically update Cloudflare DNS records with your dynamic public IP address. Designed for efficiency and compatibility across Linux and macOS, and on Windows through Git Bash, MSYS2 or WSL.

Binaries Build Lint Check Tests

📖 Full documentation (English & Español): jmrplens.github.io/Cloudflare-DNS-Updater

Key Features

  • Batch Updates: Updates multiple DNS records in a single API call to minimize latency.
  • IP Detection:
    • Local: Detects global IPv6 addresses directly from the network interface.
    • External: Uses multiple fallback services (icanhazip, ifconfig.co, ipify) for redundancy.
  • Cross-Platform: Standalone binaries for Linux and macOS; on Windows, run from source under Git Bash, MSYS2 or WSL.
  • Notifications: Support for Telegram and Discord alerts upon IP changes.
  • Logging: Rotation-aware logs with optional debug mode.
  • Safety: Lockfile mechanism to prevent concurrent executions.

Installation

Option A: Standalone Binaries

Pre-compiled binaries bundle Bash and jq, so neither has to be installed on the host. curl and the usual command line tools (tar, sed, grep) are taken from the system.

  1. Download the latest release for your OS from the Releases Page.
    • Linux: cf-updater-linux-x86_64 (Intel/AMD) or cf-updater-linux-aarch64 (ARM/Raspberry Pi)
    • macOS: cf-updater-macos-x86_64 (Intel) or cf-updater-macos-aarch64 (Apple Silicon)
  2. Make Executable (Linux/macOS only):
    chmod +x cf-updater-linux-x86_64

Option B: Run from Source

If you prefer to run the script directly, ensure you have the required dependencies installed.

Dependencies:

Setup:

  1. Clone the repository:
    git clone https://github.com/jmrplens/Cloudflare-DNS-Updater.git
    cd Cloudflare-DNS-Updater
  2. Run the script:
    ./cloudflare-dns-updater.sh

Configuration

Copy the example configuration file and edit it with your details.

cp config.example.yaml cloudflare-dns.yaml
chmod 600 cloudflare-dns.yaml   # it contains your API token

Example cloudflare-dns.yaml:

---
cloudflare:
  zone_id: "your_zone_id_here"
  api_token: "your_api_token_here"

options:
  proxied: true   # Default for all domains: true = Orange Cloud (Proxy), false = DNS only
  ttl: 1          # Default TTL: 1 = Auto, or value in seconds (60-86400)
  interface: ""   # Optional: network interface for local IPv6 detection (e.g., "eth0")

domains:
  # Update both IPv4 and IPv6 (default)
  - name: "example.com"

  # Update only IPv4
  - name: "ipv4.example.com"
    ip_type: "ipv4"

  # Update only IPv6
  - name: "ipv6.example.com"
    ip_type: "ipv6"

  # Override the global proxy/TTL defaults
  - name: "direct.example.com"
    proxied: false
    ttl: 300

notifications:
  telegram:
    enabled: false
    bot_token: ""
    chat_id: ""

  discord:
    enabled: false
    webhook_url: ""

Usage Examples

CLI Options

  • -h, --help: Show usage help.
  • -s, --silent: Run without console output (ideal for Cron).
  • -d, --debug: Enable verbose logging and API response output.
  • -f, --force: Force an update even if the IP has not changed.

Linux / macOS Automation (Cron)

To run the updater every 5 minutes:

  1. Open crontab: crontab -e
  2. Add the line:
    */5 * * * * /path/to/cf-updater-linux-x86_64 --silent

Windows Automation (Task Scheduler)

There is no Windows binary: this program needs a real Bash, and no single-file static Bash exists for Windows. Run it from source under Git Bash, MSYS2 or WSL.

  1. Open Task Scheduler and "Create Basic Task".
  2. Name it "Cloudflare DNS Updater".
  3. Set Trigger to Daily, then in properties set "Repeat task every X minutes" (e.g., 5 or 10).
  4. Action: Start a Program.
  5. Program/script: C:\Program Files\Git\bin\bash.exe
  6. Add arguments: -c "/c/path/to/Cloudflare-DNS-Updater/cloudflare-dns-updater.sh --silent"

Development

For detailed instructions on building, testing, and understanding the project structure, please see CONTRIBUTING.md.

Quick start for building binaries:

  1. Validate Code:
    ./tools/validate.sh
  2. Build All Binaries:
    ./tools/build-all.sh --all
    Artifacts will be created in the dist/ directory.

About

Bash script to update, create or delete IPv4 and IPv6 records in @cloudflare.

Topics

Resources

Contributing

Security policy

Stars

28 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Contributors

Languages