I have been using a windows host file to block ads on websites for a while now.  The host file (http://www.mvps.org/winhelp2002/hosts.txt) redirects most ad links to instead of their IP address.  By doing this, it shows either a blank page or “page can not be displayed” instead of the normal advertisements.

I wanted to take this one step further and apply this to my router (Linksys E2000) using DD-WRT.  After searching the dd-wrt forums (http://www.dd-wrt.com/phpBB2/viewtopic.php?t=20346), I came across the script to do this.  Some routers like WRT54G v5 and v6 will not be able to do this as there is not enough memeory to store the host file.

To apply the script you will need to do 3 steps.

  1.  Under the Services Tab, enable DNSMasq.
  2.  Under the Services Tab, enable Local DNS.
  3. Under the Administration Tab, click the Commands tab.  Paste the code below in the box and click ‘Save Firewall’.


  • Save Firewall – Saves this as a firewall script.  Every time your WAN port connects up, it will redownload the host file.
  • Save Startup – Saves this script as a startup script.  Each time your router boots, it will download the hosts file.
  • Run Commands – Run the script once.
  • Save Custom Script – Saves the script but does not run it, it stores it so you may run it manually.


What this script does it downloads the host file from the above link, searches for the IP address of, replaces with and then saves it to /etc/hosts on the router.  This will replace /etc/hosts file so you will not be able to use http://DD-WRT to get to the router anymore.  Just use or whatever the router IP address is.

Here is the script:
wget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep -v "#" | sed -e '2,$s/' -e 's/[[:space:]]*#.*$//' > /etc/hosts
logger "$0: Hosts-file downloaded"
stopservice dnsmasq
startservice dnsmasq
logger "$0: DNSMasq restarted"


Update: MVPS.org changed the format of the hosts.txt file from to Script has been modified to remove the comments (#).