Blocking with hosts file (summary)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



{snip a bunch!}

Summary version!  We keep saying the same thing and re-asking the same 
questions.  Boiling everyone’s [correct AFAIK] statements into a whole.  
{Hopefully I didn’t miss anything!}

> 0.0.0.0 vs. 127.0.0.1

It doesn’t matter, both get served locally.  [Paste both into a web 
browser :) ]

AFAICT this is the convention now:

- Use 0.0.0.0 to block.
- Use 127.0.0.1 to connect to your local web server, proxy, or other local 
port.

Why the historic use of 127.0.0.1 to block?

I don’t know, and do not take this as truth…  It’s possible 0. didn’t exist 
original and was added after 20??.  Based on memory 127. was the only number 
I ever saw in hosts files pre 2000-2005?  (I ran the Linux Router Project 
(LRP, the precursor to LEAF) through most of the 90s and early 00s.)

> the two variants used in tandem -- for example, you
> mentioned "if you have a web server"? Maybe, then, it would be useful to
> create a home version and a web server version.

No.

Pretty much both sets of entries would be needed at the same time.  They 
aren’t going to overlap.

Errata:  Okay, in some bizarre circumstance where you want (hard to figure out 
a need) the same exact address to be blocked in one instance and served 
locally in another, then yeah, you’d need to list ‘swap.’

> I believe Michael mentioned some kind of script?

> this is the sniplet from rc.local:
>
> 	# HOSTS-Datei mit Adblocker :-)
> 	(
> 	sleep 5m
> 	cat > /etc/hosts << XXX
> 	# insert your hostname here
> 	127.0.0.1   localhost t61
>
> 	# The following lines are desirable for IPv6 capable hosts
>
> 	::1    localhost ip6-localhost ip6-loopback
>
> 	ff02::1 ip6-allnodes
> 	ff02::2 ip6-allrouters
> 	XXX
>
> 	wget http://winhelp2002.mvps.org/hosts.txt -O - 2>/dev/null | grep
> ^0.0.0.0 >> /etc/hosts ) &

This is essentially what the script I wrote does.  It separates the logic from 
the hosts entries so you can manage ‘# insert your hostname here’ easier, add 
custom blocks easier, and is a bit safer, but it’s the same.  I’ve attached 
it again.

