1 (edited by exobyte 2008-01-09 02:32:30)

Topic: dyndns update script

The dyndns client I was using was updating too often.  I ran across this post: http://forum.openwrt.org/viewtopic.php?pid=48762#p48762

I made a few improvements from what I found there.  Now, you can set it to monitor an interface (eth0), a network (lan, wan), or query the web.  I also added error checking for when ifconfig/wget don't return an ip address and when nslookup fails.

If you seen any changes that are needed, please help!!

#! /bin/sh

. $IPKG_INSTROOT/etc/functions.sh
include /lib/network

USER="username"
PASS="password"
DOMAIN="sgfdgsdfg.dyndns.org.org"

# Where should we look for the current IP
# IP_SOURCE= "interface" | "network" | "web"
#
# IP_SOURCE="interface"
#   IP_INTERFACE="eth0.0"
#
# IP_SOURCE="network"
#   IP_NETWORK="wan"
#
# IP_SOURCE="web"

IP_SOURCE="network"
IP_NETWORK="wan"


IP_ADDR_RE="[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}"

r=`nslookup $DOMAIN 2> /dev/null`
if [ $? ]
then
  registered=`echo $r | grep -o 'Name:.*' | grep -o $IP_ADDR_RE`
  echo $registered currently registered
else
  registered="0.0.0.0"
  echo No IP address registered
fi

max_days=28 # max number of days to go without forcing an update
last_update=`date +%s`

max_seconds=`expr $max_days \* 24 \* 60 \* 60`

while [ true ]
do

  if [ "$IP_SOURCE" = "network" ]
  then
    scan_interfaces
    config_load /var/state/network
    config_get IP_INTERFACE $IP_NETWORK ifname
  fi

  if [ "$IP_SOURCE" = "network" ] || [ "$IP_SOURCE" = "interface" ]
  then
    current=`ifconfig $IP_INTERFACE | grep -o 'inet addr:[0-9.]*' | grep -o $IP_ADDR_RE`
  elif [ "$IP_SOURCE" = "web" ]
  then
    current=$(wget -O /dev/null http://checkip.dyndns.org|sed s/[^0-9.]//g)
  fi

  if [ $(($last_update+$max_seconds)) -lt `date +%s` ]
  then
    # set old_ip to be different, forcing an update
     registered="0.0.0.0"
  fi

  if [ "$current" != "$registered" ] && [ `echo "$current" | grep "^$IP_ADDR_RE$"` ]
  then
    wget -O /dev/null http://$USER:$PASS@members.dyndns.org/nic/update?hostname=$DOMAIN

    if [ $? ]
    then
      registered=$current
      last_update=`date +%s`
    fi
  fi
  sleep 300
done &

Re: dyndns update script

Just wondering: why not using the ez-ipupdate package?

OpenWrt Backfire 10.03.1-rc5 on Asus WL-500G :: Attitude Adjustment 12.09.1 (r40432) on Asus WL-500G Deluxe / Netgear WNDR3700 v1 / TP-Link TL-WR1043ND :: Attitude Adjustment 12.09 on WNDR3700 v2 & TP-Link TL-WR841N :: Attitude Adjustment 12.09+ (r35342) on TL-WR841N & Asus WL-500W (Linux 3.2, b43)

3 (edited by exobyte 2008-01-09 00:25:14)

Re: dyndns update script

Borromini wrote:

Just wondering: why not using the ez-ipupdate package?

It wasn't mentioned in here http://wiki.openwrt.org/DDNSHowTo or when I searched for "banned," "updatedd," "openwrt," and "dyndns." (updatedd is buggy, it seems)

Re: dyndns update script

Ok. Ez-ipupdate is available through ipkg and it's very nice. Haven't had any problems with it.

OpenWrt Backfire 10.03.1-rc5 on Asus WL-500G :: Attitude Adjustment 12.09.1 (r40432) on Asus WL-500G Deluxe / Netgear WNDR3700 v1 / TP-Link TL-WR1043ND :: Attitude Adjustment 12.09 on WNDR3700 v2 & TP-Link TL-WR841N :: Attitude Adjustment 12.09+ (r35342) on TL-WR841N & Asus WL-500W (Linux 3.2, b43)

Re: dyndns update script

hi, i am new to this forum.. i had a similar problem, and what seems to work for me is:

1) register with dyndns.org
2) ipkg install ez-ipupdate
3) edit /etc/ez-ipupdate.conf like this:

