Edit the file using command like this
Code:
vi /jffs/configs/dnsmasq.conf.add
how to use vi editor:
http://www.lagmonster.org/docs/vi.html
make sure these 2 lines are the only thing in that file. Hold down d key to delete other lines.
Code:
address=/0.0.0.0/0.0.0.0
addn-hosts=/tmp/adblock/hosts.blocked
That is the dnsmasq configuration part. For 2nd must have part, the scripts.
First make a file called "adblock" and add the following code into it: (sorry for lack of indentation, I find pasting into vi with indentation makes it even messier)
Code:
#!/bin/sh
MNTDIR=[COLOR="Red"]/tmp/mnt/dl/adblock[/COLOR]
TMPDIR=/tmp/adblock
counti=1
# Wait for Internet to be available.
logger -t $(basename $0) "wyxscript: Waiting for internet to come up"
while [ $counti -lt 20 ]
do
counti='expr $counti + 1'
ping -c 1 google.com
if [[ $? == 0 ]];
then
logger -t $(basename $0) "wyxscript: Internet is now up. "
# Adblocker Update v
if [ ! -f $TMPDIR/hosts.downloaded ];
then
mkdir /tmp/adblock
logger -t $(basename $0) "wyxscript: Downloading new blacklists"
wget -qO- \
"http://winhelp2002.mvps.org/hosts.txt" \
"http://someonewhocares.org/hosts/zero/hosts" \
"http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext&useip=0.0.0.0" \
| grep -w ^0.0.0.0 | sed $'s/\r$//' | sort -u > $TMPDIR/hosts.downloaded
else
logger -t $(basename $0) "wyxscript: Blacklist present, no need to redownload"
fi
if [ -f $MNTDIR/hosts.whitelist ];
then
logger -t $(basename $0) "wyxscript: Whitelist found, applying it. "
grep -v -f $MNTDIR/hosts.whitelist $TMPDIR/hosts.downloaded > $TMPDIR/hosts.blocked
cat $MNTDIR/hosts.blacklist | sed $'s/\r$//' >> $TMPDIR/hosts.blocked
else
logger -t $(basename $0) "wyxscript: Whitelist not found, using default filter. "
cp $TMPDIR/hosts.downloaded $TMPDIR/hosts.blocked
fi
logger -t $(basename $0) "wyxscript: Restarting dnsmasq"
chmod -R 777 $TMPDIR/
service restart_dnsmasq
# Adblocker Update ^
break;
else
logger -t $(basename $0) "wyxscript: Internet is not available yet...wait 30s...."
sleep 30s
fi
done
Summary of the above script:
1. Check for internet, waits 10 minutes for internet to come up, checking every 30 seconds. Make sure you can access google.com.
2. Now that internet is connected, it checks whether the filter list has been downloaded
2a. if not, download to TMPDIR
2b. if has been downloaded, log this and proceed.
3. Check if whitelist is present
3a. If it is, apply whitelist and blacklist to the filter
3b. If not, just copies downloaded list across
4. set correct permissions otherwise there is a chance Dnsmasq complains
5. restart Dnsmasq to let it read the filter list.
make adblock script executable:
Code:
chmod 777 /jffs/scripts/adblock
Now you have a choice of ways to use this script, read this and decide when this script should run.
https://github.com/RMerl/asuswrt-merlin/wiki/User-scripts
I call the script in wan-start and post-mount. To call the script, after reading "Creating scripts" section of the above guide, put the following line underneath shebang:
That's it. 1 config file, 1 script + however you decide to use it.
You should see this when the script is first run:
Code:
Sep 12 16:29:09 adblock: wyxscript: Waiting for internet to come up
Sep 12 16:29:09 adblock: wyxscript: Internet is now up.
Sep 12 16:29:09 adblock: wyxscript: Downloading new blacklists
Sep 12 16:29:12 adblock: wyxscript: Whitelist found, applying it.
Sep 12 16:29:12 adblock: wyxscript: Restarting dnsmasq
...
Sep 12 16:29:13 dnsmasq[4521]: read /tmp/adblock/hosts.blocked - 23817 addresses
...
Also, don't forget to do scheduled reboot. The script is designed so that only on each reboot you update your block list.
https://github.com/RMerl/asuswrt-merlin/wiki/Scheduled-Reboot
Optionally you many want whitelist and blacklist.
Edit the text in red to point it to the folder your whitelist and blacklist are situated. The lists should be called hosts.whitelist and hosts.blacklist. It doesn't matter where they are, they can be in /jffs or on a USB stick, as long as red text points to there the script will find it. You are safe to put it into /jffs as these 2 files don't change often.
Example of whitelist and blacklist are in Colin's post here:
http://forums.smallnetbuilder.com/showthread.php?t=18895&page=2
Credit goes to ColinTaylor for the original script.