• Stars
    star
    249
  • Rank 162,987 (Top 4 %)
  • Language
    Shell
  • Created about 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cloudflare DDNS bash Script for most Linux distributions and MacOS. Choose any source IP address to update external or internal (WAN/LAN). Cloudflare's options proxy and TTL configurable via the parameters.

DDNS Cloudflare Bash Script

contributions welcome MIT license

About

  • DDNS Cloudflare Bash Script for most Linux, Unix distributions and MacOS.
  • Choose any source IP address to update external or internal (WAN/LAN).
  • 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.
  • Optional Telegram Notifications

Requirements

  • curl
  • Cloudflare api-token with ZONE-DNS-EDIT Permissions
  • DNS Record must be pre created (api-token should only edit dns records)

Creating Cloudflare API Token

To create a CloudFlare API token for your DNS zone go to https://dash.cloudflare.com/profile/api-tokens and follow these steps:

  1. Click Create Token
  2. Select Create Custom Token
  3. Provide the token a name, for example, example.com-dns-zone-readonly
  4. Grant the token the following permissions:
    • Zone - DNS - Edit
  5. Set the zone resources to:
    • Include - Specific Zone - example.com
  6. Complete the wizard and use the generated token at the CLOUDFLARE_API_TOKEN variable for the container

Installation

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/fire1ce/DDNS-Cloudflare-Bash/main/update-cloudflare-dns.sh
sudo chmod +x update-cloudflare-dns.sh
sudo mv update-cloudflare-dns.sh /usr/local/bin/update-cloudflare-dns

Config file

You can use default config file update-cloudflare-dns.conf or pass your own config file as parameter to script.

wget https://raw.githubusercontent.com/fire1ce/DDNS-Cloudflare-Bash/main/update-cloudflare-dns.conf

Place the config file in the directory as the update-cloudflare-dns for above example at /usr/local/bin/

sudo mv update-cloudflare-dns.conf /usr/local/bin/update-cloudflare-dns.conf

Config Parameters

Option Example Description
what_ip internal Which IP should be used for the record: internal/external
dns_record ddns.example.com DNS A record which will be updated, you can pass multiple A records separated by comma
cloudflare_zone_api_token ChangeMe Cloudflare API Token KEEP IT PRIVATE!!!!
zoneid ChangeMe Cloudflare's Zone ID
proxied false Use Cloudflare proxy on dns record true/false
ttl 120 120-7200 in seconds or 1 for Auto

Optional Notifications Parameters

Option Example Description
notify_me_telegram yes Use Telegram notifications yes/no
telegram_chat_id ChangeMe Chat ID of the bot
telegram_bot_API_Token ChangeMe Telegram's Bot API Token

Running The Script

When placed in /usr/local/bin/

update-cloudflare-dns

With your config file (need to be placed in same folder)

update-cloudflare-dns yoru_config.conf

Or manually

<path>/.update-cloudflare-dns.sh

Automation With Crontab

You can run the script via crontab

crontab -e

Examples

Run every minute

* * * * * /usr/local/bin/update-cloudflare-dns

Run with your specific config file

* * * * * /usr/local/bin/update-cloudflare-dns myconfig.conf

Run every 2 minutes

*/2 * * * * /usr/local/bin/update-cloudflare-dns

Run at boot

@reboot /usr/local/bin/update-cloudflare-dns

Run 1 minute after boot

@reboot sleep 60 && /usr/local/bin/update-cloudflare-dns

Run at 08:00

0 8 * * * /usr/local/bin/update-cloudflare-dns

Logs

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-dns.log

Limitations

  • Does not support IPv6

License

MIT License

Copyright© 3os.org @2020

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

3os.org

Collocation of technical documentation and guides for devops, developers, pentesters, systems administrators and other IT professionals website
HTML
134
star
2

eicar-standard-antivirus-test-files

eicar standard antivirus test files
DIGITAL Command Language
129
star
3

DDNS-Cloudflare-PowerShell

Cloudflare DDNS PowerShell Script for Windows OS. Choose any source IP address to update external or internal (WAN/LAN). Cloudflare's options proxy and TTL configurable via the parameters.
PowerShell
73
star
4

BrewUp

BrewUp - macOS Auto Update Homebrew
Shell
48
star
5

UDM-Persistent-SSH-Keys

UDMP Persistence SSH Keys
Shell
22
star
6

raspberry-pi-power-button

Control Raspberry pi with physically attached button. Wake, Power Off, and Restart (Double Press) . Python3 script runs as a service with easy installation.
Python
22
star
7

UDM-Cloudflare-DDNS

Cloudflare DDNS container for UDM
Shell
12
star
8

raspberry-pi-pir-motion-display-control

Raspberry Pi display control based on motion (PIR) sensor using GPIO
Python
9
star
9

mkdocs-embed-external-markdown

MkDocs Embed External Markdown plugin that allow to inject section or all full markdown content from a given url. The goal is to show different markdown from different sources inside your MkDocs project.
Python
9
star
10

UDM-Failover-Telegram-Notifications

UDMP Failover Telegram Notifications
Shell
7
star
11

sonic-pad

Creality Sonic Pad - Ender 3 s1 Pro Configurations
5
star
12

klipper-ender3-s1

Klipper & Mainsail for Creality Ender 3 s1 Pro 3D Printer
Shell
4
star
13

sysupgrade-debian

Is a simple bash script to run full full-upgrade update and cleanup.
Shell
4
star
14

pihole-cloudflare-dns-sync

Lightweight Container to be used in conjunction with a Pi-hole instance to sync the DNS records of Cloudflare DNS to Pi-hole local DNS.
Python
3
star
15

UDM-Better-Fan-Speeds

Overrides UDM fan speeds with users predefined
Shell
2
star
16

interactive-dhcp-renew

Shell
1
star
17

cloudflare-watcher

Python
1
star
18

sendEmail-windwos-v1.56

sendEmail for windwos
Perl
1
star
19

ptScans

automation for pt scans like nikto, nmap, goBuster, dirb with output files for logging
Shell
1
star
20

macos-screenlock-api

HTTP server response 0 if macos's screen is locked, 1 if unlocked.
Python
1
star
21

wingetup

Powershell script to automate the process of updateing Winget packages and exporting the installed winget packages json dump to github
PowerShell
1
star