You are not logged in.

#1 2016-07-24 14:37:55

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,076
Website

Adblocking using /etc/hosts

/etc/hosts can be used to block unwanted sites system-wide, see https://en.wikipedia.org/wiki/Hosts_(file)

Configuration of this file can be tedious and time-consuming:
http://www.makeuseof.com/tag/modify-man … ile-linux/

Fortunately, there is a quick and dirty more efficient method available.
smile

Try this:

git clone http://git.r-36.net/hosts-gen && cd hosts-gen
sudo make install
sudo cp examples/gethostszero /bin
sudo chmod 775 /bin/gethostszero
sudo /bin/gethostszero
sudo hosts-gen

This will populate /etc/hosts with a list of the most egregious web abusing sites and will block them automatically.

To update the list, use:

sudo gethostszero
sudo hosts-gen

With thanks to Christopher Lohmann for this solution.

To update the file automatically, a systemd timer could be used.
https://wiki.archlinux.org/index.php/Systemd/Timers

Create two files:

/etc/systemd/system/hostszero.timer

[Unit]
Description=Update /etc/hosts daily.

[Timer]
OnCalendar=daily
AccuracySec=1h
Persistent=true

[Install]
WantedBy=timers.target

/etc/systemd/system/hostszero.service

[Unit]
Description=Update /etc/hosts

[Service]
Type=oneshot
ExecStart=/bin/gethostszero
ExecStart=/bin/hosts-gen

Then enable this with:

sudo systemctl enable hostszero.timer

Disable it with:

sudo systemctl disable hostszero.timer

Check the status with:

systemctl status hostszero.timer

Which should look something like this:

empty@TheLab:~$ systemctl status hostszero.timer
● hostszero.timer - Update /etc/hosts daily.
   Loaded: loaded (/etc/systemd/system/hostszero.timer; enabled)
   Active: active (waiting) since Sun 2016-07-24 18:00:27 BST; 2min 42s ago
empty@TheLab:~$

The original /etc/hosts file is available here:
http://someonewhocares.org/hosts/zero/hosts

Offline

#2 2016-07-24 19:52:47

redcollective
Member
From: The Wilds
Registered: 2015-09-29
Posts: 111

Re: Adblocking using /etc/hosts

I've been using someonewhocares manually for several months now, and the highest praise I can give it is I don't even notice it's working. smile

Between it and my browser extension uBlock Origin (which, by the way can utilise the same ruleset AND keep it up to date) I rarely see an advertisement for anything.

Thankyou HOAS, this looks useful.

Red


Knowledge Ferret

Offline

#3 2016-07-25 07:49:15

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 1,271
Website

Re: Adblocking using /etc/hosts

I use exclusively /etc/hosts for my browser.

This github is really good source precisely for blocking malicious via hosts.
Usually i update whenever there are new.

Of course not perform strongly like uBlock, Nevertheless prevents unnecessary dirt links.
Thanks HoaS for opening this thread.


Tumbleweed (Server) | KDE Plasma (Wayland)

Offline

#4 2016-08-04 00:22:20

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Adblocking using /etc/hosts

on archlinux, this one has been gaining popularity & credibility over the past couple of years or so, as long as i've been using it without problems.

Offline

#5 2016-08-08 00:18:08

JinxedDream
Member
Registered: 2016-08-02
Posts: 7

Re: Adblocking using /etc/hosts

Would this work on a Jessie/Bunsen setup as well? I'm struggling a bit, I just did the following today #! Waldorf -> Wheezy -> Jessie with Bunsen on the source list.

Offline

#6 2016-08-08 00:33:39

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: Adblocking using /etc/hosts

JinxedDream wrote:

Would this work on a Jessie/Bunsen setup as well? I'm struggling a bit, I just did the following today #! Waldorf -> Wheezy -> Jessie with Bunsen on the source list.

Good luck with that - I hope you did everything needed to stop breakage due to the Crunchbang packages.


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#7 2016-08-08 06:34:39

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Adblocking using /etc/hosts

JinxedDream wrote:

Would this work on a Jessie/Bunsen setup as well?

referring to my previously mentioned hostsblock? yes, definitely.

I'm struggling a bit, I just did the following today #! Waldorf -> Wheezy -> Jessie with Bunsen on the source list.

i think damo commented on this bit.
if it worked, lucky you!

Offline

#8 2016-08-08 07:44:42

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,076
Website

Re: Adblocking using /etc/hosts

JinxedDream wrote:

Would this work on a Jessie/Bunsen setup as well?

The method should be universal and only requires that systemd is run as PID1 (init).

Offline

#9 2016-08-27 18:44:27

matmutant
Member
Registered: 2016-07-19
Posts: 39
Website

Re: Adblocking using /etc/hosts

Thank you,
Works perfectly here, though I had this whenever I sudo:

sudo: unable to resolve host Bunsenlabs-mutant

Needed to add the following line to /etc/hosts:

127.0.1.1	Bunsenlabs-mutant

I suppose this will be overwritten on the next hosts update though...

Last edited by matmutant (2016-08-27 18:45:06)

Offline

#10 2016-08-27 20:57:34

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Adblocking using /etc/hosts

matmutant wrote:

I suppose this will be overwritten on the next hosts update though...

this is taken care of with the hostsblock script that i previously mentioned!

Offline

#11 2016-08-27 21:21:35

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,076
Website

Re: Adblocking using /etc/hosts

matmutant wrote:

I suppose this will be overwritten on the next hosts update though...

No, this method uses /etc/hosts.d/ to ensure that any changes to /etc/hosts are maintained, AFAIUI.

Offline

#12 2016-08-28 06:35:57

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Adblocking using /etc/hosts

Nili wrote:

Of course not perform strongly like uBlock, Nevertheless prevents unnecessary dirt links.

i think all 3 methods in this thread work the same:
combining hosts blocklist files floating on the web, into one that resides on your system as /etc/hosts, providing application-independent (!) host blocking.

in my experience this method blocks ads 100% as efficiently as a browser addon like ublock origin or adblock+ - the only difference is that these browser addons are better at collapsing empty elements.

in all cases - hosts or browser addon - it comes down to a good blocklist.

Last edited by ohnonot (2016-08-28 06:38:03)

Offline

#13 2016-08-29 16:07:38

matmutant
Member
Registered: 2016-07-19
Posts: 39
Website

Re: Adblocking using /etc/hosts

ohnonot wrote:
matmutant wrote:

I suppose this will be overwritten on the next hosts update though...

this is taken care of with the hostsblock script that i previously mentioned!

Ok, thank you, I didn't read the script well enough to see this  O:)
That is perfect then!

Offline

Board footer

Powered by FluxBB