On 16/09/13 15:36, mick wrote:
On Mon, 16 Sep 2013 11:03:32 +0100 Chris Green cl@isbd.net allegedly wrote:
Is it possible to provide a 'do nothing' web page so that one can set references to google.analytics.com for example to go to a page on localhost that does nothing?
[]
127.0.0.1 google.analytics.com
In my /etc/hosts file it will presumably get lots of 'page not found' errors, probably OK but I was wondering if there was a neater way.
I do exactly that. The hosts file on my local DNS server (running DNSMasq) is derived from Dan Pollock's file at http://someonewhocares.org/hosts/ Dan includes lots of google servers in his file.
Yes it's possible.
Some cryptic notes I have refer to this page as inspiration http://dcssrv1.oit.uci.edu/indiv/ehood/gems/ad-blocking.html
I have entries in my dnsmasq file like address=/DOMAIN_TO_BE_BLOCKED.com/127.0.0.1
I have Apache installed. Other lightweight webservers might be quicker/easier (lighttpd, nginx?) , but I had it installed anyway so I used it.
ports.conf has this added
NameVirtualHost 127.0.0.1:80 Listen 127.0.0.1:80
So dnsmasq redirects things to this virtualhost.
/etc/apache2/sites-available/default has this added: #From http://dcssrv1.oit.uci.edu/indiv/ehood/gems/ad-blocking.html <VirtualHost 127.0.0.1:80> DocumentRoot "/var/www/adblock" #ErrorLog logs/error-block.log ErrorLog /var/log/apache2/error.log SetEnvIf Request_URI .* no-access-log #CustomLog logs/access-block.log common env=!no-access-log CustomLog /var/log/apache2/access.log common env=!no-access-log Options FollowSymLinks RewriteEngine on RewriteRule ^(.*) /var/www/adblock/index.htm #http://www.lavluda.com/2007/07/15/how-to-enable-mod_rewrite-in-apache22-debi... </VirtualHost>
If I remember correctly, Rewite Rule changes anything and everything on 127.0.0.1 to point to /var/www/adblock/index.htm
I then have a file at /var/www/adblock/index.htm with this in it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en-GB">
<head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Language" content="en-GB"> <meta name="GENERATOR" content="Text Editor"> <meta name="ProgId" content="Text Editor"> <meta name="AUTHOR" content="YOUR_NAME"> <meta name="rating" content="general"> <title>AdBlock</title> </head> <body> <p>AdBlock</p> </body> </html>
The above is a valid minimalist webpage with a title Adblock, displaying only the text Adblock. You can change this if you want to.
If you set this up and restart Apache, then anything that dnsmasq redirects to 127.0.0.1 will instead show "AdBlock"
NB, this will point any web access to 127.0.0.1 to this adblock page. This may break some things if you have web servers running on this page. If that causes a problem, you could instead use 127.0.0.2 (or other numbers, .3, .4, .5 etc). I'm not sure exactly where it ends, but the first few addresses in that range are private loopback addresses, not just 127.0.0.1.
I use files from http://pgl.yoyo.org/adservers for ad servers and http://www.malwaredomains.com/ for "bad" domains
I use a script to wangle these into the correct format for dnsmasq and I find it works quite well.
HTH Steve
NB this will point 127.0.0.1 to an adblock file.