Ad-blocking with Freesco without ruining the hosting page

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 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.

About the RAMDISK

The freesco-0.2.7-adblock.tar.gz file contains the following files:

  • 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.

What does this Ramdisk do ?

  • 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.)

What is in the Ramdisk?

  • The Ramdisk is identical to the one included with Freesco 0.2.7 except:
    1. /lib/ replaced by from ZipSlack 3.9
    2. /bin/thttpdad added
  • The original thttpd executable remains in place to serve the HTTP control interface, and any other “normal” HTTP needs you may have.

What do I need to use this Ramdisk ?

  1. A PC capable of running Freesco 0.2.7. Check out the Freesco website to see what this includes.
  2. 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.
  3. The tarball containing the Custom Freesco 0.2.7 ramdisk.
  4. A fresh Freesco 0.2.7 floppy disk.
  5. Another blank, MS-DOS formatted floppy disk.
  6. A hosts file listing servers to be blocked.

Web Resources

Using the RAMDISK

The setup procedure is divided into two stages: Adblocking Server Setup and Network DNS Setup.

Adblocking Server Setup

Prepare the hard disk in the system that will become your Freesco 0.2.7-adblock system.

  • 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.

Prepare the Freesco 0.2.7 floppy disk using the original Freesco 0.2.7 file

download it from

  • Follow the instructions on their website to create the standard Freesco 0.2.7 floppy disk.

Untar the freesco-0.2.7-adblock.tar.gz tarball

copy the file “ramdisk” to a blank MS-DOS formatted floppy disk.

  • You will need unzipping software to do this. Under Windows, WinZip and WinRar will both expand the files. Of course, under GNU/Linux the tar tool can be used.

Boot the system from the Freesco 0.2.7 floppy disk and move the setup to the hard 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.

Remove the floppy disk from the system, and boot from the hard disk.

  • At the MS-DOS prompt, change to the c:\router directory.
cd router
  • Rename c:\router\ramdisk to c:\router\ramdisk.bak
rename ramdisk ramdisk.bak
  • Insert the floppy disk containing the Freesco 0.2.7-adblock ramdisk into the floppy drive.
  • Copy the file a:\ramdisk to c:\router\ramdisk.
copy a:\ramdisk c:
  • Remove the floppy disk from the drive.

Run the router setup procedure.

router setup
  • Follow the setup procedure as per the Freesco 0.2.7 manual.
  • Be sure to enable the public HTTP server when the option is given.
  • Once you have finished the setup procedure and saved your settings the system will automatically reboot.

Once the system has rebooted to the MS-DOS prompt

start the router properly. (I use the Boot Option Batch File to automate this for me.) At the DOS prompt enter:


Login as root and stop the HTTP server.

  • At the login prompt enter the username “root” and the password you set during the setup procedure.
  • At the system prompt stop the HTTP server using:
rc_httpd stop

Edit the rc_httpd script to execute the custom version of thttp in place of the public HTTP server.

  • At the system prompt enter:
edit /rc/rc_httpd
  • Navigate to the line that says:
killall thttpd

and add a new line after it:

killall thttpdad
  • Navigate to the line that says:
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
  • Exit the editor using Alt+x. Press “y” to save your changes when prompted.

Start the HTTP server(s) again :

rc_httpd start

Create the /www/errors directory and create a custom error page.

  • At the system prompt enter:
mkdir /www/errors
chmod 0755 /www/errors
  • At the system prompt enter:
edit /www/errors/errors.html
  • Enter the following line as the contents of the file:
<html><body bgcolor="eff7f9"></body></html>
  • The string #eff7f9 is the colour of the page that will be served. The string given produces a light blue colour.

    would be white.

  • You could could use any html page as your error “master page”, perhaps containing a graphic.

Create links

called /www/errors/err4XX.html to /www/errors/errors.html, where XX is every two-digit integer between 01 and 15.

  • At the system prompt enter:
ln -s /www/errors/errors.html /www/errors/err401.html
  • Repeat the above line, increasing the value of the error page number by one every time. Stop once you have created err415.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.

  • Your error page should appear, which is by default a blank page with a light blue background.

Network DNS Setup

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.

  1. Use and/or to generate a hosts file which lists adservers.
  2. Instead of generating a file with or use the dialog box to generate one with the IP address of your Freesco 0.2.7-adblock box. For example:
  3. 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 was used, clients would attempt to use their own loopback interfaces rather than the Freesco box.
  4. 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.
  5. Copy any existing name resolutions from the existing hosts file into your new file unchanged.
  6. 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.
  7. 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:

      before any other nameserver IP addresses and that /etc/host.conf should contain the line:

      order hosts,bind
  8. 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.
  9. 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.
    • First attempt to resolve a domain name that isn't listed in the adserver hosts file, eg: The example given should resolve to an IP address of
    • Next attempt to resolve a domain name that is listed in the adserver's hosts file, eg: It should resolve to the IP address of your Freesco box.

The text of this page is licensed under a Creative Commons License.

freesco/howtos/ad-blocking_with_freesco_without_ruining_the_hosting_page.txt (66996 views) · Last modified: 2005/09/14 00:49 (external edit)
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki