OpenWrt Forum Archive

Topic: Fast/lean adblocking for OpenWrt/LEDE with web ui: simple-adblock

The content of this topic has been archived between 5 Apr 2016 and 5 Apr 2018. Unfortunately there are posts – most likely complete pages – missing.

stangri wrote:

Hey, the pixelserv ip is 198.18.0.1, the rules should be:

iptables -w -t nat -A prerouting_rule -p tcp -d 198.18.0.1 --dport 80 -j REDIRECT --to-ports 65534
iptables -w -t nat -A prerouting_rule -p tcp -d 198.18.0.1 --dport 443 -j REDIRECT --to-ports 65535
iptables -w -t nat -A prerouting_rule -p tcp -d 198.18.0.1 -j ACCEPT
iptables -w -A forwarding_rule -d 198.18.0.1 -j REJECT

Either the one-liner from github or

/etc/init.d/adblock setup

should set all these up (an overwrite any previous adblock config).

Thanks!
It works flawlessly now.
I missunderstood th script at the first place.

I get an error with these notifications wjen running setup script:

/etc/init.d/adblock script update... [OK]
sh: 0: unknown operand
Packages setup... sh: 0: unknown operand
[OK]
sh: 0: unknown operand
PixelServ setup... sh: 0: unknown operand
[OK]
sh: 0: unknown operand
Firewall setup... sh: 0: unknown operand
[OK]
sh: 0: unknown operand
AdBlock config setup... sh: 0: unknown operand
[OK]

Script is run on LEDE r2158
can you help me!

(Last edited by geminisongtu on 13 Nov 2016, 18:06)

Sorry about that. Run /etc/init.d/adblock update once more to update to the version where this is fixed.

The bug had to do with just the output, everything else should have set up just fine.

thanks for your update. But on version 4.0.0, when I run your setup script, then not thing happen.
Im on LEDE r2222, using ufetch-client and libustream-mbedtls

(Last edited by geminisongtu on 17 Nov 2016, 18:25)

Just ran it on LEDE 2212:

# /etc/init.d/adblock setup
/etc/init.d/adblock script update... [OK]
Packages setup... [OK]
AdBlock config setup... [OK]

thanks for your reply. Where can I download the old build of LEDE? I find on their website, but just see the latest build.

It should work just as well with revision 2222.

If you're struggling with the setup, maybe you should consider using the adblock and luci-app-adblock packages instead, they are way more user-friendly, easier to install and configure from Web UI.

Mine has more compact code, making it easier to tinker with/adjust to your own needs.

I just installed your script on CC and get the following error. Do you have any suggestions?

root@OpenWrt:~# /etc/init.d/adblock update
/etc/init.d/adblock script update... [OK]
root@OpenWrt:~# /etc/init.d/adblock setup
/etc/init.d/adblock script update... [OK]
Packages setup... [OK]
AdBlock config setup... [OK]
root@OpenWrt:~# /etc/init.d/adblock reload
ERROR: Failed to create AdBlock data file!

Use

/etc/init.d/adblock start

to start the service. Only use reload if you want to force-reload the hosts/whitelist files.

stangri wrote:

Use

/etc/init.d/adblock start

to start the service. Only use reload if you want to force-reload the hosts/whitelist files.

Thanks! It worked!

Can this script run with lists of Adblock Plus? example: fanboy.co.nz/index.html

No, it's domain/hosts based blocking only.

Turned it into a proper package and it's as fast and as customizable (from both CLI and Web UI) as humanly possible now. wink For details please refer to the first post.

So I'm running LEDE 17.01.0-rc2 fresh install and ran the command as specified on your README: opkg update; opkg install simple-adblock luci-app-simple-adblock coreutils-sort

Getting the following errors (had to remove links in output from post):

root@LEDE:~# opkg update; opkg install simple-adblock luci-app-simple-adblock coreutils-sort

Unknown package 'simple-adblock'.
Unknown package 'luci-app-simple-adblock'.
Installing coreutils-sort (8.23-2) to root...
Installing coreutils (8.23-2) to root...
Configuring coreutils.
Collected errors:
* opkg_install_cmd: Cannot install package simple-adblock.
* opkg_install_cmd: Cannot install package luci-app-simple-adblock.
* check_data_file_clashes: Package coreutils-sort wants to install file /usr/bin/sort
        But that file is already provided by package  * busybox
* opkg_install_cmd: Cannot install package coreutils-sort.