PS:  The block list I used (StevenBlack's) combines winhelp2002’s, Peter 
Lowe's, and many other block lists into one, so scan it to see if it’s 
already got any you want to add to the wget pulls.

> Could/should I run both a hosts block list and Ad Blocker?

Yes.  They will both catch ‘nasty’ things the other won’t.  Most noticeable 
will be an Ad Blocker will catch self served ads on sites you want to visit.  
And AFAIK most Ad Blocker lists (get paid to) whitelist Google ads, which the 
hosts block list will catch.

Best All,
Michael

PS:  If anyone does find another block list to add, send me the wget pull link 
and I’ll finish the script to handle multiple combines.

#!/bin/bash
# # # Description
# Grap Blocklists for use with /etc/hosts
#
# Script=get-hosts-block.sh
# Author=Michael
# Email=use website contact
# Website=http://www.inet-design.com/
# License=GPL
# Script repository=none
# Last Edit Date=Sun 30 Aug 2020
#
# Instructions:
# As root,
# - cp /etc/hosts /{$WorkingDir}/hosts.orig
#
# - Copy computer name line from /etc/hosts
#   and any other addtions to /{$WorkingDir}/hosts.mine.unique
# e.g.
#   127.0.0.1       {computer-name}
#   0.0.0.0         fonts.googleapis.com
#   0.0.0.0         fonts.googleapis.com:443
#   0.0.0.0         tracking.klickthru.com
#   ...
#
# - Fix all pathing/naming...
#
# - Add to root crontab
#
# Notes:
# I started building this for multipe lists, but found
# StevenBlack's already includes Peter Lowe's (yoyo.org).
#
# If more than one list gets used, need to clean/combine them
# and will need to re-work 'hosts' building at end.
#
# Root crontab
# 45 6 * * 1 /home/michael/common/bin/get-hosts-block.sh >>/home/michael/common/bin/log/get-hosts-block.sh.log 2>&1
# 06:45 on Monday, that way if it breaks, it won't have broken much and can be fixed at start of day.
#
# # # # #

# Include Standard Paths & Functions
# IncFile="$(dirname "${BASH_SOURCE[0]}")/includes/stdpaths.sh"
# if [ -f "$IncFile" ] ; then
#   . "$IncFile"
# else
#   echo 'No Standard Paths!  Exiting'
#   exit 1
# fi
# IncFile="$(dirname "${BASH_SOURCE[0]}")/includes/stdfunctions.sh"
# if [ -f "$IncFile" ] ; then
#   . "$IncFile"
# fi
function randomUserAgent {
  RndNum=`echo $((1 + RANDOM % 11))`
  UserAgent[0]='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
  UserAgent[1]='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
  UserAgent[2]='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)'
  UserAgent[3]='Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'
  UserAgent[4]='Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; MDDCJS)'
  UserAgent[5]='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0;  Trident/5.0)'
  UserAgent[6]='Mozilla/5.0 (iPad; CPU OS 8_4_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H321 Safari/600.1.4'
  UserAgent[7]='Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'
  UserAgent[8]='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0'
  UserAgent[9]='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393'
  UserAgent[10]='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
  UserAgent[11]='Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)'

  echo ${UserAgent[$RndNum]}
}

renice -n 15 -p $$ >/dev/null 2>/dev/null
# # # #
# Static Setups
# Random user aget
UserAgent=`randomUserAgent`
# # # #

# change to {$WorkingDir}
# WorkingDir="/home/michael/data/trash/hoststest"
WorkingDir="/root/hosts"
if [ ! -d "$WorkingDir" ] ; then
  echo 'Hey, you goofed...'
  echo "md $WorkingDir"
  echo '-and-'
  echo 'place hosts.orig and hosts.mine.unique in it...'
  exit
fi
cd "$WorkingDir"

# backup existing hosts
CurrDateTime=$(date +"%Y%m%d-%H%M%S")
cp --preserve=all "/etc/hosts" "$WorkingDir/hosts.$CurrDateTime"

# # # [AAA-START]
# # Notes
#
# Add as many block lists as desired, one per line.
#
# escape ('\') items that bork bash, eg..
# https://pgl.yoyo.org/adservers/serverlist.php?showintro=0;hostformat=hosts
# https://pgl.yoyo.org/adservers/serverlist.php?showintro=0\;hostformat=hosts
# PS: Don't use above as it's HTML, not sure where 'raw' is...
#
HostLists=(
https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
)
# # # [AAA-END]

DateTime=`date +"%Y%m%d%H%M"`
# echo -n "$DateTime" >> attictemps.csv

i=0
for HostList in "${HostLists[@]}"; do 
  let "i=i+1"
#   echo "hostlist.$i"
#   echo "$HostList"

wget \
--user-agent="$UserAgent" \
--passive-ftp \
--execute robots=off \
--output-document="hostlist.$i" \
--append-output hostlist.log \
"$HostList"

done

cp --preserve=all 'hosts.mine.unique' 'hosts'
cat "hostlist.$i" >> 'hosts'
cp --preserve=all 'hosts' '/etc/hosts'


---------------------------------------------------------------------
To unsubscribe, e-mail: trinity-users-unsubscribe@xxxxxxxxxxxxxxxxxxxxxxxxxx
For additional commands, e-mail: trinity-users-help@xxxxxxxxxxxxxxxxxxxxxxxxxx
Read list messages on the web archive: http://trinity-users.pearsoncomputing.net/
Please remember not to top-post: http://trinity.pearsoncomputing.net/mailing_lists/#top-posting

[Index of Archives]     [Trinity Devel]     [KDE]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]     [Trinity Desktop Environment]

  Powered by Linux