Configuring Dynamic IP auto-update for custom domain name(Alternative to dyndns, noip etc… )

Mirror Mirage
4 min readDec 22, 2019
Make mydomain.com point to your ever changing Dynamic IP home server

To setup a domain name for your home server (which has a Dynamic IP), there are a few options

  1. Paid service such as dyn.com which is supported by several home routers.
  2. Free service such as no-ip.com which allows you to install a local client on your home sever, which will update the subdomain name on no-ip. However, no-ip requires you to login/verify that you still need the domain every 30 days or so.

What I wanted was a set and forget option.

I already have a domain name (Found a cheap .win domain name for about 3 dollars for 3 years).

Here is what I setup.

Namecheap and CloudFlare Configuration

  1. My DNS registrar is Namecheap.com.
  2. I signed-up on CloudFlare.com and configured Namecheap.com to use CloudFlare DNS server. You just need to change the DNS setting to custom and add CloudFlare’s name servers. Instructions are on CloudFlare.com

3. Once this is done, I did a test by creating a sub-domain on cloudflare and tried a ping request to make sure all is fine.

Testing cloudflare subdomain creation. 123.122.111.111 is a test ip, replace it with your home server IP address

Test if the configured subdomain works.

ping subdomain.mydomain.com

If it works, change it back to something different, so that you can see an update happening once we setup ddclient.

4. Configure an API token in CloudFlare. Give it the permissions Zone.Zone, Zone.DNS. This token is what your local ddclient will use to update CloudFlare DNS with your Dynamic IP address.

Now, lets configure ddclient to ensure the dynamic update of IP address happens.

I tested these on Ubuntu 18.04 and Raspbian 10. This should ideally work on Debian as well with no changes.

DDCLIENT Setup

Step 1) Change to root user.

(I ran into a bunch of crazy errors when I tried with a normal user)

sudo su

Step 2) Get ddclient

cd /tmpgit clone https://github.com/ddclient/ddclient.gitcd ddclientcp ddclient /usr/sbin/mkdir /etc/ddclientmkdir /var/cache/ddclient

Step 3) Install the dependencies for ddclient

apt-get install libdata-validate-ip-perlapt-get install libjson-any-perlapt-get install libio-socket-ssl-perl

Step 4) Configure the contents of ddclient.conf as follows

Edit the file

nano /etc/ddclient/ddclient.conf

change contents as follows

use=web, web=checkip.dyndns.org/, web-skip='IP Address'                                 # via web
protocol=cloudflare, \
zone=YOURDOMAINNAME.COM, \
login=YOURCLOUDFLAREEMAIL@EMAIL.COM, \
password=YOUR-CLOUDFLARE-APITOKEN-YOUCREATED-IN-STEP4 \
YOURSUBDOMAIN.YOURDOMAIN.COM

The password here refers to the cloudflare API token you created in Step 4.

You will need the strange \ characters yes. Replace the values in CAPS with your values.

Step 5) Let’s do a test run. Run the following command

ddclient -daemon=0 -debug -verbose -noquiet -force

You should see an output which says “SUCCESS: yoursubdomain.yourdomain.com — — Updated Succesfully to YOURPUBLICIP”

Login to CloudFlare DNS console to make sure your sub-domain IP address has been updated to point to Home server’s public IP.

The -force option forces an update. By default ddclient only does a DNS update if the IP address has changed.

Step 6) Let’s schedule the ddclient to run on a routine basis.

Add an entry to crontab

crontab -e

I configured 2 entries. One is a normal run every 5 minutes, and the other is a force update once in a day. You may change according to your needs.

15 * * * * /usr/sbin/ddclient
45 4 * * * /usr/sbin/ddclient -force

If you want to test out crontab, make the entry as

* * * * /usr/sbin/ddclient -force

so that it runs every minute, and then manually change the IP address in Cloudflare, wait for a minute and see if ddclient updates it back to your Home Public IP. Once you have verified , revert it back to 15 minutes/ 30 minutes or whichever duration you prefer.

Yay! We have successfully setup an auto-updating domain name for our Dynamic IP home server.

Foot notes and Disclaimers.

  1. This is an in-elegant way of running ddclient. ddclient should ideally be run as a daemon/systemd service. Unfortunately I couldn’t get it to work (100% some issue from my setup), So I resorted to crontab
  2. ddclient is available as apt-package. I couldn’t configure or get it running because i wanted to use cloudflare protocol, not no-ip, not dydns.org. I am sure there must be a way to manually configure it an get it up and running. Again, I wanted something quick, so resorted to manually downloading and copying the binary to /sbin and config file.
  3. ddclient can update a wide variety of DNS like dyndns, no-ip, even namecheap. I personally wanted to use cloudflare and went this route.
  4. There are many other configurations possible with ddclient such as sending an email notification. DYOR, if you need these.
  5. Last but not least, the commands were run as root user for it to work.

--

--