So it can't install coreutils-sort and can't find simple-adblock or the luci-app. How can I get coreutils-sort to work? I'm guessing removing busybox wouldn't be a good idea? I could try and install the packages manually but think something in what I'm doing is wrong? Am I missing something? I also tried this on the latest OpenWrt 15 with the same results. Many thanks!

diagonali wrote:

So it can't install coreutils-sort and can't find simple-adblock or the luci-app. How can I get coreutils-sort to work? I'm guessing removing busybox wouldn't be a good idea? I could try and install the packages manually but think something in what I'm doing is wrong? Am I missing something? I also tried this on the latest OpenWrt 15 with the same results. Many thanks!

Thank you, I've updated the README, please refer it for instructions for both OpenWrt and LEDE.

You are right -- removing busybox is not a good idea. You can skip coreutils-sort (or try 'opkg --force-overwrite install coreutils-sort'), it speeds up sorting but simple-adblock will work with the busybox sort as well. I couldn't reproduce your opkg error with the 17.01-snapshot tho -- I've just tried installing coreutils-sleep and it had no problem overwriting busybox'es sleep.

stangri wrote:
diagonali wrote:

So it can't install coreutils-sort and can't find simple-adblock or the luci-app. How can I get coreutils-sort to work? I'm guessing removing busybox wouldn't be a good idea? I could try and install the packages manually but think something in what I'm doing is wrong? Am I missing something? I also tried this on the latest OpenWrt 15 with the same results. Many thanks!

Thank you, I've updated the README, please refer it for instructions for both OpenWrt and LEDE.

You are right -- removing busybox is not a good idea. You can skip coreutils-sort (or try 'opkg --force-overwrite install coreutils-sort'), it speeds up sorting but simple-adblock will work with the busybox sort as well. I couldn't reproduce your opkg error with the 17.01-snapshot tho -- I've just tried installing coreutils-sleep and it had no problem overwriting busybox'es sleep.

Thanks for the update - followed the new instructions and they worked great! Weird that my coreutils-sort gave the error as I'd clean flashed LEDE but I used your force-overwrite command and it seemed to install fine. The finicky part of me wants to know why there was an error with mine but yours had no errors but it all seems to be working well so I'll leave it at that. Many thanks for all the work you put into this. This seemed just the ticket when I realised I could run an adblocker on my router instead of having a Pihole on the network. I actually use their hosts file with this.

I'm glad it's working great. Maybe there's a difference in how opkg handles conflicts between RC and SNAPSHOT builds.

I've added the following two lists to the default config:

https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt
https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt

The software ist correct installed, loads all the blocked sites...every script is running [OK]

But...

....in practise its blocked absolutely nothing.

How did you test it? Have you tried something like

nslookup zzz.clickbank.net

on the router?

It's likely that the device you tested it on cached some DNS responses from the ads your browser displayed prior to installation of simple-adblock. Usually restarting your device (the one you're still seeing the ads on) helps.

(Last edited by stangri on 16 Feb 2017, 02:34)

There is no caching.
It dosent work with multiwan and vpn clients.

It works very well with vpn client on my router.

In 1.5.5 I've added an option to assign one of the router LEDs to indicate adblocking status (on/off).

Hello Strangri
I've installed adblock on archer c7 with ROOTer firmware based on LEDE r3069-0e22d63
I use 4g modem for internet connection.
First time adblock start early than modem connect to internet and I see:

