跳到正文

Cloudflare DDNS Updater

不活跃
K0p1-Git/cloudflare-ddns-updater

轻量可靠的 Bash 脚本,在动态 IP 变化时自动更新 Cloudflare DNS 记录,让你的自托管服务始终可以通过域名访问。

在 GitHub 查看
星标
1847
Fork
440
关注
1847
未关闭 Issue
4

该介绍目前仅提供英文版本。

A simple and effective BASH script for automatic Cloudflare DNS record updates

Overview

Cloudflare DDNS Updater is a lightweight BASH script designed to automatically update your Cloudflare DNS records when your home or server IP address changes. This solution enables you to access your self-hosted services through a consistent domain name, even with a dynamic IP address from your ISP.

Key Features

  • 🔄 Automatic IP Detection: Detects changes in your public IP address
  • 🔧 Easy Configuration: Simple setup with minimal requirements
  • 🔒 API Token Support: Uses secure Cloudflare API tokens
  • 🌐 IPv4 & IPv6 Support: Works with both address types
  • 📝 Detailed Logging: Optional logging for troubleshooting
  • ⏱️ Cron-Friendly: Easily scheduled through cron jobs
  • 📨 Email Notifications: Optional alerts for IP changes
  • 🛡️ Multiple Domain Support: Update records across multiple zones

How It Works

The script performs these basic steps:

  1. Detects your current public IP address
  2. Compares it with the existing DNS record in Cloudflare
  3. Updates the record only when a change is detected
  4. Provides optional logging and notifications

Quick Start

Prerequisites

  • A Cloudflare account with at least one domain
  • A server or device running a Linux distribution
  • Basic BASH and command-line knowledge

Setup Instructions

  1. Download the script:

    curl -o cloudflare-ddns-updater.sh https://raw.githubusercontent.com/K0p1-Git/cloudflare-ddns-updater/master/cloudflare-ddns-updater.sh
    chmod +x cloudflare-ddns-updater.sh
  2. Configure your settings: Edit the script and update the configuration variables:

    • Cloudflare API token or Global API key
    • Your email address
    • Zone ID (domain)
    • DNS record name
    • Record type (A for IPv4, AAAA for IPv6)
  3. Run the script manually:

    ./cloudflare-ddns-updater.sh
  4. Set up automatic updates: Add a cron job to run the script periodically (e.g., every 5 minutes):

    */5 * * * * /path/to/cloudflare-ddns-updater.sh

Advanced Configuration

Email Notifications

Configure email settings to receive notifications when your IP changes:

# Email Settings
EMAIL_TO="[email protected]"
SUBJECT="Cloudflare DDNS Updater - IP Changed"

IPv6 Support

The script can be configured to update AAAA records for IPv6 addresses:

# Set to either A or AAAA
TYPE="AAAA"

Proxied Records

Control whether Cloudflare should proxy your traffic:

# Set to either true or false
PROXIED="true"

Use Cases

  • Home Lab Access: Access your home lab services from anywhere
  • Self-hosted Websites: Keep your website accessible with a changing IP
  • Remote Access: Maintain remote access to your devices
  • Game Servers: Host multiplayer game servers with a consistent domain
  • IoT Devices: Connect to your smart home devices remotely

Troubleshooting

  • Verify API Permissions: Ensure your API token has the correct zone permissions
  • Check Logs: Enable logging to identify potential issues
  • IP Detection: If IP detection fails, try alternative IP services in the script
  • DNS Propagation: Allow time for DNS changes to propagate globally

Requirements

  • BASH shell
  • curl or wget for HTTP requests
  • Basic Linux command-line knowledge
  • Cloudflare account with domain

License

This project is licensed under the MIT License.


A reliable solution for maintaining access to your services with a dynamic IP address.

按共同分类和标签排序的同类开源项目。

全部网络项目 →