Ad Block Script & DDNS

Discussion in 'Tomato Firmware' started by Bosnoval, Sep 24, 2013.

  1. Bosnoval

    Bosnoval Networkin' Nut Member

    I've just recently been testing out the following ad blocking WAN Up script taken from this forum:

    logger WAN UP Script Executing
    sleep 5
    test -s /tmp/dlhosts
    if [ $? == 1 ] ; then
        echo -e "#!/bin/sh\nwget -O - | grep | sed -e '2,\$s/' -e 's/[[:space:]]*#.*$//' > /etc/hosts\nlogger DOWNLOADED\nkillall -1 dnsmasq" > /tmp/dlhosts
        chmod 777 /tmp/dlhosts
    cru a Gethosts "45 23 * * 5 /tmp/dlhosts"
    Would this script interfere with Tomato's DDNS settings? I noticed shortly after testing that that my dynamic domain was no longer resolving internally. If so, is there a change I can make to fix this?

    Asus RT-N66U
    Tomato Firmware v1.28.0502 MIPSR2Toastman-RT-N K26 USB VPN
  2. koitsu

    koitsu Network Guru Member

    I see all kinds of problems with this:

    1. Some bogus/badly formatted entry that ends up in /etc/hosts that dnsmasq might not like could result in killall -1 dnsmasq (same as SIGHUP) causing dnsmasq to die off; in turn this would cause DNS failure across the board (not just DDNS). It all depends on what dnsmasq does in it's SIGHUP handler.

    2. There may also be some startup race condition where on reboot dnsmasq might start up but the WAN Up script might be conflicting with it in some way (i.e. a timing issue), but I'm doubting this.

    3. Biggest issue as I see it: this methodology stomps over /etc/hosts entirely! This is completely and entirely wrong in every way/shape/form. It does not append to /etc/hosts (nor should it!), it literally overwrites it. Tomato, on startup, adds its own entries to /etc/hosts which are needed for proper functionality.

    Addressing Issue #3 is easy: use the addn-hosts=/tmp/adblock.hosts feature of dnsmasq Custom Configuration part of the GUI (read the docs please!) and instead change that script to use /tmp/adblock.hosts instead of /etc/hosts. Keep these two things segregated. Do not touch /etc/hosts, ever -- let Tomato manage that file.

    You could also try not using addn-hosts at all and instead just putting the data into a file called /etc/dnsmasq/hosts/adblock. From what I can tell, the stock dnsmasq config contains addn-hosts=/etc/dnsmasq/hosts except that isn't a file -- it's a directory -- containing a file called hosts (i.e. the full path is /etc/dnsmasq/hosts/hosts) which also contains necessary data (again, Tomato-managed, do not mess with this file!). Possibly dnsmasq's addn-hosts option, if given a directory, reads the contents of all the files in that directory and treats them as addn-hosts content? Not sure; the docs aren't clear, so try this method at your own behest.

    I should also note that the "script" contained within the echo -e statement has absolutely no form of error checking; it's blind and stupid. It makes horrible, horrible assumptions. I refuse to analyse any further part of it.

    Good luck, I cannot help past this point.
    Last edited: Sep 25, 2013
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice