Update DDNS with RouterTech 2.94
Update DDNS with RouterTech 2.94
Sometimes for unknown reasons my router will disconnect and reconnect, receiving a new WAN IP address. This behavior is OK, but: In some cases it doesn't update the DDNS entry at dyndns.
How can i initiate this by script. The idea is to put it into a cron job and fire it lets say every day.
MfG Stefan Froehlich
42
How can i initiate this by script. The idea is to put it into a cron job and fire it lets say every day.
MfG Stefan Froehlich
42
- thechief
- RouterTech Team
- Posts: 12067
- Joined: Wed Feb 01, 2006 10:22 pm
- Location: England, the Centre of Africa
- Contact:
Re: Update DDNS with RouterTech 2.94
Create a cron job that runs "killall pppd" at the required times.
The Chief: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
No support via PM. Ask all questions on the open forum.
Re: Update DDNS with RouterTech 2.94
Is there a way to detect when the router goes offline and online again?thechief wrote:Create a cron job that runs "killall pppd" at the required times.
MfG Stefan Froehlich
42
- thechief
- RouterTech Team
- Posts: 12067
- Joined: Wed Feb 01, 2006 10:22 pm
- Location: England, the Centre of Africa
- Contact:
Re: Update DDNS with RouterTech 2.94
Code: Select all
dmesg | grep [t]n7atm_close
The Chief: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
No support via PM. Ask all questions on the open forum.
Re: Update DDNS with RouterTech 2.94
To whom it may concern:thechief wrote:Create a cron job that runs "killall pppd" at the required times.
I wrote a script that is retrieves the ip address from a given hostname and compares it to the ip address of the router. If they doesn't match, it resets the connection (it kills pppd as suggested by thechief). The purpose is to keep the router's ip address in sync with a dns entry. On my router sometimes the information on dyndns.org won't be updated for an unknown reason.
I've named it stf_check_myhostip.sh. For example if your hostname is "mydnsentry.homedns.org" call the script this way:
stf_check_myhostip.sh mydnsentry.homedns.org.
Code: Select all
#!/bin/sh
ULB=/usr/local/bin
. $ULB/rt_utils.sh
. $ULB/WANcheck.sh
# $1 the hostname to resolve
get_host_ip()
{
PINGRESULT=$(ping -c 1 -s 1 $1 2> /dev/null | grep "PING $1" | sed s/'PING '$1' ('/''/ | sed s/'): 1 data bytes'/''/)
echo $PINGRESULT
}
# $1 the hostname to resolve
# returns
# "noownip" when we have no ip
# "nohostip" when hostname has no ip (that is: can't be resolved)
# "1" if the hostname's ip is the same as our ip
compare_host_myip()
{
MYIP=$(get_WAN_info "ip")
if [ "$MYIP" = "N/A" ]
then
echo "noownip"
return
fi
HOIP=$(get_host_ip $1)
if [ -z "$HOIP" ]
then
echo "nohostip"
return
fi
if [ $MYIP = $HOIP ]
then
echo "1"
else
echo "0"
fi
}
# Make sure we have WAN connection before entering the loop
w=$(WaitForSync 10 24 1)
RESULT=$(compare_host_myip $1)
# echo "My IP:"$(get_WAN_info "ip")
# echo "Host IP:"$(get_host_ip $1)
# echo "Result was: $RESULT"
if [ "$RESULT" = "0" ]
then
killall pppd
echo "Connection reset"
fi
If the script detects, that the given host name's ip doesn't match your WAN ip, it resets the connection. If it detects, that the given hostname is invalid (has no IP address), it does nothing. If it detects that the router has no connection yet, it does nothing.
MfG Stefan Froehlich
42
Re: Update DDNS with RouterTech 2.94
Watch out "killall pppd" works fine for pppoA connections, but probably not for pppoE, but if you search the forums there are some cli commands that do the same as the disconnect/connect buttons in the web gui.
- thechief
- RouterTech Team
- Posts: 12067
- Joined: Wed Feb 01, 2006 10:22 pm
- Location: England, the Centre of Africa
- Contact:
Re: Update DDNS with RouterTech 2.94
For pppoe you need to do something like thismstombs wrote:Watch out "killall pppd" works fine for pppoA connections, but probably not for pppoE, but if you search the forums there are some cli commands that do the same as the disconnect/connect buttons in the web gui.
Code: Select all
CON=connection0 # but it could be connection1, connection2, etc
echo "begin;$CON:pppoe:command/stop;end" | cm_cli
sleep 1
echo "begin;$CON:pppoe:command/start;end" | cm_cli
The Chief: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
No support via PM. Ask all questions on the open forum.
- thechief
- RouterTech Team
- Posts: 12067
- Joined: Wed Feb 01, 2006 10:22 pm
- Location: England, the Centre of Africa
- Contact:
Re: Update DDNS with RouterTech 2.94
Looks good (bearing in mind the issue raised by mstombs above - but I don't think you use pppoe). Just one little point: you don't check for an empty parameter before proceeding. It can be done very simply by adding something like this at beginning (after the includes):TafnaSM wrote:To whom it may concern:
I wrote a script that is retrieves the ip address from a given hostname and compares it to the ip address of the router. If they doesn't match, it resets the connection (it kills pppd as suggested by thechief). The purpose is to keep the router's ip address in sync with a dns entry. On my router sometimes the information on dyndns.org won't be updated for an unknown reason.
I've named it stf_check_myhostip.sh. For example if your hostname is "mydnsentry.homedns.org" call the script this way:
stf_check_myhostip.sh mydnsentry.homedns.org.
Code: Select all
[ $HELPVAR -eq 1 ] && {
echo "Syntax = $ARGV0 <your dynamic DNS hostname>"
echo "Example: $ARGV0 mydnsentry.homedns.org"
exit 0
}
The Chief: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
No support via PM. Ask all questions on the open forum.
- thechief
- RouterTech Team
- Posts: 12067
- Joined: Wed Feb 01, 2006 10:22 pm
- Location: England, the Centre of Africa
- Contact:
Re: Update DDNS with RouterTech 2.94
Actually, it seems that I had already solved this a while back ("get_connection_type" in rt_utils.sh), and simply forgot. It can be used in this way, to kill and restart the ppp connection:thechief wrote:The problem with pppoe is that you have to get the connection number (i.e, connection0, or connection1, or connection2, or whatever). I haven't found a straightforward (or even completely reliable) way of doing that.
Code: Select all
CT=$(get_connection_type)
[ -z "$CT" ] && {
LOG_MSG "No valid connection. Quitting."
exit
}
LOG_MSG "The current connection is \"$CT\" - resetting the connection."
echo "begin;$CT:command/stop;end" | cm_cli
sleep 1
echo "begin;$CT:command/start;end" | cm_cli
If you don't object, then your script can be added to firmware v2.95, in this format (perhaps with a few tweaks for increased flexibility)
Code: Select all
#!/bin/sh
# ------------------------------------------------------------
# RouterTech firmware script to check whether dynamic DNS is up-to-date;
# if not, reset the ppp connection
# (c)2010, TafnaSM, RouterTech
# Author: TafnaSM
# Last amended: 4 December 2010
# ------------------------------------------------------------
ULB=/usr/local/bin
. $ULB/rt_utils.sh
. $ULB/WANcheck.sh
# empty parameter or "--help"
[ $HELPVAR -eq 1 ] && {
echo "Syntax = $ARGV0 <your dynamic DNS hostname>"
echo "Example: $ARGV0 mydnsentry.homedns.org"
exit 0
}
# $1 the hostname to resolve
get_host_ip()
{
PINGRESULT=$(ping -c 1 -s 1 $1 2> /dev/null | grep "PING $1" | sed s/'PING '$1' ('/''/ | sed s/'): 1 data bytes'/''/)
echo $PINGRESULT
}
# $1 the hostname to resolve
# returns
# "noownip" when we have no ip
# "nohostip" when hostname has no ip (that is: can't be resolved)
# "1" if the hostname's ip is the same as our ip
compare_host_myip()
{
MYIP=$(get_WAN_info "ip")
[ "$MYIP" = "N/A" ] && {
echo "noownip"
return
}
HOIP=$(get_host_ip $1)
[ -z "$HOIP" ] && {
echo "nohostip"
return
}
[ $MYIP = $HOIP ] && echo "1" || echo "0"
}
# Make sure we have WAN connection before entering the loop
w=$(WaitForSync 10 24 1)
RESULT=$(compare_host_myip $1)
[ "$RESULT" = "0" ] && $ULB/ppp_restore.sh
The Chief: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
No support via PM. Ask all questions on the open forum.
Re: Update DDNS with RouterTech 2.94
Yes, i know that. But if it is empty, the ping will fail and so compare_host_myip will return nohostip.thechief wrote:Looks good (bearing in mind the issue raised by mstombs above - but I don't think you use pppoe). Just one little point: you don't check for an empty parameter before proceeding. It can be done very simply by adding something like this at beginning (after the includes):TafnaSM wrote:To whom it may concern:
I wrote a script that is retrieves the ip address from a given hostname and compares it to the ip address of the router. If they doesn't match, it resets the connection (it kills pppd as suggested by thechief). The purpose is to keep the router's ip address in sync with a dns entry. On my router sometimes the information on dyndns.org won't be updated for an unknown reason.
I've named it stf_check_myhostip.sh. For example if your hostname is "mydnsentry.homedns.org" call the script this way:
stf_check_myhostip.sh mydnsentry.homedns.org.HELPVAR will be equal to 1 if no parameter is passed to the script, or if "--help" is passed.Code: Select all
[ $HELPVAR -eq 1 ] && { echo "Syntax = $ARGV0 <your dynamic DNS hostname>" echo "Example: $ARGV0 mydnsentry.homedns.org" exit 0 }
MfG Stefan Fröhlich
42
Re: Update DDNS with RouterTech 2.94
That's the reason why i've posted it here. But don't you think at least the function get_host_ip is usefull for other things and you should move it into rt_utils.sh?thechief wrote:If you don't object, then your script can be added to firmware v2.95, in this format (perhaps with a few tweaks for increased flexibility)
However, if not, I've made three little changes to the script:
Code: Select all
#!/bin/sh
# ------------------------------------------------------------
# RouterTech firmware script to check whether dynamic DNS is up-to-date;
# if not, reset the ppp connection
# (c)2010, Stefan Fröhlich, RouterTech
# Author: Stefan Fröhlich, thechief
# Last amended: 4 December 2010
# ------------------------------------------------------------
ULB=/usr/local/bin
. $ULB/rt_utils.sh
. $ULB/WANcheck.sh
# empty parameter or "--help"
[ $HELPVAR -eq 1 ] && {
echo "Syntax = $ARGV0 <your dynamic DNS hostname>"
echo "Example: $ARGV0 mydnsentry.homedns.org"
exit 0
}
# $1 the hostname to resolve
get_host_ip()
{
PINGRESULT=$(ping -c 1 -s 1 $1 2> /dev/null | grep "PING $1" | sed s/'PING '$1' ('/''/ | sed s/'): 1 data bytes'/''/)
echo $PINGRESULT
}
# $1 the hostname to resolve
# returns
# "noownip" when we have no ip
# "nohostip" when hostname has no ip (that is: can't be resolved)
# "1" if the hostname's ip is the same as our ip
# "0" if the hostnames's ip is different from your ip
compare_host_myip()
{
MYIP=$(get_WAN_info "ip")
[ "$MYIP" = "N/A" ] && {
echo "noownip"
return
}
HOIP=$(get_host_ip $1)
[ -z "$HOIP" ] && {
echo "nohostip"
return
}
[ $MYIP = $HOIP ] && echo "1" || echo "0"
}
# Make sure we have WAN connection before testing
w=$(WaitForSync 10 24 1)
RESULT=$(compare_host_myip $1)
[ "$RESULT" = "0" ] && $ULB/ppp_restore.sh
1) Author
2) Completed comment for function compare_host_myip
3) Changed comment at the end, because it wasn't a loop (In the first incarnation there was a loop when the script was called from init. But a cron job is definitively a better way to do that).
MfG Stefan Fröhlich
42
- thechief
- RouterTech Team
- Posts: 12067
- Joined: Wed Feb 01, 2006 10:22 pm
- Location: England, the Centre of Africa
- Contact:
Re: Update DDNS with RouterTech 2.94
I know. But it is still polite to ask. And it prevents future misunderstandings.TafnaSM wrote:That's the reason why i've posted it here.thechief wrote:If you don't object, then your script can be added to firmware v2.95, in this format (perhaps with a few tweaks for increased flexibility)
Yes, it should. I will move it there. There is just one little problem - in many cases, if the host is invalid, you will get a response containing the IP address of your DNS server. In cases where you are only checking for hosts that you know to exist (e.g., your ddns host), this is no problem. But for general use, where the host may be valid or invalid, perhaps some further tests might need to be added.TafnaSM wrote:But don't you think at least the function get_host_ip is usefull for other things and you should move it into rt_utils.sh?
Many thanks.TafnaSM wrote:However, if not, I've made three little changes to the script:
One change that I have made is this
Code: Select all
MYHOST="$1"
# empty parameter or "--help"
[ $HELPVAR -eq 1 ] && {
N=0
# if no parameter, then check for "myddns_host" in the env
[ -z "$MYHOST" ] && {
MYHOST=$(ramenv "myddns_host")
[ -n "$MYHOST" ] && N=1
}
[ $N -eq 0 ] && {
echo "Syntax = $ARGV0 <your dynamic DNS hostname>"
echo "Example: $ARGV0 mydnsentry.homedns.org"
echo ""
echo 'The host name can be stored in the environment variable: "myddns_host".'
echo "If this is done, then no argument is needed at the command line."
exit
}
}
The Chief: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
No support via PM. Ask all questions on the open forum.
Re: Update DDNS with RouterTech 2.94
I've never seen this behavior in my router. I tried invalid (unresolvable) and unreachable hosts. If it is invalid/unresolvable ping shows "bad address" and returns with an error, if it is unreachable, it shows the right IP address and returns with an error. Both is expected behavior.thechief wrote:Yes, it should. I will move it there. There is just one little problem - in many cases, if the host is invalid, you will get a response containing the IP address of your DNS server. In cases where you are only checking for hosts that you know to exist (e.g., your ddns host), this is no problem. But for general use, where the host may be valid or invalid, perhaps some further tests might need to be added.TafnaSM wrote:But don't you think at least the function get_host_ip is usefull for other things and you should move it into rt_utils.sh?
That is good. But isn't it possible to retrieve it from the router's configuration area instead of defining an other environment variable? It must be already there.thechief wrote:This allows you to specify the host in an environment variable ("myddns_host"), dispensing with the need to provide a command-line argument.
MfG Stefan Fröhlich
42
Re: Update DDNS with RouterTech 2.94
This may be a 'feature' of OpenDNS.TafnaSM wrote:I've never seen this behavior in my router. I tried invalid (unresolvable) and unreachable hosts. If it is invalid/unresolvable ping shows "bad address" and returns with an error, if it is unreachable, it shows the right IP address and returns with an error. Both is expected behavior.
- thechief
- RouterTech Team
- Posts: 12067
- Joined: Wed Feb 01, 2006 10:22 pm
- Location: England, the Centre of Africa
- Contact:
Re: Update DDNS with RouterTech 2.94
It probably is. I use OpenDNS, and I get the IP of an OpenDNS server (but not any of the publicised ones)mstombs wrote:This may be a 'feature' of OpenDNS.TafnaSM wrote:I've never seen this behavior in my router. I tried invalid (unresolvable) and unreachable hosts. If it is invalid/unresolvable ping shows "bad address" and returns with an error, if it is unreachable, it shows the right IP address and returns with an error. Both is expected behavior.
/var # ping bloggs
PING bloggs (67.215.65.132): 56 data bytes
64 bytes from 67.215.65.132: seq=0 ttl=56 time=50.000 ms
64 bytes from 67.215.65.132: seq=1 ttl=56 time=40.000 ms
64 bytes from 67.215.65.132: seq=2 ttl=56 time=40.000 ms
64 bytes from 67.215.65.132: seq=3 ttl=56 time=40.000 ms
The Chief: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
No support via PM. Ask all questions on the open forum.