Adblock Everywhere: The Raspberry Pi-Hole Way

Justin Pot 25-03-2015

Turn a cheap Raspberry Pi into a network-wide ad blocker. If you’re tired of AdBlock Plus slowing your browser down, this DNS-based option is a great alternative that works on any device. Unlike other solutions, this filters the web before it gets to your device, meaning you can block ads on your iPad or Android without the need for jailbreaking or rooting.


A company called AdTrap AdTrap Is A Little White Box That Blocks All Ads From The Internet For $139 How much would you be willing to pay for an Internet without ads? Meet AdTrap, a new device that promises to block all online ads, whether on your computer or on your mobile. Read More sells a little white box that blocks ads AdTrap Is A Little White Box That Blocks All Ads From The Internet For $139 How much would you be willing to pay for an Internet without ads? Meet AdTrap, a new device that promises to block all online ads, whether on your computer or on your mobile. Read More for $129, but you shouldn’t buy it – a $35 Raspberry Pi and an SD card are all you need to make your own hardware ad blocker for every device on your network. Here’s why Pi-Hole is a better idea than browser extensions, and how to set it up.

To quickly summarize, you need to do three things:

  1. Install a fresh version of Raspbian on your Raspberry Pi.
  2. Run the following script:
    curl -s" | bash
  3. Set up your devices to use your Raspberry Pi’s IP address as their DNS server.

Don’t know what any of this means, or why you’d want to use PiHole in the first place? Keep reading – I can explain.

Why Not Just Use AdBlock? Or The Hosts File?

It’s unintuitive, but AdBlock Plus and similar tools actually slow your browser down. These extensions use custom style sheets to strip ads, meaning that every site you look at is edited on the fly. This comes at a cost.

“Adblock, noscript, ghostery, and other addons like them cause 90% of the issues we see in the forums,” said one Chrome developer on Reddit, adding that such extensions increase memory usage anywhere from 10 to 30 per cent, and page load times by between 15 and 50 per cent.



This adds up quickly, which is why some power users use the hosts file What Is the Windows Host File? And 6 Surprising Ways to Use It The Windows Hosts file allows you to define which domain names (websites) are linked to which IP addresses. It takes precedence over your DNS servers, so your DNS servers may say is linked to... Read More to block ads instead. This approach is better because it prevents known ad servers from ever being loaded on your computer, meaning your browser doesn’t have to strip ads out. The downside: there are literally thousands of ad servers out there, and these lists need to be maintained and updated on all of your devices. And then there are mobile devices, on which you can’t easily edit the hosts file without rooting or jailbreaking.

Pi-Hole runs on a dedicated Raspberry Pi, meaning you only need to set it up once. It’s easy to install, and can update itself using several of the best known lists of ad and malware servers on the web. Let’s set it up.

1. Install a Fresh Copy of Raspian



Jacob Salmela, the man behind PiHole, recommends a clean install of Raspbian before setting up. If you’ve never installed an OS for the Pi before, don’t worry: the process is easy.

First, download Raspbian from Next you need to write the IMG file to your SD card (this will delete whatever is on your SD, so be sure to back up anything important first). How to do this depends on your computer’s operating system:

Use the appropriate tool to write Raspbian to your SD card, then insert your SD card into your Pi. Use an Ethernet cable to directly connect your Pi to your router, and then plug in your Pi’s power adapter. Raspbian will boot.

This is a good time to open your router’s settings and assign the Raspberry Pi a static IP. How to do this will vary depending on your router, so check its documentation for more information (look for “static DHCP reservation”).


2. Run The Pi-Hole Script

Now it’s time to set up Pi-Hole itself. If you’ve got a monitor for your Raspberry Pi, you can use that to set everything up; otherwise, you’ll need to use SSH to connect (this is probably simpler).

The default username and password for your Raspian setup are:

  • Username: pi
  • Password: raspberry

You’ll see instructions for changing this password after logging in for the first time, if you’re interested.

There are easy ways to use SSH in Windows How to Use SSH in Windows: 5 Easy Ways SSH is an encrypted network protocol used for remote access. Here's how to use SSH in Windows using native and third-party apps. Read More ; Mac and Linux users need only to fire up the terminal/command prompt, then use this command:

