Updating OpenDNS from your Tomato Router

Here is a script that will update OpenDNS to have your Tomato Router (or similars) IP address, so that filtering works.

I have it running as the WAN script, for when the WAN (Fibre connection) comes up.

Before the the script will run, you need to login to http://dnsomatic.com
with your username and password and
goto Account / Your Services / Expand All and click on [update account info]

Administration / Scripts / WAN up

#!/bin/sh

UNAME=OpenDNSuserName        # username
PWORD=OpenDNSpassWord        # password (plaintext, sorry!)
HNAME=all.dnsomatic.com            # you can set this to all.dnsomatic.com or you can specify the LABEL of the network/host to update
ERROR=5                    # times to retry
MYIP=`dig myip.opendns.com +short`
TMPFILE=${TMPDIR}wget.txt
if [ "${HNAME}" = "all.dnsomatic.com" ]; then NETNAME=ALL; else NETNAME=${HNAME}; fi

rm -f $TMPFILE

update()
{
    echo Updating HOST [${NETNAME}] with IP ${MYIP}
    wget --quiet --output-document $TMPFILE --user-agent="tomatoUSB - WAN Script - 0.1" http://${UNAME}:${PWORD}@updates.dnsomatic.com/nic/update?hostname=${HNAME}&myip=${MYIP}&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
    WGETRES=$?; echo "WGET=${WGETRES}"
    cat $TMPFILE | grep -c "good $MYIP"
    RES2=$?
    echo RES2 $RES2
    if [ "$RES2"  = "1" ]
    then
        echo update successful ${MYIP}
    logger OpenDNS updated successfully ${MYIP}
    else
    while [ $ERROR -gt 0 ]; do
        ERROR=$(($ERROR-1))
        echo waiting 10 seconds
        sleep 10s
        update
    done
    echo Failed trying to update
    logger OpenDNS update failed
    fi
}

update

exit 0

Leave a Reply

Your email address will not be published. Required fields are marked *