I use a custom version of the thttpd daemon on my Freesco box to solve an aesthetic problem I have when browsing web pages. I use another GNU/Linux-based machine as my default gateway, and all DNS lookups are served through it. I have a hosts file on this gateway generated by this site and this site which resolves many ad servers to incorrect IP addresses. This saves bandwidth and avoids downloading many adverts - although never 100%. Where adverts are supposed to be embedded in another webpage, the connections time out and the timeout messages are inlaid in the page. This doesn't look very nice, so I have customised a version of thttpd, and inserted it into a Freesco 0.2.7 RAMDISK image, which you can download here.
I then tweaked the hosts file on the gateway machine to use the IP address of my Freesco box, rather than the loopback IP address of 127.0.0.1 or other invalid address. When a page with a “banned” advert is loaded, the default gateway looks to my Freesco box to serve the advert. Through the use of customised error pages, a nice plain colour is inserted into the page instead, like this.
README - Contains information about using the Adblocker
RAMDISK - Custom ramdisk file for Freesco 0.2.7 with Custom built version of thttpd included
thttpdad - Custom built version of Acme's thttpd-2.20c web server
errors.html - Example of an error page. This page has a pale blue background, which is seen when substitued into other pages.
config.h - The config.h file used to build this custom version of thttpd-2.20c. Included for reference only.
files.md5 - md5 checksums for the files in this tarball.
A Ramdisk is (in this case) a compacted image of a root file system, containing files and executables. It is expanded into RAM on boot, hence the name.
This particular Ramdisk contains the files necessary to run the Freesco 0.2.7 router with an additional feature designed to replace adverts in a web page with an html page of your choice. (The suggestion is an empty page of light background colour.)
A PC capable of running Freesco 0.2.7. Check out the Freesco website to see what this includes.
A HDD in the PC. Unfortunately, the custom ramdisk is too large to fit onto the Freesco 0.2.7 floppy disk, and so a hard disk install is required.
The tarball containing the Custom Freesco 0.2.7 ramdisk.
A fresh Freesco 0.2.7 floppy disk.
Another blank,
MS-DOS formatted floppy disk.
A hosts file listing servers to be blocked.
The setup procedure is divided into two stages: Adblocking Server Setup and Network DNS Setup.
Format the hard disk with a FAT16 filesystem, and install a
MS-DOS-like operating system. I use
MS-DOS 6 underneath my Freesco system, so that is the example that this page will use. However, people have reported that PC-DOS and Free-DOS work with Freesco running on top.
copy the file “ramdisk” to a blank MS-DOS formatted floppy disk.
Do not enter the “setup” mode at the boot prompt, but leave the system to boot to the full router mode.
At the login prompt enter the username root and the password root.
Enter move2hdd at the system prompt.
Choose option c for a clean install to the hard disk.
The process will take about a minute. Once it is complete, enter “halt” at the system prompt. The system will then shut down.
At the
MS-DOS prompt, change to the c:\router directory.
cd router
rename ramdisk ramdisk.bak
copy a:\ramdisk c:
start the router properly. (I use the Boot Option Batch File to automate this for me.) At the DOS prompt enter:
router
edit /rc/rc_httpd
killall thttpd
and add a new line after it:
killall thttpdad
thttpd -p $WWWPORT -u nobody -d /www -l /dev/null && $DONE
and change it to read:
thttpdad -p $WWWPORT -u nobody -d /www -l /dev/null && $DONE
mkdir /www/errors
chmod 0755 /www/errors
edit /www/errors/errors.html
<html><body bgcolor="eff7f9"></body></html>
called /www/errors/err4XX.html to /www/errors/errors.html, where XX is every two-digit integer between 01 and 15.
ln -s /www/errors/errors.html /www/errors/err401.html
Test your adblocking server by entering http://freesco/dontexist.html, where freesco is the IP address of your Freesco box, in a web browser on a client system.
N.B. Exactly how you setup your network DNS will depend on the topology of your network, and the operating systems used on the DNS relays.
-
Instead of generating a file with 127.0.0.1 or 0.0.0.0 use the dialog box to generate one with the IP address of your Freesco 0.2.7-adblock box. For example:
192.168.0.100 iservelotsofadverts.com
You should use the local IP address of the Freesco box regardless of whether or not it is also being used as the primary
DNS relay for the network. This is because the IP addresses listed in the hosts file are passed back to the client machines unchanged following a
DNS lookup request. Therefore, if 127.0.0.1 was used, clients would attempt to use their own loopback interfaces rather than the Freesco box.
Check the current hosts file on the primary
DNS relay for existing
name resolutions. As my primary
DNS relay is linux-based, I check the file /etc/hosts.
Copy any existing name resolutions from the existing hosts file into your new file unchanged.
Place the hosts file containing the adserver list in the appropriate place on your primary
DNS relay. For example, I copy the new hosts file over the existing /etc/hosts file.
Ensure that the system on which your primary
DNS relay resides uses itself as a
nameserver, and uses the hosts file before requesting a
DNS lookup from a remote server.
In practice this means that /etc/resolv.conf should contain the line:
nameserver 127.0.0.1
before any other nameserver IP addresses and that /etc/host.conf should contain the line:
order hosts,bind
Ensure that your
DNS relay daemon is setup to use the host system as its primary
DNS server, followed by its “regular”
DNS server as its secondary
DNS server.
As my primary
DNS relay is part of a firewall based GNU/Linux distribution, there is a simple menu to set this up. How you do this on your system will very much depend on the software you are running.
You can test that your setup is correct by using a resolving tool like nslookup under linux or Dreamsys Advanced Net Tools under Windows on a
DNS client system.
The text of this page is licensed under a Creative Commons License.