What's new

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

  • 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!

D

Deleted member 62525

Guest
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 $$ $@ | logger -st "($(basename $0))"
}
SayT(){
echo -e $$ $@ | 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.
 
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 $$ $@ | logger -st "($(basename $0))"
}
SayT(){
echo -e $$ $@ | 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.
How would I modify wan0-connected script to update instead of DuckDNS it would update the built in ddns ASUS asuscomm.com?? I have a double nat situation and instead of it updating every 20 days or 1 day i'd like it to refresh when I get a new external ip.. Is that possible with this?
 
How would I modify wan0-connected script to update instead of DuckDNS it would update the built in ddns ASUS asuscomm.com?? I have a double nat situation and instead of it updating every 20 days or 1 day i'd like it to refresh when I get a new external ip.. Is that possible with this?

No because your router has no idea when the IP of the upstream WAN changes. You would need to query something like whatsmyip.com every x seconds, and if it changes, fire off a DDNS update. I believe if you use one of the built in DDNS providers you can tell it to do that by setting the method to "external", so maybe change your DDNS provider.
 

Similar threads

Sign Up For SNBForums Daily Digest

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