Synology usage series 20 – Using your own domain name with freedns.afraid.org


Step 5 – Setup dynamic DNS client on NAS

Now both registrar and dynamic DNS provider is setup probably.

The final step is to install DDNS client so that our DNS record is updated for every IP address changes.

There are lots of ddns client provided on afraid.org

http://freedns.afraid.org/scripts/freedns.clients.php

Following types of client is provided

  • DD-WRT router client
  • Tomato router client
  • Windows client
  • Unix client
  • etc

If none of them works for you (hmmm… ) , you may want to try the simple client written by me below.

  1. SSH to the NAS as root
  2. Install wget and bash shell
    # ipkg update
    # ipkg install bash
    # ipkg install wget
    # ipkg install dos2unix
    
    
  3. Copy the script below and paste to notepad. Modify your own afraid.org code and verify all the path highlighted in red. Save it to a share folder on the NAS, i.e. public. Save the file as ddns.sh.
    #!/opt/bin/bash
    # 
    # simple script to update everydns.net/afraid.org/opendns for ip changes
    # version 0.21
    #
    # Copyrighted by Ray Chan 2011
    #
    # pre-requistics
    # - wget
    # - bash
    
    # If you want a simple log file, assign 1 to log_enabled, otherwise set it to 0
    log_enabled=1; #0=disable, 1=enable
    
    # date format used by log file
    datestamp=`date '+%Y-%m-%d %H:%M:%S'`
    
    #input the freedns dynamic domain code here
    freednscode=xxxxxxxxxxxxxxxxxxxxxxx
    
    # the actual command getting the public IP, change the URL to your php hosting
    
    myipnow=`wget --timeout=10 --tries=1 -qO - http://whatismyip.com/automation/n09230945.asp`
    
    previp="0.0.0.0";
    
    # path of the log file, ignore if log_enabled=0
    logfile="/opt/var/log/ddns.log"
    
    # path of the temporary file storing prevoius ip address
    iplog="/opt/tmp/ddns.log"
    
    if [ -f $iplog ]; then
    	previp=`cat $iplog`
    fi
    
    if [ $myipnow != $previp ]; then
    	
    	# update to afraid.org
    	wget --read-timeout=0.0 --waitretry=5 --tries=400 -qO - http://freedns.afraid.org/dynamic/update.php?$freednscode > /dev/null
    	
    	#write the new ip to log file
    	echo $myipnow > $iplog
    	
    	#write to log if enabled
    	if [ $log_enabled = 1 ]; then
    		echo "$datestamp IP changed, updating ddns. [ $previp | $myipnow ]" >> $logfile
    	fi
    fi
    
  4. Move the script to /usr/local/bin

    # mv /volume1/public/ddns.sh /usr/local/bin

  5. convert the script to unix format

    # cd /usr/local/bin
    # dos2unix ddns.sh

  6. Make the script executable, and read only by root
    # chmod  700 /usr/local/bin/ddns.sh
    
  7. Add a scheduled job (cron) to the NAS so that the script will be executed per 5 minutes in order to detect IP changes
    # vi /etc/crontab
    

    Add follow entries to the end of the crontab file

    #minute hour    mday    month   wday    who     command
    
    */5       *       *       *       *       root    /opt/bin/bash /usr/local/bin/ddns.sh
    
    
  8. Restart crontab
    # /usr/syno/etc/rc.d/S04crond.sh stop
    # /usr/syno/etc/rc.d/S04crond.sh start
    

Step 6 – Add port forwarding from broadband router for external access.

In order to access different NAS services from external network, you need to setup port forwarding in your broadband router. Most of the other articles here have description about setup port forwarding for linksys router. I will not repeat here again.

Following is some common ports you might want to forward to your NAS.

80 – web station, web mail (mail station), photo station
443 – web station with ssl encryption
7001 – file station
22 – ssh
5000, 5001 – control panel (DSM)
21, 55536-56559 – ftp

Now your own domain name (i.e. nas.yourdomain.com) is attached to your dynamic IP! You can always access your diskstation using your domain name:

http://nas.yourdomain.com (access the web station)
http://nas.yourdomain.com:5000 (access the control panel)
ftp://nas.yourdomain.com (ftp to your nas)
….

** If you are using afraid.org as described above, and you are satisfied with their services, please consider make a donation to show your appreciation of their services. Indeed, free services rely on donation to cover the daily operation cost. Please consider being a paid member 🙂

** DNS changes can take up to 48 hours to propagate. New domain name changes, however, may effect almost instantly. Please be patient if you DNS is not working yet.





3 thoughts


    • It’s working on my 207+ and 101j. Double verify your setup, even a single little typo can break things. Or you may want to try other ddns client which you find on the afraid.org.

Leave a Reply

Your email address will not be published. Required fields are marked *