Skip to content

fernvenue/cloudflare-ddns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare DDNS

cloudflare-ddns cloudflare-ddns cloudflare-ddns

A lightweight Cloudflare Dynamic DNS shell script.

Features

  • Support A and AAAA types.
  • Work with systemd timer.
  • Specific outbound interface.
  • Telegram notification.
  • Socks proxy for Cloudflare and Telegram APIs.
  • Use API token instead of global API key.
  • Update multiple records at the same time.

Usage

Get and fill in the information in the script:

curl -o /usr/local/bin/ddns.sh https://gitlab.com/fernvenue/cloudflare-ddns/-/raw/master/ddns.sh
vim /usr/local/bin/ddns.sh
  • CLOUDFLARE_API_KEY: Global API Key of your Cloudflare account.
  • CLOUDFLARE_RECORD_NAME: Record name, such as ddns.example.com.
  • CLOUDFLARE_RECORD_TYPE: Record type, can be A or AAAA.
  • CLOUDFLARE_USER_MAIL: The email address of your Cloudflare account.
  • CLOUDFLARE_ZONE_NAME: Zone name, such as example.com.
  • OUTBOUND_INTERFACE: Optional, used to specify the outbound interface.
  • SOCKS_ADDR: Optional, your socks server address, work for Cloudflare and Telegram APIs.
  • SOCKS_PORT: Optional, your socks server port.
  • TELEGRAM_BOT_ID: Optional, your telegram bot ID.
  • TELEGRAM_CHAT_ID: Optional, your telegram account or channel ID.
  • FORCE_UPDATE: Used to update anyway even if the IP unchanged, default is false.

You can also define parameters by flags:

  • -t = $CLOUDFLARE_API_TOKEN
  • -k = $CLOUDFLARE_API_KEY
  • -n = $CLOUDFLARE_RECORD_NAME
  • -r = $CLOUDFLARE_RECORD_TYPE
  • -u = $CLOUDFLARE_USER_MAIL
  • -z = $CLOUDFLARE_ZONE_NAME
  • -i = $OUTBOUND_INTERFACE
  • -a = $SOCKS_ADDR
  • -p = $SOCKS_PORT
  • -b = $TELEGRAM_BOT_ID
  • -c = $TELEGRAM_CHAT_ID
  • -f = $FORCE_UPDATE

Give permission and run. You must have resolved the target domain name to an address.

chmod +x /usr/local/bin/ddns.sh
/bin/bash /usr/local/bin/ddns.sh

Use systemd timer to automate.

curl -o /etc/systemd/system/ddns.service https://gitlab.com/fernvenue/cloudflare-ddns/-/raw/master/ddns.service
curl -o /etc/systemd/system/ddns.timer https://gitlab.com/fernvenue/cloudflare-ddns/-/raw/master/ddns.timer
systemctl enable ddns.timer
systemctl start ddns.timer
systemctl status ddns
What if I using non-systemd Unix system?

Maybe you can use cron to automate it, for example add */1 * * * * /usr/local/bin/ddns.sh to the cron configuration, and the configuration file for a user can be edited by calling crontab -e regardless of where the actual implementation stores this file.

Notice: if you changed any Cloudflare account information, make sure it is also changed in the script.

Multiple records?

Rename your /usr/local/bin/ddns.sh to /usr/local/bin/ddns-example1.sh, /usr/local/bin/ddns-example2.sh, then you can use [email protected] and [email protected] to update multiple records like:

systemctl start ddns@example1
systemctl start ddns@example2
...

By the way, multiple types for one single domain also supported and tested.

Links