Wed Mar  1 13:57:08 2017 user.notice simple-adblock [1231]: Forcing local DNS server: 192.168.1.1.
Wed Mar  1 13:57:08 2017 kern.info kernel: [   36.028160] br-lan: port 2(wlan0) entered forwarding state
Wed Mar  1 13:57:15 2017 user.notice simple-adblock [1231]: [DL] Blocked Hosts:  mvps. [0;31m[✗][0m
Wed Mar  1 13:57:20 2017 user.notice simple-adblock [1231]: [DL] Blocked Hosts: yoyo [0;31m[✗][0m
Wed Mar  1 13:57:20 2017 user.notice : tr: short write
Wed Mar  1 13:57:20 2017 user.notice : head: standard output: I/O error
Wed Mar  1 13:57:25 2017 user.notice simple-adblock [1231]: [DL] Blocked Hosts: malwaredomainlist [0;31m[✗][0m
Wed Mar  1 13:57:25 2017 user.notice : tr: short write
Wed Mar  1 13:57:25 2017 user.notice : head: standard output: Broken pipe
Wed Mar  1 13:57:28 2017 kern.notice kernel: [   55.988127] random: nonblocking pool is initialized
Wed Mar  1 13:57:31 2017 user.notice simple-adblock [1231]: [DL] Blocked Hosts: adaway [0;31m[✗][0m
Wed Mar  1 13:57:36 2017 user.notice simple-adblock [1231]: [DL] Blocked Hosts: someonewhocares [0;31m[✗][0m
Wed Mar  1 13:57:36 2017 user.notice : tr: short write
Wed Mar  1 13:57:36 2017 user.notice : head: standard output: Broken pipe
Wed Mar  1 13:57:41 2017 user.notice simple-adblock [1231]: [DL] Blocked Hosts: zeustracker. [0;31m[✗][0m
Wed Mar  1 13:57:46 2017 user.notice simple-adblock [1231]: [DL] Blocked Domains:malwaredomains[0;31m[✗][0m
Wed Mar  1 13:57:46 2017 user.notice : tr: short write
Wed Mar  1 13:57:46 2017 user.notice : head: standard output: I/O error
Wed Mar  1 13:57:52 2017 user.notice simple-adblock [1231]: [DL] Blocked Domains: s3 [0;31m[✗][0m
Wed Mar  1 13:57:57 2017 user.notice simple-adblock [1231]: [DL] Blocked Domains: s3[0;31m[✗][0m
Wed Mar  1 13:58:02 2017 user.notice simple-adblock [1231]: [DL] Blocked Domains: s3[0;31m[✗][0m
Wed Mar  1 13:58:02 2017 user.notice : tr: short write
Wed Mar  1 13:58:02 2017 user.notice : head: standard output: I/O error
Wed Mar  1 13:58:07 2017 user.notice simple-adblock [1231]: [DL] Blocked Domains: ransomwaretracke [0;31m[✗][0m
Wed Mar  1 13:58:07 2017 user.notice : tr: short write
Wed Mar  1 13:58:12 2017 user.notice simple-adblock [1231]: [DL] Blocked Domains: gitlab [0;31m[✗][0m
Wed Mar  1 13:58:17 2017 user.notice simple-adblock [1231]: [DL] Blocked Domains: dshield [0;31m[✗][0m
Wed Mar  1 13:58:17 2017 user.notice simple-adblock [1231]: Waiting for background processes [0;32m[✓][0m
Wed Mar  1 13:58:17 2017 user.notice simple-adblock [1231]: [0;31mERROR[0m: service failed to create its data file!

When connect are established I restart adblock and see the following:

Wed Mar  1 22:17:40 2017 user.notice simple-adblock [28000]: No longer forcing local DNS server.
Wed Mar  1 22:17:41 2017 user.notice simple-adblock [28000]: Reloading dnsmasq [0;31m[✗][0m
Wed Mar  1 22:17:41 2017 user.notice simple-adblock [28000]: [0;31mERROR[0m: service failed to reload dnsmasq!
Wed Mar  1 22:17:41 2017 daemon.err ux t tpd[1148]: Command failed: Not found
Wed Mar  1 22:17:42 2017 user.notice simple-adblock [28081]: No longer forcing local DNS server.
Wed Mar  1 22:17:43 2017 user.notice simple-adblock [28081]: Reloading dnsmasq [0;31m[✗][0m
Wed Mar  1 22:17:43 2017 user.notice simple-adblock [28081]: [0;31mERROR[0m: service failed to reload dnsmasq!
Wed Mar  1 22:17:43 2017 daemon.err ux t tpd[1148]: Command failed: Not found
Wed Mar  1 22:18:25 2017 user.notice simple-adblock [28753]: Forcing local DNS server: 192.168.1.1.
Wed Mar  1 22:18:26 2017 daemon.err ux t tpd[1148]: tr: short write
Wed Mar  1 22:18:26 2017 daemon.err ux t tpd[1148]: head: standard output: I/O error
Wed Mar  1 22:18:30 2017 user.notice simple-adblock [28753]: [DL] Blocked Hosts: mvps [0;32m[✓][0m
Wed Mar  1 22:18:30 2017 daemon.err ux t tpd[1148]: tr: short write
Wed Mar  1 22:18:30 2017 daemon.err ux t tpd[1148]: head: standard output: Broken pipe
Wed Mar  1 22:18:31 2017 user.notice simple-adblock [28753]: [DL] Blocked Hosts: yoyo[0;32m[✓][0m
Wed Mar  1 22:18:31 2017 daemon.err ux t tpd[1148]: tr: short write
Wed Mar  1 22:18:31 2017 daemon.err ux t tpd[1148]: head: standard output: Broken pipe
Wed Mar  1 22:18:33 2017 user.notice simple-adblock [28753]: [DL] Blocked Hosts: malwaredomainlist [0;32m[✓][0m
Wed Mar  1 22:18:34 2017 user.notice simple-adblock [28753]: [DL] Blocked Hosts: adaway[0;32m[✓][0m
Wed Mar  1 22:18:38 2017 user.notice simple-adblock [28753]: [DL] Blocked Hosts: someonewhocares[0;32m[✓][0m
Wed Mar  1 22:18:38 2017 daemon.err ux t tpd[1148]: tr: short write
Wed Mar  1 22:18:38 2017 daemon.err ux t tpd[1148]: head: standard output: I/O error
Wed Mar  1 22:18:40 2017 user.notice simple-adblock [28753]: [DL] Blocked Hosts: zeustracker [0;32m[✓][0m
Wed Mar  1 22:18:43 2017 user.notice simple-adblock [28753]: [DL] Blocked Domains: mirror1  [0;32m[✓][0m
Wed Mar  1 22:18:45 2017 user.notice simple-adblock [28753]: [DL] Blocked Domains: s3 [0;32m[✓][0m
Wed Mar  1 22:18:47 2017 user.notice simple-adblock [28753]: [DL] Blocked Domains: s3 [0;32m[✓][0m
Wed Mar  1 22:18:49 2017 user.notice simple-adblock [28753]: [DL] Blocked Domains: s3 [0;32m[✓][0m
Wed Mar  1 22:18:49 2017 daemon.err ux t tpd[1148]: tr: short write
Wed Mar  1 22:18:49 2017 daemon.err ux t tpd[1148]: head: standard output: I/O error
Wed Mar  1 22:18:52 2017 user.notice simple-adblock [28753]: [DL] Blocked Domains: ransomwaretracker[0;32m[✓][0m
Wed Mar  1 22:18:54 2017 user.notice simple-adblock [28753]: [DL] Blocked Domains: gitlab[0;32m[✓][0m
Wed Mar  1 22:18:56 2017 user.notice simple-adblock [28753]: [DL] Blocked Domains: dshield [0;32m[✓][0m
Wed Mar  1 22:18:56 2017 user.notice simple-adblock [28753]: Waiting for background processes [0;32m[✓][0m
Wed Mar  1 22:18:59 2017 user.notice simple-adblock [28753]: Sorting merged file [0;32m[✓][0m
Wed Mar  1 22:19:04 2017 user.notice simple-adblock [28753]: Whitelisting domains [0;32m[✓][0m
Wed Mar  1 22:19:09 2017 user.notice simple-adblock [28753]: Formatting merged file [0;32m[✓][0m
Wed Mar  1 22:19:09 2017 user.notice simple-adblock [28753]: Removing temporary files [0;32m[✓][0m
Wed Mar  1 22:19:10 2017 user.notice simple-adblock [28753]: Reloading dnsmasq [0;32m[✓][0m
Wed Mar  1 22:19:11 2017 user.notice simple-adblock [28753]: service enabled: blocking 53640 domains.

Could You help me to know causes of errors?
thanks

I deleted parts of domain names from logs because I can't save post.

Hey man, thanks for reporting this!

The errors seem to come from this piece of code:

R_TMP="/var/$(head /dev/urandom | tr -dc 'A-Za-z0-9' | head -c10)"

It's ran once per each URL to generate a random filename.

I'm very surprised it didn't work on your system, what happens if you just do:

head /dev/urandom

from the console?

I see very strange sign in PUTTY

Ի#i▒▒▒؏}▒&t6▒▒K:▒▒▒Q▒▒▒▒!▒▒N▒r5\▒)▒>#▒B▒▒s▒Y0▒R▒q
                                                 ▒▒▒▒▒n▒M▒▒▒▒▒▒W*▒9▒kt▒ԿWقb"▒^▒▒~wk▒▒▒▒\sس▒

maybe did I make something wrong?

No, that's right, it should be giving out a sequence of random stuff.

Are you sure that the errors are simple-adblock related? I understand you've had to mask some stuff so you could post it, were all errors with:

daemon.err uhttpd[1148]

?

The discussion might have continued from here.