Ad-blocking

From Amahi Wiki
Jump to: navigation, search


Msgbox-WOPr.png Work In Progress
This article is currently undergoing major expansion or restructuring. You are welcome to assist by editing it as well. If this article has not been edited in several days, please remove this template.


This section will document how to run your HDA as a network wide ad-blocking tool, utilising DNS redirects and a small pixel server.

The work here was based on: https://sfxpt.wordpress.com/2011/02/21/the-best-ad-blocking-method/.

Pixelserv is a webserver which simply serves 1x1 blank pixels. By redirecting web requests for adverts to our pixelserver, ads are replaced by this 1x1 pixel leaving the target webpage intact. This will work on all devices across your network, removing the need for software-based solutions on each device.

A shell script get-adlist.sh will update the list of blocked domains (stored as /etc/dnsmasq.adblock.conf) whever you run it. You can also manually edit the list and remove domains that you wish to see (in the case of wrongly blocked domains).


Fedora 19

Precusors -

  • You'll need net-tools installed to use ifconfig
yum install net-tools
  • This guide assumes your network interface is named p2p1 and your HDA IP address is 192.168.1.2. Check with ifconfig, and change this guide where neccessary.


Get Ad List

nano /usr/local/bin/get-adlist.sh
#!/bin/sh
# Download the DNSmasq formatted ad block list
curl "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext" | sed "s/127\.0\.0\.1/192.168.1.99/" > /etc/dnsmasq.adblock.conf
# Restart DNSmasq
service dnsmasq restart
chmod -v 755 /usr/local/bin/get-adlist.sh
/usr/local/bin/get-adlist.sh

Change DNSMasq config

echo "conf-file=/etc/dnsmasq.adblock.conf" >> /etc/dnsmasq.conf
service dnsmasq restart

Bind Apache to main IP address

  • Edit the Apache config file using a file editor:
nano /etc/httpd/conf/httpd.conf
  • Add your HDAs IP address to this section in the conf file:
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 192.168.1.2:80
  • Restart Apache
service httpd restart


Pixel Server

  • You need to download Pixelserv to the HDA:
wget http://proxytunnel.sourceforge.net/files/pixelserv.pl.txt 
  • Move and rename the Pixelserv binary:
mv pixelserv.pl.txt /usr/local/bin/pixelserv
  • Edit pixelserv using a file editing program of your choice
nano pixelserv
  • Change the IP address to a free one of your choice (eg. 192.168.1.99)
$sock = new IO::Socket::INET (  LocalHost => '0.0.0.0',

change to

$sock = new IO::Socket::INET (  LocalHost => '192.168.1.99',
  • Change permissions
chmod 755 /usr/local/pixelserv 

  • Create file /etc/init.d/pixelserv
nano /etc/init.d/pixelserv

and copy the following to it (changing the IP addresses where neccessary):

#! /bin/sh
# /etc/init.d/pixelserv
#

# Carry out specific functions when asked to by the system
case "$1" in
   start)
     echo "Creating Interface "
     ifconfig p2p1:0 192.168.1.99
     echo "Starting pixelserv "
     /usr/local/bin/pixelserv &
     ;;
   stop)
     echo "Stopping script pixelserv"
     pkill -9 pixelserv &
     echo "Killing Interface "
     ifconfig p2p1:0 down
     ;;
   *)
     echo "Usage: /etc/init.d/pixelserv {start|stop}"
     exit 1
     ;;
esac
exit 0
  • Change permissions
chmod 755 /etc/init.d/pixelserv


Enjoy ad-free network on ALL devices!