Besides my full-time job as a technology consultant, I always love to try something new. At this time, I really want to maximize my raspberry pi device as my personal web server. In addition to it, I also want to be able to access it through the internet wherever I go. But there is a problem comes out. I cannot simply set up my DNS server to bind it with my home internet IP address because it constantly changes. To overcome this, I did some research and here’s dynamic DNS for Cloudflare using DDClient as my solution.
I subscribe to one of the internet provider in Malaysia which gives me 100 Mbps of internet speed, and it is really nice. It is one of best offer I can get because the price is relatively low and the internet speed itself relatively stable even when it’s raining (from my experience, not all internet provider can do that actually).
But, the problem with a home internet connection is the IP address. It will be dynamically changed when your router is connecting to your provider’s back office. Although an IP address change relatively not frequent, but every time it changes you need to update your DNS provider to register your domain to point correct IP address. Thus you can do it manually or automatically use a script.
On the other hand, if you try to do manually first it is pain in the ass and second, you don’t know when it changes. You constantly need to check your home router IP address and your website will be facing a downtime every time you forgot to change your IP address.
Moreover, your crappy router decides to have a problem and you have to reset it (yeah this happens a lot of time). And when it’s back on, you discover with horror that your provider assigns the IP address dynamically and guess what: your website is now unreachable due to IP changed.
Solution (Dynamic DNS for Cloudflare using DDClient)
I don’t want to setup my web server to update my DNS provider manually. It takes too much time for me just to check my IP address and I really hate it.
There are a couple of blogs that I read, but almost all of it talks the same methods. So, there are three alternatives:
- Switch to a provider which supplies static IPs which this cost a lot of money to make me poor. But then, their performance still an issue. 🙁
- Manually change the IP address of the ‘A’ record of your domain DNS every time the router decides to act weird or your provider act weird.
- Set up an automatic script to change the IP address of A record of your domain DNS, and run it using the scheduler (CRON/another scheduler).
After that, I decided to check my DNS provider settings.
I googling around and found out there is out of the box UNIX library ddclient. DDclient and Cloudflare are working well together from what I read. Thus, I really curious on how it works. So, I decided that dynamic DNS for Cloudflare using DDClient is my solution for now.
On this blog post, I will show you how to setup Dynamic DNS for Cloudflare using DDClient; and how you can achieve the same using tutorial provided.
So, here is my step by step tutorial to setup your ddclient inside your Linux server. I use ubuntu as my base operating system and I choose version 16.04 for LTS feature.
Dynamic DNS for Cloudflare using DDClient Step By Step Guide
Install DDClient library from ubuntu repository. Do not forget to add ‘sudo’ in your command, if not it will throw an exception permission error.
> sudo apt-get install ddclient
Install library ddclient JSON Perl from ubuntu repository also. This is required since ddclient need to send JSON payload to CloudFlare API.
> sudo apt-get install ddclient libjson-any-perl
Check your ddclient version. If it is version 3.8.2; then you need to update it to ver. 3.8.3 to fully support CloudFlare. Most of all, you need to take a note ver <= 3.8.2 seems not supported. (Please correct me if I’m wrong).
> cd /usr/sbin/ > ddclient –help output:
Then, download and extract the latest version of the ddclient binary.
> wget http://downloads.sourceforge.net/project/ddclient/ddclient/ddclient-3.8.3.tar.bz2 > tar -jxvf ddclient-3.8.3.tar.bz2 output:
Overwrite the existing binary with the newer one that we extract previously. Moreover, please do not forget to put -f to copy in force method.
> cp -f ddclient-3.8.3/ddclient /usr/sbin/ddclient
Then, move the configuration file from /etc/ddclient.conf to /etc/ddclient/ddclient.conf
> mkdir /etc/ddclient > mv /etc/ddclient.conf /etc/ddclient
Finally, edit ddclient configuration file in ddclient.conf under /etc/ddclient/ddclient.conf by tying below command. Then do not forget to save the config file.
> sudo vi /etc/ddclient/ddclient.conf # Configuration file for ddclient generated by debconf # # /etc/ddclient.conf daemon=300 ssl=yes use=web, web=checkip.dyndns.com/, web-skip='IP Address' login=cloudflare_email_address([email protected]) password=cloudflare-api-key protocol=cloudflare, server=www.cloudflare.com, subdomain.domain.extension (e.g. subdomain.randytan.me) > escape then press :wq! (to save and exit)
After editing the configuration, please open your web browser.
Try to login to Cloudflare > DNS > Add ‘A’ record, put in your domain/subdomain name with any random IP address. Then make sure it is the same as you put in step 7 under domain.extension.
Then after CloudFlare is done, please back to your shell/command terminal.
Try to run ddclient in verbose and debug mode for the new configuration. Then do not forget to double check if IP address that bind already correct. (You can check your IP address by typing ‘my ip address’ in Google)
> sudo ddclient -daemon=0 -debug -verbose –noquiet output:
Setup the ddclient configuration by typing below command. After that do not forget to save it.
> sudo vi /etc/default/ddclient > wq! (to save and exit) screenshot:
Configure the ddclient setup daemon in UNIX. First, copy and paste init.d/ddclient service configuration from the tar.bz2 to replace the old daemon service. Then do the next step.
> cd /home//ddclient-3.8.3 > sudo cp sample-etc_rc.d_init.d_ddclient.ubuntu /etc/init.d/ddclient output:
Reload service daemon init.d, and start the ddclient service.
> cd /usr/sbin > systemctl daemon-reload > sudo service ddclient start > sudo service ddclient status --this is to check status of daemon service output:
In summary, there are few alternatives on how to set up dynamic DNS. But on this tutorial Dynamic DNS for Cloudflare using DDClient, I show you step by step guide how to make DNS automatically updated without manual work to update it.
There are alternatives such as calling the CloudFlare API directly without using any library or just using Shell script. You can check out few alternatives from this blog. And if you are curious there are few of people who already create a PHP script also.
Please do not forget to give me comments, and I really welcome if you give feedback or suggestions. Have a good day, folks!