0

Has anyone used this method: http://www.putorius.net/2012/01/block-unwanted-advertisements-on.html

I tried per instructions. Maybe I'm too new to Linux, it's not working for me.

While looking for etc/hosts I came across hosts.allow and hosts.deny. Do I simply add doamains to the hosts.deny list ?

user308751
  • 11
  • 7
  • Which browser are you using? There are much simpler ways to block ads. – Wilf Jul 24 '14 at 17:40
  • Firefox. Adblock extensions slow the browser down too much, esp with no preloader for linux. – user308751 Jul 24 '14 at 17:59
  • Noscript is a pretty lightweight way to block ads - see [here](http://askubuntu.com/q/502201/178596) – Wilf Jul 24 '14 at 19:36
  • I've used noscript it helped me with a rendering issue I was having in windows that I'm not encountering in linux. It's a bit time consuming I find because of each site needing to be tuned. – user308751 Jul 24 '14 at 19:55
  • `hosts.allow` and `hosts.deny` are not `hosts`. – psusi Jul 25 '14 at 03:21
  • ok this is a bit confusing. Taken at face value I thought I could block domains by adding them to hosts.deny ? – user308751 Jul 25 '14 at 10:00
  • `hosts.allow` and `hosts.deny` is used for granting access to your computer. See `man hosts.deny`. – saiarcot895 Jul 25 '14 at 12:35

1 Answers1

4

The main problem there is that it assumes the user is root. I modified the script to add in sudo, so that any user allowed to use sudo can use the script.

#!/bin/bash
cp /etc/hosts ~/.etchosts
cd /tmp
wget http://winhelp2002.mvps.org/hosts.txt
sudo rm /etc/hosts
sudo mv hosts.txt /etc/hosts
cat ~/.etchosts | sudo tee -a /etc/hosts

That being said, I recommend you use an extension in whichever browser(s) you use to block ads there instead of messing with /etc/hosts. I find the extensions do a better job of blocking ads while allowing content.

saiarcot895
  • 10,727
  • 2
  • 35
  • 39
  • Thank you. I use Firefox and find that adblock extensions slow the browser down too much, esp with no ppreloader for start up. If I run this script is a text editor supposed to open and do I modify anything there, for example like when I modified memory swap settings earlier ? This is all new to me. Thanks – user308751 Jul 24 '14 at 18:15
  • @user308751: No, nothing is supposed to open. You can either save the script to a file, mark it as executable (`chmod +x fileName`), and then run it (`./fileName`), or just copy the script line by line (starting with the second line). – saiarcot895 Jul 24 '14 at 18:18
  • ok thank you. Curious, when I try to manually modify any host file then save changes, I get the access denied message. How do I gain access ? – user308751 Jul 24 '14 at 19:12
  • If you aren't using `sudo`, and you aren't `root`, then you get the access denied message. You can use `sudo vim /etc/hosts` or `sudoedit /etc/hosts` (which uses your default editor) to edit `/etc/hosts`. – saiarcot895 Jul 24 '14 at 19:13
  • ok got it I was going straight at it, just came over from windows thank you – user308751 Jul 24 '14 at 19:25
  • thank you for script modification I will try this process when I have time. I still don't understand the "fill the file with the following" part ...... If I'm not in a text editor and not creating or modifying a file then ....... I'm sorry I just don't understand, fresh noob coming over from windows ;-( – user308751 Jul 25 '14 at 12:31
  • @user308751: Where do you see that? You only have to run the commands above, and the `/etc/hosts` file will contain the list of domains to block. – saiarcot895 Jul 25 '14 at 12:37
  • So I pasted the script and now the file hosts is deleted and not in the trash either, not good? good? I dunno anymore. – Eric Huelin Jul 19 '17 at 09:56
  • you must be kidding.... browser extensions are barely blocking any advertisement and/or intermediate tracking sites. For me this is the only and best method I've seen delivering descent results so far. I even run it on all my android devices using DNS66, an application (for obvious reasons) not in the play-store, but works very well using VPN profiles to trash crap traffic to 0.0.0.0. – Boeboe Feb 28 '18 at 14:36