---
interface=ppp0
service-type=dyndns
user=youruser:yourpasswd
host=yourhost.dyndns.org
quiet

# Do not change the lines below
cache-file=/tmp/ez-ipupdate.cache
pid-file=/var/run/ez-ipupdate.pid
---
4) create /etc/ppp/ip-up.d/S01dyndns like this:
---
#!/bin/sh
/usr/sbin/ez-ipupdate -c /etc/ez-ipupdate.conf
---
and don't forget to
5) chmod a+x /etc/ppp/ip-up.d/S01dyndns

works - up til now - like charme for me :-)

Re: dyndns update script

wkapga wrote:

4) create /etc/ppp/ip-up.d/S01dyndns like this:

Why did you need that?
The ez-ipupdate package already comes with a file /etc/hotplug.d/iface/30-ez-ipupdate which should take care of running ez-ipupdate when necessary.

Re: dyndns update script

hmm... you are right... nevertheless, it did not work straight out of the box..
maybe i set the interface wrong somewhere in my config?
dydns was just not updated before i created the script 4)...

i guess i have to do some further research :-)
but for now it's a case of "never change a running system" :-)))

thanks

Re: dyndns update script

I seem to recall running into problems with ez-ipupdate as well. If I recall correctly, in my case, the IP address didn't update when the ISP assigned a new IP address when renewing the DHCP lease; it would only update if I rebooted the router. Looking at the hotplug script, it appears to update only when the WAN interface first comes up.

Re: dyndns update script

placebo: that sounds very reasonable - ihad exactly the same issue.. so i will stuck with my solution described above which still works flawlessly...
should we contact a maintainer of the package?

Re: dyndns update script

.... docs. do you read them?

# cat /etc/ez-ipupdate.conf
service-type=dyndns
user=foo:bar
host=foobar.ath.cx
interface=ppp0
max-interval=2073600
#quiet

# Do not change the lines below
cache-file=/tmp/ez-ipupdate.cache
pid-file=/var/run/ez-ipupdate.pid

Re: dyndns update script

it seems that i am too stupid to find the doc. the doc on ez-ipupdate.com is down, the tar contained examples but no doc. and i did not find anything on the wiki/forum..
weedy, can you please be so kind point me (and other readers of this thread) in the right direction - maybe this would be good way to close this thread:-)

Re: dyndns update script

Weedy wrote:

.... docs. do you read them?

# cat /etc/ez-ipupdate.conf
service-type=dyndns
user=foo:bar
host=foobar.ath.cx
interface=ppp0
max-interval=2073600
#quiet

# Do not change the lines below
cache-file=/tmp/ez-ipupdate.cache
pid-file=/var/run/ez-ipupdate.pid

What's your point?

Re: dyndns update script

Weedy wrote:
...
cache-file=/tmp/ez-ipupdate.cache
...

Your cache file will be removed after a reset causing the abuse of the service when resetting the device more times.
I would place the cache file in the jffs2 partition when there are only 14 writes expected within a year.

Re: dyndns update script

Hello, I'm noo to OpenWRT.

When using some version one of these scripts that update dyndns (custom) under whiterussian 0.9, what would be a good way to push the new wan ip into the config of other parts of the router?

I have some loopback port forwarding configured that requires the current wan ip (in firewall.uer).

ex:
iptables -t nat -A prerouting_rule -d 71.75.16.19 -p tcp --dport 80 -j DNAT --to 192.168.1.5

71.75.16.19  is the current wan ip. How do I best update\maintain firewall.user and kick /init.d/S35firewall?

Re: dyndns update script

for most usages you could replace -d wan_ip with -i wan_interface, which will not change

Re: dyndns update script

Weedy wrote:

.... docs. do you read them?

# cat /etc/ez-ipupdate.conf
service-type=dyndns
user=foo:bar
host=foobar.ath.cx
interface=ppp0
max-interval=2073600
#quiet

# Do not change the lines below
cache-file=/tmp/ez-ipupdate.cache
pid-file=/var/run/ez-ipupdate.pid

