Bash script to update IPv4 and IPv6 records in Cloudflare. Update with WAN or LAN IP.
Based on this project: DDNS-Cloudflare-Bash.
- Bash Script for most Linux, Unix distributions and MacOS.
- Choose any source IP address to update external or internal (WAN/LAN) for ech domain.
- For multiply lan interfaces like Wifi, Docker Networks and Bridges the script will automatically detects the primary Interface by priority.
- Cloudflare's options proxy and TTL configurable via the config file for each domain.
- Optional Telegram Notifications
- curl
- Cloudflare api-token with ZONE-DNS-EDIT Permissions
- DNS Record must be pre created in web interface (WIP: Create record if no exist)
To create a CloudFlare API token for your DNS zone go to cloudflare-api-token-url and follow these steps:
- Click Create Token
- Select Create Custom Token
- Provide the token a name, for example,
example.com-dns-zone-readonly
- Grant the token the following permissions:
- Zone - DNS - Edit
- Set the zone resources to:
- Include - Specific Zone -
example.com
- Include - Specific Zone -
- Complete the wizard and use the generated token at the
CLOUDFLARE_API_TOKEN
variable for the container
You can place the script at any location manually.
MacOS: Don't use the /usr/local/bin/ for the script location. Create a separate folder under your user path /Users/${USER}
The automatic install examples below will place the script at /usr/local/bin/
wget https://raw.githubusercontent.com/jmrplens/DyDNS_Cloudflare_IPv4-6/main/update-cloudflare-records.sh
sudo chmod +x update-cloudflare-records.sh
sudo mv update-cloudflare-records.sh /usr/local/bin/update-cloudflare-records
You can use default config file update-cloudflare-records.yaml or pass your own config file as parameter to script.
wget https://raw.githubusercontent.com/jmrplens/DyDNS_Cloudflare_IPv4-6/main/update-cloudflare-records.yaml
Place the config file in the directory as the update-cloudflare-dns for above example at /usr/local/bin/
sudo mv update-cloudflare-records.yaml /usr/local/bin/update-cloudflare-records.yaml
domains:
- name: example.com
ip_type: external
ipv4: true
ipv6: true
proxied: true
ttl: auto
settings:
cloudflare:
- zone_id: #########
- zone_api_token: ########
misc:
- create_if_no_exist: false
notifications:
telegram:
enabled: false
bot_token: token
chat_id: id
Multiple domains is supported:
domains:
- name: example.com
ip_type: external
ipv4: true
ipv6: true
proxied: true
ttl: auto
- name: example2.com
ip_type: external
ipv4: true
ipv6: true
proxied: true
ttl: auto
- name: ..........
.........
Option | Example | Description |
---|---|---|
name | example.com | Domain name. Required |
ip_type | external | Which IP should be used for the record: internal/external. Optional (default: external) |
ipv4 | true | Update IPv4 DNS Record: true/false. Optional (default: true) |
ipv6 | true | Update IPv6 DNS Record: true/false. Optional (default: true) |
proxied | true | Use Cloudflare proxy on dns record: true/false. Optional (default: true) |
ttl | 3600 | 120-7200 in seconds or auto. Optional (default: auto) |
Option | Example | Description |
---|---|---|
zone_api_token | token | Cloudflare API Token KEEP IT PRIVATE!!!! |
zone_id | id | Cloudflare's Zone ID |
Option | Example | Description |
---|---|---|
create_if_no_exist | false | Not yet implemented |
Option | Example | Description |
---|---|---|
enabled | true | Use Telegram notifications: true/false. |
bot_token | token | Telegram's Bot API Token |
chat_id | id | Chat ID of the bot |
When placed in /usr/local/bin/
update-cloudflare-records
With your config file (need to be placed in same folder)
update-cloudflare-records yoru_config.conf
You can run the script via crontab
crontab -e
Example | Code |
Run every minute |
* * * * * /usr/local/bin/update-cloudflare-records |
Run every minute with your specific config file |
* * * * * /usr/local/bin/update-cloudflare-records myconfig.yaml |
Run every every 2 minutes |
*/2 * * * * /usr/local/bin/update-cloudflare-records |
Run at boot |
@reboot /usr/local/bin/update-cloudflare-records |
Run 1 minute after boot |
@reboot sleep 60 && /usr/local/bin/update-cloudflare-records |
This Script will create a log file with only the last run information Log file will be located at the script's location.
Example:
/usr/local/bin/update-cloudflare-records.log