You are not logged in.

#1 2010-10-10 11:36:31

graysky
Member
From: The worse toilet in Scotland
Registered: 2008-12-01
Posts: 8,648
Website

appending a blocklist to /etc/hosts

Is it possible to append a blocklist (er... redirectlist) to /etc/hosts somehow?

For example, mvps has been supplying a very nice list of known parasite websites for years.  Basically, it just uses 127.0.0.1 to redirect known bad websites so they don't load. It's a nice system-wide method to block them.  I have been pasting their list into my /etc/hosts but am wondering if I can someone call it as I do in bash scripts.

For example, this doesn't work, but you get idea:

$ cat /etc/hosts
127.0.0.1               localhost.localdomain   localhost novelty

192.168.1.1     router
192.168.1.2     inky
192.168.1.3     blinky

. /etc/hostsmvps # try to load the mvps redirect list

CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2010-10-10 13:15:21

eldragon
Member
From: Buenos Aires
Registered: 2008-11-18
Posts: 1,026

Re: appending a blocklist to /etc/hosts

cat file.txt >> /etc/hosts

as root (sudo will not work)

edit: this is not the requested solution. sorry.

Last edited by eldragon (2010-10-10 13:24:01)

Offline

#3 2010-10-10 15:55:04

Wintervenom
Member
From: /home/wintervenom
Registered: 2008-08-20
Posts: 1,011
Website

Re: appending a blocklist to /etc/hosts

Copy your local machine and network hosts to "/etc/hosts.local," then:

#!/bin/dash
### MVPS Hosts Updater #########
# Version 0.3 by Scott Garrett #
# Wintervenom [(at)] gmail.com #
################################

# Download the MVPS hosts file.
wget -c -O /tmp/hosts.txt http://www.mvps.org/winhelp2002/hosts.txt

# Be paranoid and replace every IP address with 0.0.0.0.  We also get
# only want the actual blacklist, 'cause we want to prepend the user's
# own hosts.  0.0.0.0 is nicer than constantly knocking on localhosts' door.
sed -r -e 's:^([0-9]{1,3}\.){3}[0-9]{1,3}:0.0.0.0:' /tmp/hosts.txt > /tmp/hosts.new.txt
tail -n+`grep -nF 'start of lines' /tmp/hosts.new.txt | cut -d':' -f1` /tmp/hosts.new.txt > /tmp/hosts.txt

# Write this new list over the system hosts list.  MVPS' line feeds
# are \n\r; we will be getting rid of those dirty carriage returns.
# We'll first write the user's hosts head, then the black list.
cat /etc/hosts.local > /etc/hosts
cat /tmp/hosts.txt | tr -d "\r" >> /etc/hosts
rm /tmp/hosts*.txt

# This is the end!

Last edited by Wintervenom (2010-10-10 15:57:35)


My [GitHub] and my [artwork].
Data is guaranteed to stay crunchy in milk.
Keep your _✍ hand strong.

Offline

#4 2010-10-10 16:04:07

graysky
Member
From: The worse toilet in Scotland
Registered: 2008-12-01
Posts: 8,648
Website

Re: appending a blocklist to /etc/hosts

Wintervenom wrote:

Copy your local machine and network hosts to "/etc/hosts.local," then:

#!/bin/dash
### MVPS Hosts Updater #########
# Version 0.3 by Scott Garrett #
# Wintervenom [(at)] gmail.com #
################################

# Download the MVPS hosts file.
wget -c -O /tmp/hosts.txt http://www.mvps.org/winhelp2002/hosts.txt

# Be paranoid and replace every IP address with 0.0.0.0.  We also get
# only want the actual blacklist, 'cause we want to prepend the user's
# own hosts.  0.0.0.0 is nicer than constantly knocking on localhosts' door.
sed -r -e 's:^([0-9]{1,3}\.){3}[0-9]{1,3}:0.0.0.0:' /tmp/hosts.txt > /tmp/hosts.new.txt
tail -n+`grep -nF 'start of lines' /tmp/hosts.new.txt | cut -d':' -f1` /tmp/hosts.new.txt > /tmp/hosts.txt

# Write this new list over the system hosts list.  MVPS' line feeds
# are \n\r; we will be getting rid of those dirty carriage returns.
# We'll first write the user's hosts head, then the black list.
cat /etc/hosts.local > /etc/hosts
cat /tmp/hosts.txt | tr -d "\r" >> /etc/hosts
rm /tmp/hosts*.txt

# This is the end!

Thanks for the script, I actually wrote one very similar to yours but then thought I'd ask about sourcing it like a bash script does...

Last edited by graysky (2010-10-10 16:04:16)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2010-10-10 20:49:45

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: appending a blocklist to /etc/hosts

It's better to put these things into the user.action of privoxy! You can do it like this

{ +block }
LIST

Offline

#6 2010-12-30 11:36:35

graysky
Member
From: The worse toilet in Scotland
Registered: 2008-12-01
Posts: 8,648
Website

Re: appending a blocklist to /etc/hosts


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#7 2010-12-30 13:06:59

dyscoria
Member
Registered: 2008-01-10
Posts: 1,007

Re: appending a blocklist to /etc/hosts

I modified wintervenom's script to include another blocklist, and delete duplicates:

https://bbs.archlinux.org/viewtopic.php … 57#p866757


flack 2.0.6: menu-driven BASH script to easily tag FLAC files (AUR)
knock-once 1.2: BASH script to easily create/send one-time sequences for knockd (forum/AUR)

Offline

#8 2012-10-18 07:12:41

Markus00000
Member
Registered: 2011-03-27
Posts: 302

Re: appending a blocklist to /etc/hosts

Edit: Sorry, I think I shouldn't have posted this here. I already reported this post.

I get the following error messages. I guess, it started after switching to systemd:

    # hosts_update
    /usr/bin/hosts_update: line 6: /etc/rc.d/functions: No such file or directory
    /usr/bin/hosts_update: line 13: stat_busy: command not found
    /usr/bin/hosts_update: line 15: stat_done: command not found
    /usr/bin/hosts_update: line 17: stat_busy: command not found
    /usr/bin/hosts_update: line 28: stat_done: command not found

Any possibility to make this package compatible with pure systemd systems?

Last edited by Markus00000 (2012-10-18 07:25:29)

Offline

#9 2012-10-18 08:18:13

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,273

Re: appending a blocklist to /etc/hosts

Well, let's keep this one read only.
Closing.


To know or not to know ...
... the questions remain forever.

Offline

Board footer

Powered by FluxBB