Hi. It seems ez-ipdate will check/update the ip every 10minutes.
How to change the periodic checking?

I tried this in /etc/ez-ipupdate.conf

...
period=1800  ### 30minutes interval check
...

but it's still checking every 10minues, based on the info from 'logread'.

Thanks.

Re: dyndns update script

Exobyte, thanks for your excellent script!  I have expanded upon it and built a set of scripts to configure dynamic dns using a uci config file (/etc/config/ddns).  This script can be configured to connect to one of several dynamic dns service providers (dyndns.org, no-ip.com etc.) I have also built a new version of wget that uses matrixssl (100kb) instead of openssl ( 1MB) so that wget can still connect via ssl (to providers that require it), but not take up a huge amount of disk space.  My new ddns-scripts package as well as the new wget package can be found here.

Re: dyndns update script

@exobyte

Your script works fine, thanks for that. But there seems to be one limitation:
I use the X-wrt Image with built-in webif^2 - so this behaviour might be different to what users with pure OpenWrt expierence.
Anyway, when I check the log after the ISP changed my IP I get following message:

"Apr  4 06:13:46 (none) user.notice ddupd: X.227.192.146 currently registered"

That's the IP the router had before dyndns-update. Finally I found out that it needs about a minute to get the correct (new) IP. I wanted the log to inform me about the up to date IP. The following works for me (/etc/ppp/ip-up.d/S10-Host-Request):

#!/bin/sh
sleep 70
wget -O - http://checkip.dyndns.org|sed 's/[^0-9.]//g' | /usr/bin/logger -t "Current IP"  
nslookup myhost.dyndns.org | grep Name: | /usr/bin/logger -t "Registered Hostname"
nslookup myhost.dyndns.org | grep Address: | /usr/bin/logger -t "Registered with IP"

19 (edited by forum2008 2008-04-04 12:21:29)

Re: dyndns update script

There has been added a new package called ddns-scripts. Maybe give it a try. It's configurable via UCI (Unified Configuration Interface). The config file is /etc/config/ddns.

Re: dyndns update script

Very great~!
Keep up the great work~!

Re: dyndns update script

Hi! I have just installed the ddns-scripts package, as described in http://oldwiki.openwrt.org/DDNSHowTo.html, however, it does not work.
I have configured it for zoneedit.com, using the correct username and password. But every time I change IP (via PPPoE), this happens (ps aux):

 1625 root      2048 S    /bin/sh /usr/lib/ddns/dynamic_dns_updater.sh myddns 0
 1785 root      2048 S    /bin/sh /usr/lib/ddns/dynamic_dns_updater.sh myddns 0
 1854 root      2048 S    /bin/sh /usr/lib/ddns/dynamic_dns_updater.sh myddns 0
 1856 root      1968 S    nc dynamic.zoneedit.com 80 
 1857 root      1960 S    cat

And there it hangs, doing nothing.

Re: dyndns update script

I'm having the exact same issue...

Looking at wire captures, I see it send the HTTP request to dynamic.zoneedit.com, and then zoneedit immediately sends a FIN,ACK packet (to immediately close the connection).

From what I can tell, the update is not successful either. So this is definitely not working currently with zoneedit.

Bummer.

Re: dyndns update script

Ahh, the problem seems to be the shell_get thing. Not sure exactly what it's doing wrong, but I installed wget-nossl and mucked with the scripts a bit and it seems to be working now.

I'll do a bit more poking at it later to see if I can determine the cause of the problem.

Re: dyndns update script

FWIW, I opened a TRAC bug on the zoneedit problems. The problem, I think is that shell_get isn't sending CR-LF as end of line chars. It's just sending linefeeds. Luckily, it looks like the shell_get thing really isn't needed, and the wget in busybox is sufficient after all.

More details here:

https://dev.openwrt.org/ticket/5202

25 (edited by gcbwrt 2011-06-02 07:45:27)

Re: dyndns update script

[s]easiest solution:

# crontab -e

add:

0 0 */2 * * wget -q -O - http://username:password@members.dyndns.org/nic/update?hostname=your.full.domain.dyndns.com

Can't get any easier than that![/s]

edit: i'm dumb smile ignore all that. really.