ssh pi@IP.address

“IP.address”, of course, is replaced with the static IP you assigned earlier.


Once you’ve logged in, all you need to do is run this command:

curl -s "" | bash

This will download the automated Pi-Hole installer and run it. To summarize, this script will:

  • Update your Pi’s software to the latest version.
  • Install a DNS service and a web server
  • Change the settings for these two programs
  • Download lists of known adware servers from 7 different sites.

Lean back and watch the process – it explains each step as it goes along. Once it’s done, we’re almost ready.

3. Set Up Your Devices To Use PiHole

Now that your PiHole is set up, there’s only one thing left to do: point your devices to it. We’ve shown you how to change your DNS settings How To Change Your DNS Servers & Improve Internet Security Imagine this - you wake up one beautiful morning, pour yourself a cup of coffee, and then sit down at your computer to get started with your work for the day. Before you actually get... Read More , but here’s a quick rundown of the method for each major platform. Note that these settings are all specific to your local network, meaning if you sometimes switch between a wireless and wired connection you may need to set it up twice.

Changing Your Windows DNS Server

Head to the Control Panel and find “Change Adapter Settings”. Right click whatever connection you’re currently using, then click “Properties”.


Click “Internet Protocol Version 4”, then click “Properties” again.


Now, click “Use The Following DNS Servers”.


Give your Pi’s IP address as the primary (first) DNS server, and (Google’s DNS service, in case something goes wrong) as the secondary server.

Changing Your Mac DNS Server

Head to your Mac’s Preferences panel, then click “Network”. Click your current connection in the left panel, then click the “Advanced” button at bottom-right. Click “DNS” and you’ll see the following screen:


Give your Pi’s IP address as the primary (top) DNS server, and (Google’s DNS service, in case something goes wrong) as the backup.

Changing Your Android DNS Server

Head to your Android’s settings screen, then tap and hold your current WiFi network. Tap “Modify network” when the option comes up, then tap “Show advanced options”. You’ll see a screen like this:


At the bottom of the screen you can set two DNS servers. Give your Pi’s IP address as DNS 1, and (Google’s DNS service, in case something goes wrong) as DNS 2.

Changing Your iPhone or iPad DNS Server

Head to your device’s preferences, then head to the WiFi. Next to your home network, click the “i” button to bring up more options. Here you’ll see the


Give your Pi’s IP address, followed by a comma, followed by (Google’s DNS service, in case something goes wrong).

(Linux users: there are just too many distros and desktop environments for me to cover you guys well, and I bet you all know how to change DNS settings anyway).

How Well Does It Work?

In our testing, this setup doesn’t let a lot of text or image ads get through. Even major video sites like YouTube stop showing ads altogether once this is set up.

That’s not to say no ads get through whatsoever: streaming music services like Pandora, Spotify and Rdio all kept playing ads in our tests. Jacob Salmela himself struggled when he attempted to block Hulu ads with this setup, so it seems like media ads are a different beast entirely. But work is ongoing.

Still, the web is a very pleasant place with this set up, and browser performance is snappy when compared to AdBlock.

Isn’t Ad Blocking Evil or Something?

Blocking ads is something reasonable people can disagree on. My friend Mihir thinks publishers need to stop whining about AdBlock Publishers Need to Stop Whining About Adblock Ad-blocking seems like a natural option for any consumer because of a simple reason: it's an easy way to get rid of an annoyance. Read More ; another friend, Matt, thinks AdBlock needs to die to save journalism as we know it It's About Ethics in Stealing Games Journalism: Why AdBlock Needs to Die A simple, free browser plugin killed Joystiq – and is ruining the Internet. Read More . As a journalist the ethical implications of blocking ads obviously trouble me, but as a technologist I just think the technology behind Pi-Hole is fascinating.

This article is more about the cool technology that makes blocking ads possible than the ethical implications of that, and I understand there’s a ton of hypocrisy there. But Pi-Hole is so cool, and I couldn’t help but share it with you. Seriously: read more about how PiHole works, and you’ll see why I think it’s brilliant – even if the ethics of blocking ads are murky at best. I hope, if nothing else, getting this working teaches you a bit about how DNS works.

