<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Cloudflare on Esad Cetiner</title><link>https://ecetiner.com/tags/cloudflare/</link><description>Recent content in Cloudflare on Esad Cetiner</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>© 2026 Esad Cetiner</copyright><lastBuildDate>Thu, 12 Jan 2023 18:11:16 +0000</lastBuildDate><atom:link href="https://ecetiner.com/tags/cloudflare/index.xml" rel="self" type="application/rss+xml"/><item><title>Free dynamic DNS with Cloudflare</title><link>https://ecetiner.com/linux/fast-dynamic-dns-with-cloudflare/</link><pubDate>Thu, 12 Jan 2023 18:11:16 +0000</pubDate><guid>https://ecetiner.com/linux/fast-dynamic-dns-with-cloudflare/</guid><description><description>&lt;p&gt;Do you want to host a website at home, or run your own personal cloud with Nextcloud? Chances are, you have a dynamic IP address assigned from your ISP. A common issue with running services at home is having to frequently update your DNS records whenever your IP address changes, luckily with Dynamic DNS (DDNS) this can be automated. Cloudflare offers a powerful API that allows us to automate various tasks such as updating what IP address our DNS records point to, a &lt;a href="https://github.com/K0p1-Git/cloudflare-ddns-updater" target="_blank" rel="noreferrer"&gt;github user&lt;/a&gt; has written a shell script that lets us take advantage of Cloudflare&amp;rsquo;s API without having to write any code!&lt;/p&gt;
&lt;h2 class="relative group"&gt;Prerequisites
&lt;div id="prerequisites" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#prerequisites" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;You must own a domain name.&lt;/li&gt;
&lt;li&gt;You must either have your DNS Nameservers pointed to Cloudflare or use Cloudflare as a domain registrar.&lt;/li&gt;
&lt;li&gt;You must have a Linux Server that&amp;rsquo;s running at home.&lt;/li&gt;
&lt;li&gt;Linux Fundamentals&lt;/li&gt;
&lt;li&gt;Networking Fundamentals.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class="relative group"&gt;Downloading the script
&lt;div id="downloading-the-script" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#downloading-the-script" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;To download the script, first make sure you have git installed and then git clone the script.&lt;/p&gt;
&lt;h3 class="relative group"&gt;Ubuntu / Debian
&lt;div id="ubuntu--debian" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#ubuntu--debian" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo apt install git&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 class="relative group"&gt;RHEL / Cent OS
&lt;div id="rhel--cent-os" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#rhel--cent-os" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo yum install git&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 class="relative group"&gt;Cloning the repository
&lt;div id="cloning-the-repository" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#cloning-the-repository" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git clone https://github.com/K0p1-Git/cloudflare-ddns-updater&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;That&amp;rsquo;s it for now, we have to create an API token to use this script.&lt;/p&gt;
&lt;h2 class="relative group"&gt;Getting our API token and Zone ID
&lt;div id="getting-our-api-token-and-zone-id" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#getting-our-api-token-and-zone-id" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;To get your API token go to &lt;a href="https://dash.cloudflare.com" target="_blank" rel="noreferrer"&gt;https://dash.cloudflare.com&lt;/a&gt;, log in, and then click your domain name, in my case this is ecetiner.com. You&amp;rsquo;ll then want to look for &amp;ldquo;Get your API Token&amp;rdquo; at the very bottom right of your screen, I&amp;rsquo;ve included a screenshot as it can be hard to find for some people. Right above &amp;ldquo;Get your API Token&amp;rdquo; You&amp;rsquo;ll see your Zone ID, copy and save it as we&amp;rsquo;ll need it for the script to work.&lt;/p&gt;
&lt;figure&gt;&lt;img
class="my-0 rounded-md"
loading="lazy"
decoding="async"
fetchpriority="low"
alt="An image showing where to get your API token."
src="https://ecetiner.com/wp-content/uploads/get-api-token-ddns.webp"
&gt;&lt;/figure&gt;
&lt;p&gt;Next under API Token you want to click &amp;ldquo;Create Token&amp;rdquo; then under &amp;ldquo;Edit DNS Zone&amp;rdquo; click &amp;ldquo;Use Template&amp;rdquo;. Your token&amp;rsquo;s permissions should look like mine.&lt;/p&gt;
&lt;figure&gt;&lt;img
class="my-0 rounded-md"
loading="lazy"
decoding="async"
fetchpriority="low"
alt="An Image showing what permissions to use when creating a token. The only permission needed is DNS being set to edit."
src="https://ecetiner.com/wp-content/uploads/create-api-token-ddns.webp"
&gt;&lt;/figure&gt;
&lt;p&gt;After that you&amp;rsquo;ll want to click &amp;ldquo;Continue to summary&amp;rdquo; then &amp;ldquo;Create Token&amp;rdquo;. Your token will be displayed and a &lt;code&gt;curl&lt;/code&gt; command will be provided which lets you test the API token. Make sure you keep the token somewhere safe and don&amp;rsquo;t publish it on the internet as it can negatively impact your security. If your token is missing or was compromised, then you can &amp;ldquo;roll&amp;rdquo; the token which will generate a new one and invalidate the old one.&lt;/p&gt;
&lt;h2 class="relative group"&gt;Configuring the script
&lt;div id="configuring-the-script" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#configuring-the-script" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;Go back to your server and cd into cloudflare-ddns-updater.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cd cloudflare-ddns-updater/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Open the file cloudflare-template.sh with a text editor, nano is a good beginner friendly text editor.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;nano cloudflare-template.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once you open the file you&amp;rsquo;ll be shown some lines that you&amp;rsquo;ll need to be configure, enter whatever value is relevant for your use case within the quotation marks then save and exit. The table below will guide you on how to fill it out.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setting&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;auth_email&lt;/td&gt;
&lt;td&gt;Put the email address that is used to log into Cloudflare.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;auth_method&lt;/td&gt;
&lt;td&gt;Set this value to token.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;auth_key&lt;/td&gt;
&lt;td&gt;You put the API token that we generated earlier here, Go back to “Getting our API token” if you do not have a API token.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;zone_identifier&lt;/td&gt;
&lt;td&gt;Put your Zone ID here, go back to “Getting our API token” if you don’t know what yours is.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;record-name&lt;/td&gt;
&lt;td&gt;Add your DNS record name here, subdomain.example.com or example.com go here.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ttl&lt;/td&gt;
&lt;td&gt;How long (In seconds) a change in your DNS will take effect, set this to 60 so your DNS record can update quickly.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;proxy&lt;/td&gt;
&lt;td&gt;If you want to proxy your website through Cloudflare set this to true, Otherwise set it to false.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 class="relative group"&gt;Testing the script
&lt;div id="testing-the-script" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#testing-the-script" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;To test the script, update the DNS record you want DDNS for and set it to an invalid IP address (For example 1.1.1.1). Make sure you wait a few minutes for the change to propagate. Check with dig to see if your DNS is invalid.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;dig a example.com&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.18.1-1ubuntu1.2-Ubuntu &amp;lt;&amp;lt;&amp;gt;&amp;gt; a example.com
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; global options: +cmd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; Got answer:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 22899
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; OPT PSEUDOSECTION:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;; EDNS: version: 0, flags:; udp: 65494
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; QUESTION SECTION:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;example.com. IN A
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; ANSWER SECTION:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;example.com. 3600 IN A 93.184.216.34
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; Query time: 320 msec
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; WHEN: Fri Jan 13 04:26:46 AEDT 2023
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; MSG SIZE rcvd: 56&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once your DNS record has propigated, run the script, wait a few minutes then check again with dig. Your IP address should be your home IP address now.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo bash cloudflare-template.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 class="relative group"&gt;Create a cronjob to auto run the script
&lt;div id="create-a-cronjob-to-auto-run-the-script" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#create-a-cronjob-to-auto-run-the-script" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;Now that we have a functioning script, we need to setup a cronjob so it runs automatically every minute. After all, nobody wants to have to run the script manually everytime something breaks!&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;crontab -e&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Copy paste the following and replace /path/to/script with the location to your script.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;*/1 * * * * bash /path/to/script/cloudflare-template.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;That&amp;rsquo;s all there is to it, you&amp;rsquo;ve now setup DDNS with Cloudflare and your DNS records will be automatically updated as your IP address changes!&lt;/p&gt;</description></description></item></channel></rss>