English / [简体中文]
- ✅ Supports IPv4 (A record) and IPv6 (AAAA record)
- ✅ Automatically obtains ZONE_ID, no manual configuration required
- ✅ Automatically creates non-existent DNS records
- ✅ Supports specifying network interfaces
- ✅ Supports Cloudflare CDN proxy mode
- ✅ Automatically cleans up old logs (keeps 7 days)
- ✅ Configuration file management for easy parameter modification
curl- Used for sending HTTP requestsjq- Used for parsing JSON data
Directly run the script, which will automatically create a configuration file config.json:
bash cloudflare_ddns.shEdit the automatically generated config.json file and fill in the following parameters:
{
"TOKEN": "xxxx", // Cloudflare API Token
"DOMAIN": "xxx.xxx.com", // Domain to be resolved (e.g., www.example.com)
"NETWORK_INTERFACE": "", // Optional: Specify network interface (e.g., eth0, wlan0)
"CDN_PROXIED": false, // Whether to enable Cloudflare CDN proxy (true/false)
"TYPE": "AAAA" // IP type: A (IPv4) or AAAA (IPv6)
}Obtain it by visiting Cloudflare API Tokens. Requirements:
- Grant DNS modification permissions
- Grant read permissions for ZONE and Zone Settings
Use crontab to set up a scheduled task to execute the script:
# Edit crontab
crontab -e
# Run every 5 minutes (adjust the interval as needed)
*/5 * * * * /path/to/cloudflare_ddns.sh >/dev/null 2>&1- Log files are located in the
log/directory - Automatically cleans up logs older than 7 days
- Log format:
modification_log_YYYY-MM-DD.log
- Ensure the script has execution permissions:
chmod +x cloudflare_ddns.sh - The first run will automatically create a configuration file and log directory
- If the configuration file is modified, the script will automatically use the new configuration next time it runs
- If you need to force an update of DNS records, you can delete the
data.jsonfile and rerun the script - Some systems may encounter curl certificate issues; for OpenWrt, you can use
opkg install --force-reinstall ca-bundleto fix it