Image Credits: cannon firing a shot Via Shutterstock

Related topics: Ad-Blockers, DNS, Raspberry Pi.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Tech Man
    May 15, 2018 at 10:31 pm

    If you connect to a different network on the Pi, would the DNS server's address change?

  2. donal
    April 3, 2016 at 10:40 pm

    hi folks
    problem here
    i am using pdanet on a tethered android phone (for 4g)
    the pdanet connection uses - pdanet gateway

    the tethered laptop uses - it must use this address to share thru uts own ethernet port(laptop)

    I can use a dd- wrt linksys wrt54g - but dont need to so i just have the laptop feeding an 8 port gigabit switch - i cannot for the life of this get this working - set the raspberry pi to (static) - installed the software - not resolving my main pc on internet - pi itself HAS internet - when i reboot the Pi does the pihole run automatically or do i need to launch it from the command line ??

  3. JC
    March 17, 2016 at 1:57 am

    Has anyone set this up to work outside the local network?

    • Justin Pot
      March 17, 2016 at 2:28 am

      It could just be a matter of some port forwarding, but I'm not sure I'd recommend it.

  4. JC
    March 17, 2016 at 1:56 am

    I have an old (rooted) android phone. Could I run PiHole on this, instead of a raspberry pi?

    • Justin Pot
      March 17, 2016 at 2:28 am

      I don't know how to do that personally, but in theory it could be possible.

  5. Olegbc
    January 7, 2016 at 4:48 am

    Is there a way to just set my router to resolve every request going through it via DNS in Raspberry PI so I don have to change configuration on every connected device?

    • Justin Pot
      January 7, 2016 at 3:19 pm

      I was working on figuring exactly this out when my SD card broke. I need to aquire another one to test it, but my theory is that you could:

      1. Set the Pi to use Google DNS, or Open DNS, instead of just using the DNS server assigned to it.
      2. Ensure that the Pi has a static IP on the local network.
      3. Set the router to use that static IP as the primary DNS server.

      I see no reason why this shouldn't work, but I never actually got it working.

      • Anonymous
        February 4, 2016 at 5:55 am

        I can confirm that this works as it's exactly how I set mine up. The DNS on the Pi set to Google DNS, my router's DNS is set to my Pi's static IP and all user devices on the network are set to DHCP.

        • Justin Pot
          February 4, 2016 at 2:42 pm

          Good to know!

    • Apollo
      March 15, 2016 at 6:30 pm

      Just be sure to have a secondary DNS server listed on your router, else your DNS requests will have no where to go if the Pi goes down for whatever reason. I set my secondary DNS server to Google DNS.

  6. Roy
    December 28, 2015 at 7:14 pm


    I had a Pi eating dust and wanted to do something with it, this works like a charm on my mobile device, but my girlfriends iPad is still showing ads, is there something I may have forgotten?

    Thanks in advance!

    • Justin Pot
      December 29, 2015 at 4:02 am

      Did you change the DNS settings on her iPad? If that doesn't work, try restarting the device maybe.

  7. Justin
    November 26, 2015 at 3:02 pm

    Could this be configured with a port number to use on phone away from home to use ad-blocking features and DNS resolution?

    • Justin Pot
      November 26, 2015 at 4:12 pm

      In theory yes, but I've no idea how well that would work. I suspect it would be pretty slow.

  8. Anonymous
    September 4, 2015 at 8:01 am

    considering buying this, but I have one question, If I get a bigger sd card will it utilize the bigger space for caching or no?

    • Justin Pot
      September 4, 2015 at 2:01 pm

      I don't think a bigger SD card would benefit you for this setup, no.

      • Anonymous
        September 4, 2015 at 7:48 pm

        alright thanks for the quick reply , great post, I cant wait to build me one of these

  9. Anonymous
    July 15, 2015 at 11:36 pm

    Set this up yesterday. Everything worked perfectly. 4 hours later my raspberry pi 2 failed. When I pressed to eject sdcard. It burnt my finger. Card melted and a little deformed on rear of SD card.
    Truly, it burnt my finger.
    Anyone else have this kind of problem?
    Perhaps the constant writing to the card did this.
    I had used the same setup before for xbmc/openelec. Didn't have a problem

    • Justin Pot
      July 16, 2015 at 1:34 pm

      I never experienced this with my setup, which I left running for months. I wonder what might have happened...

      • Anonymous
        July 16, 2015 at 2:35 pm

        I've found some old posts about SD card overheating. But nothing in past 2 years. Not sure if I want to try another SD card. Seriously worried about going up in smoke and perhaps a fire.

    • Anonymous
      July 27, 2015 at 2:07 am

      Was the Pi overclocked?

  10. Anonymous
    June 22, 2015 at 6:42 pm


    Has anyone tested this successfully with iPad/iPhone?


    • Anonymous
      July 28, 2015 at 2:02 pm


    • Justin Pot
      July 28, 2015 at 5:01 pm

      I haven't tested this with an iDevice, sorry, but I see no reason why it wouldn't work.

    • Anonymous
      August 1, 2015 at 2:47 pm

      It works for me for all devices: iPads, droids, Macs, PCs. As long as you can change the DNS server on the device, it should work.

  11. Anonymous
    June 4, 2015 at 6:42 pm

    I'm a complete novice to networking and I can't succeed to get the ad block working :(

    Could someone please help with the settings I should use on my DD-WRT router to route DNS query to Raspberry PI.

    I managed to give static IP to the Raspberry PI and changed the DNS settings on the devices I use (Phone and laptop), but still no luck.

    Please ask if you need any more info to help me.


    • Justin Pot
      June 5, 2015 at 12:30 am

      If you gave a static IP address to the Pi and directed your devices to use it, it should be working. I'm not sure you need to do anything at the router level. Clearing the DNS cache on your devices might help.

    • Anonymous
      June 6, 2015 at 5:51 pm

      Thanks for your reply. Now it works for me :)

      • Justin Pot
        June 6, 2015 at 9:33 pm

        I'm so glad!

  12. BigLair
    April 21, 2015 at 10:57 pm

    Got this working on a new PI 2, works great, router points to the PI Hole for DNS and all devices on my network get the correct DHCP and DNS settings and all are now without ads! Awesome!

    • Chad
      May 3, 2015 at 9:56 pm

      Did you have to change the Pi's DNS so it's not stuck in a loop? I posed that question above, but there hasn't been a confirmed answer to it yet.

  13. Steve
    April 1, 2015 at 11:06 pm

    I'm loving the pi-hole method. It's even taking the ads out of free Android games. I've never found an ad - blocker that would do that!

    • Justin Pot
      April 2, 2015 at 2:07 pm

      Glad it's working!

  14. biff
    March 30, 2015 at 7:38 pm

    Just put a whitelist.txt or blacklist.txt in /etc/pihole/ before running the script. One domain per line.

    • Justin Pot
      March 31, 2015 at 2:17 pm

      I didn't know this! I'll respond to the commentor above again.

  15. philmiami
    March 29, 2015 at 10:48 pm

    I have a AdTrap ( device and/are a person who comments on the user based forums for the AdTrap.
    I got mine right when they became available right after the kickstarter campaign BUT
    I want to do this with the Pi.
    Now my question(s) are this:
    *Does it use something like the EasyBlock list (or download it or any of the readily available free lists of ad servers)?
    *What is the "power" of the Pi? Can it handle multiple devices hitting the router either wired or wireless and block the ad networks?
    *I put up on the forum the MOBILE ad networks, from around the globe. Those that put ads inside of "free" apps on iOS or Android. Those are REAL annoying. Since the apps don't have to use PORT 80 like a web browser to connect, will this be able to stop those ad networks?

    I got my AdTrap and it is 85% useful but does NOT stop anything over HTTPS (like, so on my iMac (I got 3 iMac's, 2 Mac Minis, 2 iPads, Apple TV, Vizio w/wifi, android tablets and phones and stuff) I use FireFox with flash block extensions, Ad Block Plus, and Ghostery ..........will this help in blocking https ads?



    • Justin Pot
      March 30, 2015 at 2:18 pm

      1. This method downloads four of the best-known such lists on the web, then removes the duplicates.
      2. I haven't had trouble with multiple devices, but my testing is admittedly limited.
      3. If the ad networks are on the block list, there's no reason any of their ads can get through.
      4. HTTPS: this method blocks ad servers entirely, so there's no reason anything should slip through regardless of encryption. Having said that, I've noticed some things to get through.

  16. Simon
    March 28, 2015 at 7:58 pm

    A simple partial solution to all the arguing over the ethics and economics of ad blocking is to white-list the specific sites that you want to help financially. This is very easy to do with Ad-Blocker. Is there a way to white list specific sites using Pi-hole?

    • Justin Pot
      March 30, 2015 at 2:15 pm

      Looking over at his site, the authors of PiHole says he's working on a whitelist function but so far as I can tell it's not done yet.

    • Justin Pot
      March 31, 2015 at 2:17 pm

      Hey Simon Bif has a solution for you below, check it out.

  17. Patch
    March 26, 2015 at 9:28 pm

    There are no negative moral or ethical matters concerning blocking ads you don't want to see. It is a choice. It is comparable to changing the radio station when the ads come on. If you aren't interested, you shouldn't have to see or hear it. Want us to pay attention? Attract our attention, and attempt to keep it. Morally shaming those who make a choice to do away with unnecessary information being fed to them is the real shameful act.

    • Justin Pot
      March 26, 2015 at 10:47 pm

      This is less like changing the station when the ads come on and more like designing a radio that will mute the volume during ads. It's a subtle distinction, sure, but it does matter I think. The fact is that if everyone blocked ads – and we're getting closer to that situation ever day – most of the content that's currently free on the web would either stop existing or stop being free.

      We all benefit from ads, whether we block them or not. I hear what you're saying, but I think things are a little more complex than you let on.

    • dragonmouth
      March 28, 2015 at 1:50 pm

      Has it ever been objectively proven that advertising actually brings in more money then it costs? Does seeing an for a product make people want to get that product? Or is it a case of manufacturers convincing themselves that if they don't advertise, they will miss sales?

      I know that advertising is an American institution and tradition (Madison Ave and all that), and would be blasphemous, if not treasonous to suggest that it be totally stopped. But I wonder whether the resulting drop in sales (if any) would not be more than made up by not having to spend $billions on advertising.

  18. thelaptopguru
    March 26, 2015 at 8:58 am

    Has anyone tried running a Pi rom in a VM environment? The Pi's run a Linux based O/S right?

  19. Nunya
    March 25, 2015 at 9:35 pm

    Anyone know of a similar way to do this on a VM? I have a server running several VM's right now, and i don't have a Pi, if I could just add another VM for this that would be great.
    Im sure I could easily add a Windows or Linux machine to do DNS and add the domains myself, but just looking for something as simple as this to implement

    • Justin Pot
      March 25, 2015 at 11:28 pm

      This is a really interesting question. There's no reason this setup couldn't run on any other Linux distro, but the script as it exists right now assumes you're running Raspian. You could take a look at the script and modify it, maybe?

  20. Chad
    March 25, 2015 at 8:55 pm

    Is there a way to set it up so your router's DNS points to the Pi? That way you wouldn't have to change the DNS on each device.

    • Justin Pot
      March 25, 2015 at 9:10 pm

      I've read comments from people who say they achieved this, but every time I tried it the result was the Internet not working on any of my devices. Results might vary depending on your router.

    • Chad
      March 26, 2015 at 1:52 pm

      I would be very interested in learning how others have accomplished this. Initially I thought it would be as simple as changing the router's DNS to point to the Pi, but then the Pi (being connected to the router) would most likely point it's DNS right back to the router and be stuck in a loop. I suppose one could point the Pi's DNS to the ISP's DNS or even just Google's or someplace else. I can't imagine this would actually work differently for different routers, but for argument's sake, I'm running DD-WRT on a Netgear WNDR4000. I'd love to hear results from other people. I'll try to do some testing myself as well if I get time and post what I find.

    • Justin Pot
      March 26, 2015 at 3:11 pm

      Yeah, the more I think about this the more I doubt those commenters who claim they got it to work, but if someone here got it working I'd love to know about it.

  21. rammjet
    March 25, 2015 at 8:55 pm

    I’ve tried the hosts file method before. There are a couple of Google servers that are blocked that also make it impossible to load some Google-cached pages. Then it is a hassle to edit the hosts file to unblock these servers every time it is updated.

    I currently use µBlock. But I’m thinking that my router which runs DD-WRT could do something similar to what is done on the Pi.

    • Justin Pot
      March 25, 2015 at 9:11 pm

      I think you could do something similar with DD-WRT, yes, let us know if you get it working.

  22. DonGateley
    March 25, 2015 at 8:34 pm

    Short of changing your DNS server is there a way to momentarily disable/enable the function? Something perhaps that you can run on the Pi with SSH.

    • Justin Pot
      March 25, 2015 at 11:27 pm

      Not that I know of, though I suppose you could just turn the DNS server off.

    • DonGateley
      March 26, 2015 at 12:19 am

      Thanks, Justin. For the naive, how would one do that?

    • Justin Pot
      March 26, 2015 at 1:48 pm

      I'd have to read into this to find a method, it's far easier to just change your DNS servers using a program like this:


    • DonGateley
      March 26, 2015 at 8:10 pm

      Thanks. Justin. DNS Jumper is simply too cool not to have. The amount of useful info at makeuseof never ceases to amaze me.

  23. GSystems
    March 25, 2015 at 7:45 pm

    You guys just reminded me to update my HOSTS file lol Thanks!

    Another suggestion (that I employ on my network) is OpenDNS. It can get tedious at times, but it works wonders and provides many other services (like individual domain blocking and, of course, DNS-caching).

    • Justin Pot
      March 25, 2015 at 8:10 pm

      So far readers seem to be reminded to do everything but set up a Pi-Hole! I hope someone gives it a shot eventually, I'm really enjoying mine.

      As for OpenDNS: this is a great idea. I need to review this, is there a way to automatically updated it like there is with Pi-Hole?

    • GSystems
      March 25, 2015 at 8:47 pm

      lol...I don't have a Rasberry Pi, but it still intrigues me seeing the amazing things people do with it.

      No, sir...that is definitely a drawback that makes it "tedious." Perhaps OpenDNS updates their categorical servers regularly (as a matter of fact, I am sure they do), but no where near as extensive as what you're doing with Pi...or even folks are doing with HOSTS.

      Every now and then I'll take a night, get the latest list, and manually add in the servers to block...but that's only when I'm extremely bored.

    • Justin Pot
      March 25, 2015 at 9:12 pm

      You should totally get a Pi! They're like twenty bucks, it's not a huge investment. And there are so many fun things you can do!

    • GSystems
      March 25, 2015 at 10:03 pm

      Perhaps I will. I didn't realize the barrier to entry was so low. Hmmm.

  24. Thibault Maekelbergh
    March 25, 2015 at 5:14 pm

    How will this effect me if I switch locations each day?
    If I set my MacBook to the pi's DNS servers and go to school or work, will I have to manually adjust them?

    • Justin Pot
      March 25, 2015 at 6:02 pm

      Your DNS settings are unique to the network you're using, so you won't have to reconfigure your settings when you leave your home. The ad blocking will stop working, however – it's tied to your network.

  25. gett
    March 25, 2015 at 4:21 pm

    Is it working on Pi 2?

    • Justin Pot
      March 25, 2015 at 4:30 pm

      I can't think of any reason why it wouldn't work on a Pi 2! Seems like a bit of a waste, though.

  26. michel
    March 25, 2015 at 3:51 pm

    So you're saying the blocking add-ons slow down your browser; the add-on makers claim it speeds up your browser. Who's right?

    • Sam
      March 25, 2015 at 4:12 pm

      Maybe try a browser benchmark with it enabled and disabled? I'd guess there's very little slowdown from ABP if all it's doing is loading a custom stylesheet - CSS is just a tiny bit of text so the file is probably not even a kilobyte.

    • Justin Pot
      March 25, 2015 at 8:13 pm

      The problem with the custom style sheets is that modern web pages have iframes within iframes within iframes, and all of those end up with their own custom style sheets. But you're right: we should do testing on this. I hope we can get an article looking into these claims out soon, because I was basing this entirely on my own subjective experience.

      Having said that: man, does Pi-Hole ever feel faster than adblock.