What's new

Simple AdBlocking dnsmasq

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Xerxist

Regular Contributor
I found a simple script that wasn't working at first but after I made my own adjustments this works fine on the Asus Merlin builds with Entware installed.

This uses dnsmasq to block ads and automatically updates every day at 6AM.

Install Entware

https://github.com/RMerl/asuswrt-merlin/wiki/Entware

Add the following lines to /jffs/scripts/services-start

Code:
wget "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext" -O "/tmp/dnsmasq.adblock.conf"
echo "conf-file=/tmp/dnsmasq.adblock.conf" >> /etc/dnsmasq.conf
killall dnsmasq
sleep 3
dnsmasq -c 1500 --log-async -n
(crontab -l ; echo "0 6 * * * """/jffs/scripts/updateadblock.sh"") |crontab -
killall crond
crond

Create the following file /jffs/scripts/updateadblock.sh

Code:
wget "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext" -O /tmp/dnsmasq.adblock.conf
killall dnsmasq
sleep 3
dnsmasq -c 1500 --log-async -n

Make the /jffs/scripts/updateadblock.sh executable

chmod +x /jffs/scripts/updateadblock.sh

Reboot the router
 
Last edited:
Awesome

I am so novice that still stuck at making a script
I have enabled JFFS, so basically copy/paste above in txt file and rename to that service-start but what what ext?
And then execute in Winscp?
 
Awesome

I am so novice that still stuck at making a script
I have enabled JFFS, so basically copy/paste above in txt file and rename to that service-start but what what ext?
And then execute in Winscp?

If you have enabled JFFS and installed entware you can install nano.

opkg install nano

/jffs/scripts/services-start (this already exists when entware is installed)

nano /jffs/scripts/services-start

copy and paste at the bottom

wget "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mime type=plaintext" -O "/tmp/dnsmasq.adblock.conf"
echo "conf-file=/tmp/dnsmasq.adblock.conf" >> /etc/dnsmasq.conf
killall dnsmasq
sleep 3
dnsmasq -c 1500 --log-async -n
(crontab -l ; echo "0 6 * * * """/jffs/scripts/updateadblock.sh"") |crontab -
killall crond
crond

Press control+O and enter
Press control+X to quit nano

nano /jffs/scripts/updateadblock.sh

copy and paste

wget "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mime type=plaintext" -O /tmp/dnsmasq.adblock.conf
killall dnsmasq
sleep 3
dnsmasq -c 1500 --log-async -n

Press control+O and enter
Press control+X to quit nano

Then follow the rest of the commands.
 
Last edited:
There's a problem with wget command.

The file generated by wget has the following html tags.
And dnsmasq doesn't like them :)

Code:
<html>

<head>
<meta name="author" value="Peter Lowe; pgl@yoyo.org">
<meta name="description" value="Ad server hostnames for blocking ads (format: dnsmasq -- for use with dnsmasq (link
<meta name="keywords" value="ad blocking, blocking ads, ad servers, ads, banners, hosts file, privacy">

<link rel=alternate type="application/rss+xml" title="Ad server hostnames for blocking ads (format: dnsmasq -- for

<title>
Ad server hostnames for blocking ads (format: dnsmasq -- for use with dnsmasq (linksys routers?))</title>

<link rel='stylesheet' href='/css/pgl.css' type='text/css'></head>

<body>



<p><pre>

And in the bottom the </html>
I'm looking for remove them..
 
There's a problem with wget command.

The file generated by wget has the following html tags.
And dnsmasq doesn't like them :)

Code:
<html>

<head>
<meta name="author" value="Peter Lowe; pgl@yoyo.org">
<meta name="description" value="Ad server hostnames for blocking ads (format: dnsmasq -- for use with dnsmasq (link
<meta name="keywords" value="ad blocking, blocking ads, ad servers, ads, banners, hosts file, privacy">

<link rel=alternate type="application/rss+xml" title="Ad server hostnames for blocking ads (format: dnsmasq -- for

<title>
Ad server hostnames for blocking ads (format: dnsmasq -- for use with dnsmasq (linksys routers?))</title>

<link rel='stylesheet' href='/css/pgl.css' type='text/css'></head>

<body>



<p><pre>

And in the bottom the </html>
I'm looking for remove them..

I just checked on my router but I only have ip's.


like this :

ddress=/101com.com/127.0.0.1
address=/101order.com/127.0.0.1
address=/103bees.com/127.0.0.1
address=/123found.com/127.0.0.1
address=/123pagerank.com/127.0.0.1
address=/180hits.de/127.0.0.1
address=/180searchassistant.com/127.0.0.1

Let me double check the script and clean up the first post a bit.
Which editor and terminal are you using?
I'm using putty and nano to edit the scripts as vi gave me problems with copy and pasting some times.
 
Last edited:
Please go easy on me, this is only like my 5th time using terminal, installing entware (I put it on a USB stick) and all was totally new to me, but this was a functionality I was really looking to install so I thought I'd try it out.

I followed the instructions, thank you to the guys who posted and shared them!

