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:
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