(of course you could use the file /etc/hosts in the exact same way as for windows, in the OP, but that's just TOO DARN EASY for us Linux folk!)
First, go off to google and do an images search for "spam". Collect up a few smallish spam pictures of your choice and keep them somewhere safe.
Now, get the list of domains from that windows hosts file, and write a simple script to generate entries from them for your name server's config file (you DO run your own name server, I HOPE!) like so:
Excerpt from
named.conf:
zone "ads.infospace.com" IN {
type master;
file "pri/spam.dom";
allow-update { none; };
notify no;
};
zone "ads.msn.com" IN {
type master;
file "pri/spam.dom";
allow-update { none; };
notify no;
};
zone "ads.switchboard.com" IN {
type master;
file "pri/spam.dom";
allow-update { none; };
notify no;
};
zone "doubleclick.net" IN {
type master;
file "pri/spam.dom";
allow-update { none; };
notify no;
};
... etc.
Notice they all reference the same zonefile. That zonefile will look something (or exactly) like this:
Excerpt from
pri/spam.dom zonefile:
$TTL 1W
@ IN SOA ns.localhost. root.localhost. (
2002081602 ; Serial
28800 ; Refresh
14400 ; Retry
604800 ; Expire - 1 week
86400 ) ; Minimum
IN NS ns
@ IN A 1.2.3.4
* IN A 1.2.3.4
Notice the wildcard entry in the bottom line that points anyhost.spam.domain at the same IP address. Make the IP address (shown here as 1.2.3.4) the address of a machine that you control. That will be our spamserver.
On the spamserver machine, get the apache webserver going and give it a virtual hosts configuration entry like this:
Excerpt from
vhosts.conf:
NameVirtualHost 1.2.3.4
<VirtualHost spam>
Servername *
AliasMatch .* /some/directory/spam.php
ServerPath /some/directory/spam
DocumentRoot /some/directory/spam
ErrorLog /var/log/apache2/spam-error_log
</VirtualHost>
Note the wildcard entries that mean any request whatsoever to the server on that IP will end up being answered by our script
/some/directory/spam.php . (If that's a problem because you want to have other content on your web server, just use an additional alias interface for the spamserver, eg.
ifconfig eth0:1 1.2.3.4, or even
ifconfig lo:1 127.1.2.3 on a standalone machine.. Make sure the address you choose matches the one in the
spam.dom zonefile.)
The
spam.php script is very simple, and looks like this:
spam.php:
<?
$filenum = rand(1,25);
$file = $filenum . '.jpg';
Header('Content-type: image/jpg');
readfile($file);
?>
As can be seen, any request made to the script is answered by a random image from the same directory as the script, the images having been named
1.jpg, 2.jpg, ... 25.jpg. Rename the spam images collected earlier in this way, dump them in the directory with
spam.php and you are ready to go.
The result is that wherever you would previously have had advertisement images in webpages you view, you have instead the delightful spectacle of various images of cans of spam, etc. (or whatever you chose to put there) with the compelling side benefit that your requests to evilcorporation.com are not setting cookies in your browser, either. (The windows method gives you that too, but with ugly "broken image" icons in place of the beautiful spam artwork....)
(Edit for formatting)