Solved DDNS update IP with wan-event detect WAN IP change

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.

Markster

Senior Member
There are many ways to configure DDNS on @RMerlin software. Until last week I had a custom script configured using router DDNS page and that works fine
except it refreshes the IP only once a day. I was looking for ways to have the DDNS IP refreshed as soon as my router WAN IP is changed.
I started experimenting with wan-event and as it turns out this is the solution you want if your requirement is to have DDNS IP very current and updates as soon as WAN IP is changed by ISP or otherwise. I used 2 scripts to accomplish that. First script is by @Martineau who created a wan-event script template. Here is the code:

wan-event
#!/bin/sh

# v384.15 Introduced wan-event script, (wan-start will be deprecated in a future release.)

# wan-event {0 | 1} {stopping | stopped | disconnected | init | connecting | connected}
#
Say(){
echo -e $$ [email protected] | logger -st "($(basename $0))"
}
SayT(){
echo -e $$ [email protected] | logger -t "($(basename $0))"
}
#========================================================================================================================================
#Say "User wan-event running"

scr_name="$(basename $0)"
WAN_IF=$1
WAN_STATE=$2

# Call appropriate script based on script_type
SERVICE_SCRIPT_NAME="wan${WAN_IF}-$WAN_STATE"
SERVICE_SCRIPT_LOG="/tmp/WAN${WAN_IF}_state"

# Execute and log script state
if [[ -f "/jffs/scripts/$SERVICE_SCRIPT_NAME" ]] ; then
Say " Script executing.. for wan-event: "$SERVICE_SCRIPT_NAME
echo "$SERVICE_SCRIPT_NAME" > $SERVICE_SCRIPT_LOG
sh /jffs/scripts/$SERVICE_SCRIPT_NAME $*
else
Say " Script not defined for wan-event: "$SERVICE_SCRIPT_NAME
fi

Following that I created my wan0-connected script to handle auto renewal for my DDNS provider - DuckDns.org. Feel free to modify this as required.


#!/bin/sh

CERT_DOMAIN="your domain name"
DuckDNS_Token="your token"

sleep 5

IP=`nvram get wan0_ipaddr`

logger -st $0 "Refresh started."
curl -s -S --retry 3 "https://www.duckdns.org/update?domains=$CERT_DOMAIN&token=$DuckDNS_Token&ip=$IP" >> /tmp/wan0-connected.log 2>&1
if [ "$?" == "0" ]; then
logger -st $0 "Refresh completed. WAN IP is $IP"
else
logger -st $0 "ERROR - $( tail -n 1 /tmp/wan0-connected.log )"
fi

Having both scripts in place when WAN IP is changing by IP new lease or when you change something on the router that would refresh the WAN IP, these two scripts
do the job and perform the DDNS IP update as soon as your WAN IP is changed. Enjoy.
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

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