Instant Raspberry Pi Ad-blocker

This Will Install The New Version Of The Pi-hole Only!

Run this command only on a clean install of the Raspberry Pi running Raspbian.  Your results may vary if you try to run this on an existing system, so it is not recommended.

  1. Install Raspbian onto the Pi (use this version if you plan on installing the mini LCD for real-time monitoring at some point)
  2. Connect the Pi to your router with an Ethernet cable
  3. (suggested) run sudo raspi-config  to expand the filesystem and give the GPU less memory
  4. Edit the /etc/network/interfaces  file to use a static IP address [critical step]
  5. Run this command (if you forgot to set a static IP, then run /usr/local/bin/gravity.sh after that command finishes)
  6. Configure your computers/devices to use the Pi as their DNS server [critical step]
  7. (optional) Block malware or tracking sites
  8. (optional) Use alternative upstream DNS servers

Test If It Works

You can test if ads get blocked by using this site.

Details

https://github.com/jacobsalmela/pi-hole

 

26 Replies to “Instant Raspberry Pi Ad-blocker”

  1. Hi! Is there any way to implement this method on Open-wrt? I would like to block ads on the router, so I don’t need to use AdBlockers on all my PCs and phones

    1. Without knowing too much, it seems to me it might be possible. The Pi-hole is just a DNS/Web server. A router already has both of these; it’s just a matter of figuring out how to deploy these settings.

      I am not familiar with Open-WRT, but I am planning on combining the Raspberry Pi wireless router and the Pi-hole into a single project (with another one-command install). It won’t be as powerful as a consumer router with Open-WRT on it, but it should work just fine.

      1. Hey Jacob,

        It’s great that you’re working on this. Would it be possible for this to work with openvpn aswell? My ideal set up is the pi connected via an ethernet powerline adapter and transmitting a wifi signal via wifi adapter. The pi will be running adblock and a always on vpn (from some vpn provider such as pia). Is that too complicated?

        1. It’s been a while since I have setup OpenVPN, so I cannot say yes or no definitively. However, if you can be on the same network as the Pi-hole, you should be able to get the ad-blocking power. But I don’t know how well it would work trying to run OpenVPN, dnsmasq, lighttpd,and have it function as an access point…

  2. I have ads coming up for Youtube on my iPad – it’s the only device I’m yet to install an ad-block app since that requires Jailbreaking.

    Why do you suppose that is?

    1. I have noticed that some hulu-plus-video-ads-raspberry-pi/video ads are more difficult to block. I think it has to do with it expecting video content but a blank Web page is being delivered instead.

      You can start by watching the DNS log file to see what domains are being queried and then verify that they are on the /etc/dnsmasq.d/adList.conf and are being sent to the Pi-hole.

      Use this command to watch the log in real time as the ads appear:

      tail -f /var/log/daemon.log

      That is a good starting point anyway!

  3. Jacob – thanks for making this, it’s great!

    Question – 1) How do I keep the ad-blocking lists up to date? and 2) Will the log file eventually grow larger than my SD card in the Raspberry Pi? – if so, how would I erase the log file to “start over”?

    Thanks.

    1. You can simply run the gravity-adv.sh script. It just goes out and re-downloads every list. Not exactly perfect as it wipes out the old file and makes a new one. But it does work.

      If you are talking about DNS log file, it is actually stored in RAM and can be cleared out when you restart.

      1. As a noob, how do you run the “gravity-adv.sh” script?

        Would I just past this into terminal: “sudo /usr/local/bin/gravity.sh &” and then restart the raspberry pi for changes to take effect?

        thanks.

    2. If you want to run just the gravity.sh script, there are a few different ways.

      The easiest would be to do it like the command in this post, but replace the URL:

      curl -s https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity-adv.sh | bash

      Alternatively, you could download the file to your computer

      curl -o $HOME/gravity-adv.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity-adv.sh

      and then run it locally (the extra command is to make sure it executable):

      chmod 755 $HOME/gravity-adv.sh
      $HOME/gravity-adv.sh

      You could also simply just copy the script and paste it into a new file and then run the commands above.

  4. I’ve setup my raspberry Pi 2 with your script, but am finding images from important sites like xkcd are not loading? How do I tweak the block list to accommodate?

    1. You need to put a whitelist.txt in /etc/pihole/ with one domain per line. I had one other person who had issues with xkcd and that worked for them.

      If you still have troubles, you may want to try running this updated script, which hasn’t been merged with the master branch because we are still fine-tuning it. But it does do a little better job of whitelisting sites.

  5. Did not work for me. I ran the one line command and there were no errors.

    When I put the IP address of the PI as my DNS on my mobile device I cannot load any webpages. I get the following error:

    DNS_PROBE_FINISHED_NXDOMAIN

  6. 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) (the static IP I
    gave to PI), but still no luck.

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

    Thanks.

    1. You need to have Raspbian installed, which should be doable when you first boot up thanks to the NOOBS that is on your SD card. Plug the Pi into your router. Then, just run the command:

      curl -s "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/automated%20install/basic-install.sh" | bash.

      But be aware that performance might suffer at the moment, so you will need to run one more command to download the old list.

      1. I have yet to plug in and power the Pi
        it has a OS on the microSD card
        but wouldn’t I have to connect to a tv, put a keyboard and mouse on it and then boot it up and let it install a OS first, or just plug it in and let it go an let it get a ip address from the router thru DHCP

        1. Honesty, I have never used NOOBs, but I think it does let you choose an OS to install, which should be Raspbian.

          You can hook it up to a TV. I usually configure the Pi from my Mac by putting it in headless mode, which is usually easier for copying/pasting codes, etc.

          1. I am going to hook to tv, use my USB apple keyboard and a old usb mouse to set it up
            yes, raspberry os is there from what I read to pick
            It also comes with a wifi adapter USB but I will use a cable first
            see how it goes

  7. What effects will setting up this ad blocking server have on my network speed? is performance slowed any or at all? I would assume that if all traffic was routed through the rasbpi then my network speed may suffer.

    1. It actually makes your network faster since the ads are never downloaded. The Pi doesn’t act as a router–it just responds to DNS queries and then tells it where to find it. Your network router will still perform most of the work. Everyone I talk to say it makes their network faster.

Leave a Reply