Pixelserv
The first, and maybe most common is to use pixelserv. This is a really lightweight perl web server that simply serves a 1x1 transparent GIF to any requests made to it. Thus, anytime ads get redirected by dnsmasq to pixelserv, you'll actually receive a tiny image that won't be visible on the page.To start with, download the pixelserv file:
sudo curl /usr/local/bin/pixelserv http://proxytunnel.sourceforge.net/files/pixelserv.pl.txt >pixelserv.pl.txt
sudo chmod 755 /usr/local/bin/pixelserv
sudo nano /usr/local/bin/pixelserv
$sock = new IO::Socket::INET ( LocalHost => '192.168.42.49',
You could try running the server now, but you'd get the following error:
pi@raspberrypi /usr/local/bin $ ./pixelserv error : cannot bind : Cannot assign requested address exit
sudo nano /etc/network/interfaces
iface wlan0 inet static address 192.168.42.1 netmask 255.255.255.0 post-up ip addr add dev wlan0 192.168.42.49/24 pre-down ip addr del dev wlan0 192.168.42.49/24
Now reboot your Pi so the settings take effect:
sudo reboot
sudo /usr/local/bin/pixelserv
First, kill the server you're running by typing "Ctrl-C".
Now, create a new file with nano:
sudo nano /etc/init.d/pixelserv
#!/bin/bash ### BEGIN INIT INFO # Provides: pixelserv # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: pixelserv server for ad blocking # Description: Server for serving 1x1 pixels ### END INIT INFO case "$1" in start) echo "pixelserv: starting" /usr/local/bin/pixelserv & ;; stop) echo "pixelserv: stopping" killall pixelserv ;; *) echo "Usage: service $0 {start|stop}" exit 1 ;; esac exit 0
Change the permissions on that file:
sudo chmod 744 /etc/init.d/pixelserv
sudo /etc/init.d/pixelserv start sudo /etc/init.d/pixelserv stop
update-rc.d pixelserv defaults
sudo service pixelserv start sudo service pixelserv stop
sudo update-rc.d -f pixelserv remove
Apache
As an alternative to pixelserv, we can use Apache to serve a blank html file with an HTTP 200 response. Apache is a bit heavier but likely much more stable than pixelserv.Let's start by installing Apache (make sure to stop and disable pixelserv if you've already installed that):
sudo apt-get install apache2 -y
Test that apache is picking up our redirected requests:
curl doubleclick.com
pi@raspberrypi ~ $ curl doubleclick.com <html><body><h1>It works!</h1> <p>This is the default web page for this server.</p> <p>The web server software is running but no content has been added, yet.</p> </body></html> pi@raspberrypi ~ $
First enable the apache2 rewrite engine by executing the following:
sudo a2enmod rewrite
sudo nano /etc/apache2/sites-available/default
<Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all RewriteEngine on RedirectMatch 200 (.*)$ ErrorDocument 200 " " </Directory>
Make the same change for the default-ssl file as well (sudo nano /etc/apache2/sites-available/default-ssl).
At this point if you restart Apache, you'll get an error about not being able to determine the server's fully qualified domain name. We can fix that by executing the following command:
echo "ServerName raspberrypi" | sudo tee -a /etc/apache2/conf.d/fqdn
sudo service apache2 restart
pi@raspberrypi /etc/apache2/sites-available $ curl doubleclick.com pi@raspberrypi /etc/apache2/sites-available $