10-03-2014 11:42 AM - edited 04-29-2015 12:39 PM
Here's a script I created to update my DDNS entries for dhcp wan interfaces. This works with any ddns providers where you can pass the correct paramater through an http/https URL. In this case an authentication token, but username/password should work also.
In my case, I use EntryDNS and is in my opinion a great free DNS management service. I like that it provides a 60 second TTL.
Just edit the interface names, I have two wan interfaces, if you only have one, use that one for both WAN and WAN2, and replace TOKEN in the curl commands with the authentication token given to you by your provider Place the script in /etc/dhcp3/dhclient-exit-hooks.d . Make sure you change the file to be executable using the chmod +x command. ie sudo chmod +x /etc/dhcp3/dhclient-exit-hooks/myddns .
You can also run an action when an interface's ip address is released, expired, etc.
This is my first linux script, so feel free to critique it. It's been running successfully on my network.
#!/bin/sh #Script to update DynamicDNS for some providers not natively supported #This particular version is used for providers that require a token instead of username/password #Providers that require username/password should work too, just need to edit the curl commands #This script supports two wan ports #EntryDNS is a free provider that I've been very happy with http://entrydns.net/help #This script should be pretty easy to modify for other ddns providers. #Documentation on some of the options used in this script can be found at # http://manpages.ubuntu.com/manpages/maverick/en/man8/dhclient-script.8.html # #Place this script in /etc/dhcp3/dhclient-exit-hooks.d and make the file executable . ie chmod +x filename #Replace TOKEN with the authentication token given to you by ddns provider RUN="yes"
#To turn on logging change no to yes TO_LOG="no" #Force the ddns entry to be updated when you click [Renew] in the GUI even if the address hasn't changed FORCE_UPDATE="no" #Set your WAN interfaces WAN="eth0" WAN2="eth1" if [ "$RUN" = "yes" ]; then if [ "$TO_LOG" = "yes" ]; then LOG=/tmp/myddns.log else LOG=/dev/null fi echo $(date "+%x +%r %Z") >> $LOG case $reason in BOUND|RENEW|REBIND|REBOOT) #RENEW and REBIND provide both $old_ip_address and $new_ip_address BOUND and REBOOT only provide %new_ip_address echo Address was acquired or reacquired on interface $interface : $reason >> $LOG if [ $old_ip_address = $new_ip_address ]; then echo New address $new_ip_address is same as old address $old_ip_address : No need to update ddns >> $LOG #When you manually renew your dhcp address and the address didn't change, $reason is REBOOT not RESET elif [ $reason = REBOOT ] && [ "$FORCE_UPDATE" != "yes" ]; then echo New address $new_ip_address is same as old address $old_ip_address : No need to update ddns >> $LOG elif [ $interface = $WAN ]; then #You should be able to get the needed syntax from your ddns provider curl -k -X PUT -d "ip=$new_ip_address" https://entrydns.net/records/modify/TOKEN echo WAN Interface $interface acquired address $new_ip_address >> $LOG echo ddns entry updated. >> $LOG elif [ $interface = $WAN2 ]; then #Second Wan interface curl -k -X PUT -d "ip=$new_ip_address" https://entrydns.net/records/modify/TOKEN echo WAN2 Interface $interface acquired address $new_ip_address >> $LOG echo ddns entry updated. >> $LOG fi ;; EXPIRE|FAIL|RELEASE|STOP) #If action needed when interface no longer has ip_address echo Address on interface $interface was released : $reason >> $LOG ;; MEDIUM|PREINIT|NBI|TIMEOUT) #Other reasons script will run *see doc link above for description echo Other reason script was run: $reason >> $LOG ;; esac echo "-------------" >> $LOG echo "" >> $LOG fi
edited to fix some spelling errors in comments and to add ability to force update
2nd edit to note that file needs to be executable ie. chmod +x (thanks to DanielGrufman for correction)
10-03-2014 04:50 PM
If you want to play around with the script, here are the variables that are available depending on the $reason that led to the script being run:
old_subnet_mask= old_domain_name_servers= old_broadcast_address= old_expiry= new_subnet_mask= new_domain_name=
OLDPWD=/etc/sysconfig/network-scripts new_ip_address= new_network_number= interface= reason= old_dhcp_message_type= new_expiry= PATH= new_dhcp_lease_time= pid= new_dhcp_server_identifier= PWD= LANG= new_routers= new_domain_name_servers= SHLVL=1 old_dhcp_server_identifier= new_dhcp_message_type= old_ip_address= old_dhcp_lease_time= new_broadcast_address= old_network_number= old_routers= old_domain_name=
10-03-2014 07:45 PM - edited 10-03-2014 07:46 PM
Looks legit! Does the built-in dynamic DNS setting not work for EasyDNS? I have been using namecheap for a while without any issues.
 jenkins@JENKI-MAIN-gw# set service dns dynamic interface eth1 service afraid dnspark dslreports dyndns easydns namecheap sitelutions zoneedit
10-03-2014 09:06 PM
Yes, EasyDNS works with the build in settings. Accessible in the GUI. But there's a lot of ddns providers, that the built in dynamic DNS (based on ddclient) doesn't support.
02-12-2015 06:05 AM
Just a comment from a Linux newbi. The "chmod" command should have "+x" (instead of "-x") to set the permissions to executable. Took a while to figure out for me but I learned something new... Thanks for the post though since I am trying to make use Duckdns.org that uses tokens.