What's new

Custom DDNS update rate?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Steffe

Regular Contributor
Hey,

I'm behind NAT, and thus need to check my external ip, and subsequently update if the ip has changed. So my question is, how often is the Custom DDNS updated/executed?

EDIT: Found out it was 1 day. May it be set lower than that... say 1 hour?

I wrote this script using the noip service and it might be useful for others in the same situation as me :)

Features:
  • It is possible to log changes (I use external USB drive).
  • IP address is stored as temporary nvram value, so that I can check if ip changed to avoid banning of my account.
  • Logging of respond messages from noip
  • Backup site to check external ip if primary site is down. Currently doesn't validate if ip is correct format (123.123.123.123 format).

Code:
#!/bin/sh
# Custom DDNS (dynamic DNS) for the no-ip.com service for asuswrt-merlin
#

USERNAME=""
PASSWORD=""
HOSTNAME=""
USERAGENT="asuswrt-merlin No-IP Updater/0.1"     
#NEWIP="$1" # passed to script, however, we have local ip so external providers to find ip is used                                                                                 
LOGFILE="" # leave empty if not used

### CODE BELOW ####
NEWIP=$(curl -s http://ipv4.myip.dk/api/info/IPv4Address | cut -d "\"" -f2)
OLDIP=$(nvram get EXTERNALIP) # get old ip from nvram

# backup ipcheck
if [ -z $NEWIP ]; then
    NEWIP=$(curl -s http://icanhazip.com/)
fi

if [ $NEWIP == $OLDIP ]; then
    LOGLINE="(nochange) IP address is current: $NEWIP; no update performed."
    /sbin/ddns_custom_updated 1
else
    # update ip
    nvram set EXTERNALIP=$NEWIP
    URL="https://$USERNAME:$PASSWORD@dynupdate.no-ip.com/nic/update?hostname=$HOSTNAME&myip=$NEWIP"
    RESPONSE=$(curl -s -k --user-agent "$USERAGENT" "$URL")
    RESPONSE_A=$(echo $RESPONSE | awk '{ print $1 }')
    if [ $RESPONSE_A == "good" ]; then
        /sbin/ddns_custom_updated 1
        LOGLINE="(good) DNS hostname(s) successfully updated to $NEWIP."
    elif [ $RESPONSE_A == "nochg" ]; then
        /sbin/ddns_custom_updated 1
        LOGLINE="(nochg) IP address is current: $NEWIP; no update performed."
    elif [ $RESPONSE_A == "nohost" ]; then
        /sbin/ddns_custom_updated 0
        LOGLINE="(nohost) Hostname supplied does not exist under specified account. Revise config file."
    elif [ $RESPONSE_A == "badauth" ]; then
        /sbin/ddns_custom_updated 0
        LOGLINE="(badauth) Invalid username password combination."
    elif [ $RESPONSE_A == "badagent" ]; then
        /sbin/ddns_custom_updated 0
        LOGLINE="(badagent) Client disabled - No-IP is no longer allowing requests from this update script."
    elif [ $RESPONSE_A == "!donator" ]; then
        /sbin/ddns_custom_updated 0
        LOGLINE="(!donator) An update request was sent including a feature that is not available."
    elif [ $RESPONSE_A == "abuse" ]; then
        /sbin/ddns_custom_updated 0
        LOGLINE="(abuse) Username is blocked due to abuse."
    elif [ $RESPONSE_A == "911" ]; then
        /sbin/ddns_custom_updated 0
        LOGLINE="(911) A fatal error on our side such as a database outage. Retry the update in no sooner than 30 minutes."
    else
        /sbin/ddns_custom_updated 0
        LOGLINE="(error) Could not understand the response from No-IP. The DNS update server may be down."
    fi
fi
LOGDATE="[$(date +'%Y-%m-%d %H:%M:%S')]"
echo "IP: $NEWIP"
echo $LOGLINE
if [ -n $LOGFILE ]; then
    echo "$LOGDATE $LOGLINE" >> $LOGFILE
fi
exit
 
If I remember correctly when the WAN IP address changes it'll trigger the ddns update. There is a forced refresh option which as it suggests, will force an update to the ddns service provider. You might want to add the above to the wiki here: https://github.com/RMerl/asuswrt-merlin/wiki/Custom-DDNS
 
Well, yes.. I would also think it did that, however, if you're behind NAT then your wan ip does not change when the external changes. The force refresh might work, but it's only daily. Would have been better to adjust it to hourly updates. My script only updates request DNS update if the external ip has changed.

Edit: Yes, will add it when it has been tested a bit more. I'm still considering using cron to accomplish above mentioned.
 
Last edited:
Did you ever get this to work directly with No-IP? I can't seem to get it to work. Do I place it in the standard spot from the Custom Scripts Page?
 
EDIT: Found out it was 1 day. May it be set lower than that... say 1 hour?

I don't know if I would recommend setting updates to 1 hour... maybe 6 or 12 hours if your IP is changing, thing is to look at your DHCP lease time from the ISP - most leave it at 24 hours unless they're getting ready to do maintenance on the network..
 
I think the script is working as intended. However, my IP has not changed. You should use the jffs partition for your script and add the content in the script /jffs/scripts/ddns-start, and then enable custom DDNS.

https://github.com/RMerl/asuswrt-merlin/wiki/Custom-DDNS
I did that, Literally pasted your script into that file path with the changed settings for my No-IP account. I keep getting an error, what do you input as the host-name on the custom DDNS setting? It also, just sits there on applying forever.
 
What does you log say?
Mine says:
Code:
Apr 20 04:00:29 watchdog: start ddns.
Apr 20 04:00:29 rc_service: watchdog 496:notify_rc start_ddns
Apr 20 04:00:29 custom script: Running /jffs/scripts/ddns-start (args: 192.168.1.2)
Apr 20 04:00:29 ddns: Completed custom ddns update

Router site:
upload_2016-4-21_16-21-27.png


Path for script is:
-rwxrwxr-x 1 admin root 2597 Jan 11 20:48 /jffs/scripts/ddns-start

Is your script executeable? Can you execute it manually? Check permissions.
If that still doesn't work, try and execute it with debug and remove the arguments "-s" to the curl commands: "sh -x /jffs/scripts/ddns-start". Remember to remove your password.
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top