Auto updates dynamic IP via Cloudflare API (DDNS)

Dynamic IP vs Fixed IP

Dynamic IP

A dynamic IP address is a temporary address for devices connected to a network that continually changes over time. An Internet Protocol (IP) address is a number used by computers to identify host and network interfaces, as well as different locations on a network.

Fixed IP

A static IP address is also known as a fixed IP address or dedicated IP address, and is the opposite of a dynamic IP address. A computer with an assigned static IP address uses the same IP address when connecting to the Internet

What is DDNS (Dynamic DNS)

Each device that connects to the internet has an Internet Protocol (IP) address, and websites on web servers are no different. However, when you navigate to a website, you do not type in a series of numbers, which would be its IP address. Instead, you type in the name of the site, such as “” The mechanism that associates webpages with their IP addresses is called the Domain Name System or DNS.

However, as more and more devices connect to the internet, a system is needed to automatically assign IP addresses to domain names. In this way, IP addresses that were no longer in use could be recycled and given to new devices. A dynamic DNS (DDNS) service does this for you, mapping the name of your website to your IP address.

So in this tutorial, we will use Cloudflare as our DDNS provider. We will write a script which auto check machine external IP every 5 minutes and update it through Cloudflare CLI.

How can we keep IP up to date

Download script below and assign executable permission

current directory: /root
View raw code at:

wget && chmod +x

Configure domain properties

config name: /root/update-cloudflare-dns.conf

## Filename: update-cloudflare-dns.conf

## Which IP should be used for the record: internal/external
## Internal interface will be chosen automaticly as a primary default interface

## DNS A record to be updated

## Cloudflare's Zone ID

## Api token can be generated from here
## Cloudflare Zone API Token

## Use Cloudflare proxy on dns record true/false

## 60-300 in seconds or 1 for Aut

## Telegram Notifications yes/no (only sent if DNS is updated)

## Telegram Chat ID

## Telegram Bot API Key

Setup cron job auto check and update every 5 minutes

nano /etc/crontab

*/5 * * * *  root /root/

Save it and restart crontab service

service cron restart

Final Result

==> 2022-06-14 13:51:52
==> External IP is:
==> DNS record of is: . Trying to update...
==> Success!
==> DNS Record Updated To:, ttl: 60, proxied: false

Source code credit

Credit from:
License: MIT Copyright@