Tutorial:Disable Ads with DD-WRT

If you are running DD-WRT on your router and you hate ads, here is the solution to disable them on every computer in your home.

  1. Navigate to the “Services | Services” tab on your DD-WRT router.
  2. Under “DNSMasq“, make sure “DNSMasq” and “Local DNS” are enabled. Then copy and paste the following code into the “Additional DNSMasq Options” text box.

  3. Next, navigate to “Administration | Commands“.  Copy and paste the following code into the “Commands” form.  Then click the “Save Startup” button.
    echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^\" | grep -v localhost | awk '{print \"$_rogue\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n" >/tmp/write_dlhosts
    echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
    chmod +x /tmp/write_dlhosts
    /tmp/write_dlhosts &

  4. Reboot your router.

If you would like to confirm that your blocking is enabled, open a command prompt and type in “nslookup admarket.cz“. You should get an address of back from your DNS server.

For further information and the source of this information, take a look over on the DD-WRT forums

    • Anthony (DarkiLLuSiOn)
    • April 20th, 2013

    You say _rogue=
    but on the pic it shows : _rogue= O_o

      • Joel
      • April 24th, 2013

      Either one will work as the _rogue= variable is just where you are pointing all ad URL’s to. I’ll update the article though. Thanks!

    • zYuz
    • April 24th, 2013

    Are there any way to add more ads-blocking sites to this script ?

    For example: http://hosts-file.net/ad_servers.asp

    Is this script including pixserv ?

    • ihateADs
    • December 6th, 2014

    Here is some more ad-blocking lists,


    This one below uses ssl so you have to add –no-check-certificate
    wget -qO- –no-check-certificate “https://adaway.org/hosts.txt”

    • Ankur
    • February 1st, 2015

    I’ve tried the script as you have suggested, it downloads quite a lot of hosts in the /temp/dlhosts file however the nslookup admarket.cz still resolves the actual IP address.

    I’ve OpenDNS configured in my Static DNS entries, would that be the reason?

    How do I check if relevant Ads are still being blocked?

    • bong
    • September 6th, 2015

    Not working.
    Ads are still there

    • jedlyu
    • November 7th, 2015

    Not working. Eventually I did login to the router as root. In the /tmp dir is a “write_dlhosts” script. I executed it & there was created a ‘dlhosts’ file. & ads are blocked subsequently.

    • joyfe
    • November 21st, 2015


    cna you post some steps that you did when you executed the script write_dlhosts as when i am trying to do the same nothing happens after it.

    • Eddie
    • September 25th, 2016

    So, I would really like to install this script. Issue is I have VPN scripts, what would be the syntax to add this after the VPN starts?

    Thanks in advance, Ed

    • svd
    • October 23rd, 2016

    there is a typo in the script:

    there should be ” -v ” in this part: “grep -v \”^\” | grep”

    • robert
    • December 3rd, 2016

    I’m really just looking to block Hulu ads on my devices like my smart tv and Fire tv. Will this work on that?

    • Michal
    • December 20th, 2016

    Hi all,
    So what is the functional guidance? I also have DD-WRT and want to block ads and popups …

    Thank Michal

  1. No trackbacks yet.