I was particularly interested because I had been trying to do some of this manually in the URL filter of my RT-N66, but noticed a really slow responsiveness in the browser (i.e. it'd just hang waiting for the ads or whatever I was trying to filter out, and just drag down the page load, the opposite effect of what I was looking for). I mentioned that over in this other thread.

Anyway, is there a way to check and see in my logs what this has actually blocked and know if it's working? I took a look at the list that it uses and just picked an IP off it (95.101.248.241) and just tried going to that URL and it basically just waited for it to load for 20-30+ sec and eventually gave up. Which is pretty much like the Asus URL filter acts. And I was reading on the webpage and the author seemed to think it was designed to give a quick "not found" response (are we not using the IPtables implementation of it?).

I dunno, I wish (maybe there is?) a way I could still add a bunch of URLs to this myself.

Thanks in advance for your help, and like I said, go easy on me! ;)
 
Please go easy on me, this is only like my 5th time using terminal, installing entware (I put it on a USB stick) and all was totally new to me, but this was a functionality I was really looking to install so I thought I'd try it out.

I followed the instructions, thank you to the guys who posted and shared them!

I was particularly interested because I had been trying to do some of this manually in the URL filter of my RT-N66, but noticed a really slow responsiveness in the browser (i.e. it'd just hang waiting for the ads or whatever I was trying to filter out, and just drag down the page load, the opposite effect of what I was looking for). I mentioned that over in this other thread.

Anyway, is there a way to check and see in my logs what this has actually blocked and know if it's working? I took a look at the list that it uses and just picked an IP off it (95.101.248.241) and just tried going to that URL and it basically just waited for it to load for 20-30+ sec and eventually gave up. Which is pretty much like the Asus URL filter acts. And I was reading on the webpage and the author seemed to think it was designed to give a quick "not found" response (are we not using the IPtables implementation of it?).

I dunno, I wish (maybe there is?) a way I could still add a bunch of URLs to this myself.

Thanks in advance for your help, and like I said, go easy on me! ;)

This is very basic ad blocking.
I'm a bit new to this firmware as I only had the router for a month now.
I used to have an Cisco E3000 with TomatoUSB on there which has sort of the same functionality.

This doesn't use iptables to block the ad but just redirects it to 127.0.0.1 which causes a time out.This doesn't log anything on blocking it just redirects.

If you pick an IP of the list it will just route through.
You need to use the dns name.
If you run a ping from one of the clients in your network to for instance : ping 101order.com it will reply on 127.0.0.1

In Internet explorer this doesn't show much delay in loading pages but maybe in other browsers it does.
Which browser are you using?

Also a good test is Youtube.
Youtube shouldn't give you ad video's anymore :D

I'm looking into making it more advanced like running pixelserv.
That will just load a blank image instead of redirect it to 127.0.0.1
Someone already made something like that in the forum from the last time I checked but I couldn't get it working properly yet.
 
Last edited:
I tried vi and nano but HTML tags are present.. Really ;)

The only thing I can imagine is that you are missing the quotes from the wget command. Like these "

Before you run the wget command again remove the "/tmp/dnsmasq.adblock.conf" or rebooting the router will clear that too.
 
The only thing I can imagine is that you are missing the quotes from the wget command. Like these "

Before you run the wget command again remove the "/tmp/dnsmasq.adblock.conf" or rebooting the router will clear that too.

Yes, now wget works :)
 
Last edited:
If you have enabled JFFS and installed entware you can install nano.

opkg install nano

/jffs/scripts/services-start (this already exists when entware is installed)

nano /jffs/scripts/services-start

copy and paste at the bottom

wget "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mime type=plaintext" -O "/tmp/dnsmasq.adblock.conf"
echo "conf-file=/tmp/dnsmasq.adblock.conf" >> /etc/dnsmasq.conf
killall dnsmasq
sleep 3
dnsmasq -c 1500 --log-async -n
(crontab -l ; echo "0 6 * * * """/jffs/scripts/updateadblock.sh"") |crontab -
killall crond
crond

Press control+O and enter
Press control+X to quit nano

nano /jffs/scripts/updateadblock.sh

copy and paste

wget "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mime type=plaintext" -O /tmp/dnsmasq.adblock.conf
killall dnsmasq
sleep 3
dnsmasq -c 1500 --log-async -n

Press control+O and enter
Press control+X to quit nano

Then follow the rest of the commands.

wget "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mime type=plaintext" -O "/tmp/dnsmasq.adblock.conf"

remove the space?

wget "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext" -O "/tmp/dnsmasq.adblock.conf"
 
Last edited:
Between mine and type you have a space there which is wrong. I'm testing a much easier solution now which only involves changing the dns server for your wan which makes this completely absolute. If you want to try it. Use these two dns servers. 87.118.111.215 and 80.79.54.55. Some explanation on its site http://www.fooldns.com/fooldns-community/english-version/

Sent from my GT-I9505 using Tapatalk 4
 
also after last the last step reboot your router, you should also reboot your pc or restart network interface of pc.

ps, I don't have a space, you have ;)

hmm odd, can't simple edit the post to remove the space, the space between mime and type causes the file to have html entries. Need to be without the space. But the forum somehow automatically adds a space.
 
Last edited:
I updated the first post to use the code marking after a couple of posts it seems somthing goes wrong when you post without that marking. You can restart the pc but you can also run ipconfig /flushdns to clear the dns cache.

Sent from my GT-I9505 using Tapatalk 4
 
Last edited:

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Staff online

Top