DynDNS Update for particular net interface

Home Page Forums Network Management Request a new feature DynDNS Update for particular net interface

This topic contains 6 replies, has 0 voices, and was last updated by  faximilian 3 years, 11 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #44156

    faximilian
    Member

    Dear Fulvio,

    I have already written to you yesterday on reqesting a new activation key.

    I have multiple WAN interfaces. Unfortunately the DDNS settings do not a allow to specify which WAN interface is used to determine the WAN IP address.

    Could you please insert an option to define the DDNS settings for a particular WAN interface (“Get public IP adress from the following Interface:”). As an alternative it would be very nice to be able to set multiple DDNS-Settings (e. g. setting 1: Dyndns domain for WAN1, setting 2: No-IP domain for WAN 2, etc.)

    As a workaround I have used at the moment the NetBalancer rules: Traffic to members.dydns.org and checkip.dyndns.org is lead only through a particular interface. I hope dyndns will never change its IPs…

    Thanks in advace!

    Regards,

    faximilian

    #53629

    faximilian
    Member

    in order to get the IP adress of the local interface you could use

    IP=`ifconfig ppp0 | awk ‘/inet addr/{print substr($2,6)}’`

    instead of the code below in your ddns2 script

    # IP=`wget –timeout=15 -t 1 -O – -o /dev/null $CHECKIP_URL |egrep ‘[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}’|head -1|sed -r ‘s/.* ([0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}).*/1/’`

    Actually this only a workaround.

    REMARK: EVEN THIS IS NOT A WORKAROUND BECAUSE DYNDNS USES THE IP FROM WHICH THE COMPUTER CONNECTS TO THE SERVER AS THE DYNAMIC IP

    I am still looking for a possibility to access a particular website (checkip.dyndns.com) through a defined interface while using NetBalancer. Defining a rule does not work because dyndns.com uses dynamic ip addresses for their servers…

    #53630

    redfive
    Participant

    If you have multiple pppx interfaces, this could be a good starting point.
    Regards

    #53631

    faximilian
    Member

    I would suggest to use

    curl –interface $INTERFACE

    instead of

    wget

    in the ddns updater script. This should solve the problem in a good way.

    Dear Fulvio,

    could you perhaps help with a solution.

    Regards,

    Fabian

    #53632

    faximilian
    Member

    Hi redfive,

    thanks for your answer.

    The script you linked to uses the –bind-address option.

    This is only a good idea if the interface WAN address is known to the router. If not, the script will fail. E. g., in my case I am using a connection to a second router as a WAN connection. wget –bind-address would simply not work here.

    For this reason I would suggest to use curl instead of wget.

    Regards,

    faximilian

    #53633

    faximilian
    Member

    The second solution I would suggest is to add an option for IP resoulution in the NetBalancer settings: “Use interface XY on targeting an IP which is defined by the following domain name…”

    #53634

    faximilian
    Member

    Now I have tried to replace wget commands by curl commands. Additionally I added a variable called INTERFACE which should be defined by the GUI.

    However, I don’t know how to test economically the script in zeroshell.

    Could someone please help me to debug the code:



    #!/bin/sh
    . /etc/kerbynet.conf
    sleep 35
    RESOLUTION=1.1.1.1
    while true ; do
    CHANGED=no
    EXPIRED=no
    SKIP=no
    if [ "`cat $REGISTER/system/ddnsclient/Enabled 2>/dev/null`" == yes ] ; then
    OLDHOST="$REGISTER/system/ddnsclient/OldHOST"
    OLDIP="$REGISTER/system/ddnsclient/OldIP"
    LASTUPDATE="$REGISTER/system/ddnsclient/LastUpdate"
    STATUS="$REGISTER/system/ddnsclient/Status"
    INTERFACE="$REGISTER/system/ddnsclient/Interface"
    CHECKIP_URL="`cat $REGISTER/system/ddnsclient/CheckIP`"
    IP=`curl -G --interface $INTERFACE --retry 1 -s $CHECKIP_URL |egrep '[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}'|head -1|sed -r 's/.* ([0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}).*/1/'`
    if ! echo $IP | egrep -q '^[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}$'; then
    logger -t DDNS "ERROR: IP checker not available ($CHECKIP_URL)"
    SKIP=yes
    fi

    PROVIDER="`cat $REGISTER/system/ddnsclient/Provider 2>/dev/null`"
    HOST="`cat $REGISTER/system/ddnsclient/Host 2>/dev/null`"
    [ -z "$HOST" ] && SKIP=yes
    if [ "$HOST" != "`cat $OLDHOST 2>/dev/null`" ] ; then
    CHANGED=yes
    fi
    if [ "$IP" != "`cat $OLDIP 2>/dev/null`" ] ; then
    CHANGED=yes
    fi
    TIMESTAMP=`date +%s`
    OLDTS="`cat $LASTUPDATE 2>/dev/null`"
    if ! [ -z "$OLDTS" ] ; then
    if [ "$(( TIMESTAMP - OLDTS ))" -gt 2073600 ] ; then
    EXPIRED=yes
    fi
    fi
    if [ "$PROVIDER" = ".OpenDNS" ] ; then
    RESOLUTION=1.1.1.1
    else
    RESOLUTION=`host $HOST 2>/dev/null |egrep '[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}'|head -1|awk '{print $4}'`
    fi
    if [ "$IP" != "$RESOLUTION" ] ; then
    CHANGED=yes
    echo "WAITING TO BE UPDATED" > $STATUS
    else
    echo "UPDATED" > $STATUS
    fi
    if [ "$SKIP" != yes ] ; then
    if [ "$CHANGED" == yes -o "$EXPIRED" == yes -o "$PROVIDER" = "OpenDNS" ] ; then
    if [ "$CHANGED" != yes -a "$EXPIRED" == yes ] ; then
    logger -t DDNS "WARNING: Update is needed to prevent $HOST expiration"
    fi
    if [ "$IP" != "$RESOLUTION" -o "$EXPIRED" == yes ] ; then
    if [ "$PROVIDER" != "OpenDNS" ] ; then
    logger -t DDNS "WAN IP=$IP $HOST=$RESOLUTION (Update is needed)"
    else
    logger -t DDNS "WAN IP=$IP"
    fi
    ERROR="/tmp/dyndns.err"
    RESULT="/tmp/dyndns.out"
    USERNAME="`$SCRIPTS/getkey /system/ddnsclient/Username`"
    PASSWORD="`$SCRIPTS/getkey /system/ddnsclient/Password`"
    logger -t DDNS "Dynamic DNS updating $HOST ($USERNAME)"

    if [ "$PROVIDER" = "OpenDNS" ] ; then
    OPT="--user $USERNAME:$PASSWORD"
    CURL="https://updates.opendns.com/nic/update?"
    elif [ "$PROVIDER" = "DynDNS" ] ; then
    OPT="--user $USERNAME:$PASSWORD"
    CURL="http://members.dyndns.org/nic/update?system=dyndns&hostname=$HOST&mx=$HOST"
    else
    # No-IP
    OPT="--user $USERNAME:$PASSWORD"
    CURL="http://dynupdate.no-ip.com/nic/update?hostname=$HOST&mx=$HOST"
    fi
    if ! curl -G --interface $INTERFACE --retry 1 --connect-timeout 15 -s -S -o "$RESULT" $OPT "$CURL" 2>"$ERROR" ; then
    if grep -q "Authorization failed" "$ERROR" ; then
    CURLERROR="Authorization failed. BAD Username/Password"
    else
    CURLERROR="Connectivity ERROR"
    fi
    else
    CURLERROR=""
    fi
    if [ -z "$CURLERROR" ] ; then
    logger -t DDNS "==> `cat $RESULT`"
    if grep -q "!yours|notfqdn|abuse|nohost|badagent|badauth|badsys|dnserr|numhost|911|!donator" $RESULT ; then
    echo "Disabled for fatal ERROR. Please check the logs" > $STATUS
    logger -t DDNS "==> A fatal error occurs and the DDNS client is now disabled. Please solve the problem and enable the Dynamic DNS Client."
    echo no > $REGISTER/system/ddnsclient/Enabled
    else
    echo "UPDATED" > $STATUS
    echo $HOST > $OLDHOST
    echo $IP > $OLDIP
    echo $TIMESTAMP > $LASTUPDATE
    fi
    else
    echo "$CURLERROR" > $STATUS
    logger -t DDNS "ERROR:"
    grep -v " => " "$ERROR" | logger -t DDNS
    fi
    fi
    fi
    fi
    fi
    sleep 304
    done


    #53635

    faximilian
    Member

    The following script works well a a cron script

    You only have to adapt the INTERFACE variable



    #!/bin/sh
    . /etc/kerbynet.conf
    RESOLUTION=1.1.1.1
    CHANGED=no
    EXPIRED=no
    SKIP=no
    if [ "`cat $REGISTER/system/ddnsclient/Enabled 2>/dev/null`" != yes ] ; then
    OLDHOST="$REGISTER/system/ddnsclient/OldHOST"
    OLDIP="$REGISTER/system/ddnsclient/OldIP"
    LASTUPDATE="$REGISTER/system/ddnsclient/LastUpdate"
    STATUS="$REGISTER/system/ddnsclient/Status"
    INTERFACE="ppp0"
    CHECKIP_URL="`cat $REGISTER/system/ddnsclient/CheckIP`"
    IP=`curl -G --interface $INTERFACE --retry 1 -s $CHECKIP_URL |egrep '[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}'|head -1|sed -r 's/.* ([0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}).*/1/'`
    if ! echo $IP | egrep -q '^[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}$'; then
    logger -t DDNS "ERROR: IP checker not available ($CHECKIP_URL)"
    SKIP=yes
    fi

    PROVIDER="`cat $REGISTER/system/ddnsclient/Provider 2>/dev/null`"
    HOST="`cat $REGISTER/system/ddnsclient/Host 2>/dev/null`"
    [ -z "$HOST" ] && SKIP=yes
    if [ "$HOST" != "`cat $OLDHOST 2>/dev/null`" ] ; then
    CHANGED=yes
    fi
    if [ "$IP" != "`cat $OLDIP 2>/dev/null`" ] ; then
    CHANGED=yes
    fi
    TIMESTAMP=`date +%s`
    OLDTS="`cat $LASTUPDATE 2>/dev/null`"
    if ! [ -z "$OLDTS" ] ; then
    if [ "$(( TIMESTAMP - OLDTS ))" -gt 2073600 ] ; then
    EXPIRED=yes
    fi
    fi
    if [ "$PROVIDER" = ".OpenDNS" ] ; then
    RESOLUTION=1.1.1.1
    else
    RESOLUTION=`host $HOST 2>/dev/null |egrep '[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}'|head -1|awk '{print $4}'`
    fi
    if [ "$IP" != "$RESOLUTION" ] ; then
    CHANGED=yes
    echo "WAITING TO BE UPDATED" > $STATUS
    else
    echo "UPDATED" > $STATUS
    fi
    if [ "$SKIP" != yes ] ; then
    if [ "$CHANGED" == yes -o "$EXPIRED" == yes -o "$PROVIDER" = "OpenDNS" ] ; then
    if [ "$CHANGED" != yes -a "$EXPIRED" == yes ] ; then
    logger -t DDNS "WARNING: Update is needed to prevent $HOST expiration"
    fi
    if [ "$IP" != "$RESOLUTION" -o "$EXPIRED" == yes ] ; then
    if [ "$PROVIDER" != "OpenDNS" ] ; then
    logger -t DDNS "WAN IP=$IP $HOST=$RESOLUTION (Update is needed)"
    else
    logger -t DDNS "WAN IP=$IP"
    fi
    ERROR="/tmp/dyndns.err"
    RESULT="/tmp/dyndns.out"
    USERNAME="`$SCRIPTS/getkey /system/ddnsclient/Username`"
    PASSWORD="`$SCRIPTS/getkey /system/ddnsclient/Password`"
    logger -t DDNS "Dynamic DNS updating $HOST ($USERNAME)"

    if [ "$PROVIDER" = "OpenDNS" ] ; then
    OPT="--user $USERNAME:$PASSWORD"
    CURL="https://updates.opendns.com/nic/update?"
    elif [ "$PROVIDER" = "DynDNS" ] ; then
    OPT="--user $USERNAME:$PASSWORD"
    CURL="http://members.dyndns.org/nic/update?system=dyndns&hostname=$HOST&mx=$HOST"
    else
    # No-IP
    OPT="--user $USERNAME:$PASSWORD"
    CURL="http://dynupdate.no-ip.com/nic/update?hostname=$HOST&mx=$HOST"
    fi
    if ! curl -G --interface $INTERFACE --retry 1 --connect-timeout 15 -s -S -o "$RESULT" $OPT "$CURL" 2>"$ERROR" ; then
    if grep -q "Authorization failed" "$ERROR" ; then
    CURLERROR="Authorization failed. BAD Username/Password"
    else
    CURLERROR="Connectivity ERROR"
    fi
    else
    CURLERROR=""
    fi
    if [ -z "$CURLERROR" ] ; then
    logger -t DDNS "==> `cat $RESULT`"
    if grep -q "!yours|notfqdn|abuse|nohost|badagent|badauth|badsys|dnserr|numhost|911|!donator" $RESULT ; then
    echo "Disabled for fatal ERROR. Please check the logs" > $STATUS
    logger -t DDNS "==> A fatal error occurs and the DDNS client is now disabled. Please solve the problem and enable the Dynamic DNS Client."
    echo no > $REGISTER/system/ddnsclient/Enabled
    else
    echo "UPDATED" > $STATUS
    echo $HOST > $OLDHOST
    echo $IP > $OLDIP
    echo $TIMESTAMP > $LASTUPDATE
    fi
    else
    echo "$CURLERROR" > $STATUS
    logger -t DDNS "ERROR:"
    grep -v " => " "$ERROR" | logger -t DDNS
    fi
    fi
    fi
    fi
    fi

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.