Does your ISP only offer you a dynamically allocated public ip-address through dhcp? You are not alone! Dynamic-DNS to the rescue! As we all may know, a DNS A-record i.e. example.com resolves to a particular ip-address i.e. 18.104.22.168. You normally set this record manually by logging in to your DNS-provider-account. However, if your ISP does not offer you a static ip-address it can be a hassle to run i.e. a webserver, should the ip-address suddenly change making your DNS-record point to a now obsolete address. Visitors lost in cyberspace. The way around this is to set up a deamon running on your server that regularly checks for changes in the ip-address, typically every 5 minutes, and make changes to your dns-account when needed. In this blog-post we will look at setting up ddclient for this purpose. We will use the Linux Ubuntu-distro when doing this. Let’s do it.
First install ddclient:
apt-get install ddclient
This will install and start a configuration wizard. Type in your data.
I choose “other” here since my dns-provider is not listed.
My NIC was named em1 which can be shown running the ifconfig command
That was the last entry, now I get this at the prompt when finishing:
update-rc.d: warning: stop runlevel arguments (1) do not match ddclient Default-Stop values (0 1 6)
This warning can be ignored. Checking with sysv-rc-conf we can see that the ddclient service is configured to be on for runlevels 2,3,4,5 as it should be.
root@ubuntu01:~# sysv-rc-conf --list ddclient ddclient 1:off 2:on 3:on 4:on 5:on
Let’s check what /etc/default/ddclient now looks like
root@ubuntu01:~# more /etc/default/ddclient # Configuration for ddclient scripts # generated from debconf on Tue Jun 23 11:47:25 CEST 2015 # # /etc/default/ddclient run_ipup="false" run_daemon="true" daemon_interval="300"
Ok, so everything looks nice and dandy here. deamon-mode true and update interval check every 300 seconds (5 minutes). Now take a peek what we got in /etc/ddclient.conf
root@ubuntu01:~# more /etc/ddclient.conf # Configuration file for ddclient generated by debconf # # /etc/ddclient.conf protocol=dyndns2 use=if, if=em1 server=dns.loopia.se/XDynDNSServer/XDynDNS.php login=creang.com password='password_here' creang.com,creang.se
Ok, so no using of ssl here, I want the deamon to use ssl when calling my dns-provider-account for security reasons, so I put that as well in the config file, also my dns-provider does only support system=custom
Please note that the line use=if, if=em1 will check for any change in ip-address against the NIC. This is viable if you have the public-ip assigned directly to your network interface, like I have. If you are running your server behind a router/firewall using NAT-forwarding then you will want to configure the use of requesting a web-page in order to fetch your current public ip-address, like this:
use=web, web=dns.loopia.se/checkip/checkip.php, web-skip='Current IP Address:'
Now, all done!
Just restart the service with:
root@ubuntu01:~# service ddclient restart
We can now see that the deamon is running just fine with the pstree -p command
ddclient running as process 1348, runs every 300 seconds, five minutes
root@ubuntu01:~# ps -ef|grep ddclient root 1348 1 0 13:10 pts/0 00:00:00 ddclient - sleeping for 110 seconds
Should you want to re-run the configuration wizard, use this command:
Double check that everything is working correctly with this command:
root@ubuntu01:~# ddclient -daemon=0 -debug -verbose -noquiet ... DEBUG: get_ip: using if, em1 reports 22.214.171.124 SUCCESS: creang.com: skipped: IP address was already set to 126.96.36.199. SUCCESS: creang.se: skipped: IP address was already set to 188.8.131.52.