DEV Community

Cover image for Say Goodbye to Ads with Pi-Hole
Bhavesh Yadav
Bhavesh Yadav

Posted on

Say Goodbye to Ads with Pi-Hole

Are you annoyed by the endless stream of ads attacking you or your family from your computer to your phone, or TV? They're basically everywhere. Is it even possible to get rid of them once and for all in your whole network? Your whole house? So you don't need to set something on each and every one device. 💻📱📺

They're basically everywhere 🌍. Is it possible to get rid of them once and for all in your whole network? Your whole house? 🏠

Good news! There is. And you can set it up to work with one device or your whole network in your home.


What is Pi-Hole?

It's a piece of nifty little software named Pi-Hole. Back in the days when this project was created, it started as a piece of software for Raspberry Pi. Raspberry Pi is this little bad boy. It's a whole computer on one board the size of a credit card. It's cheap, and it consumes very little energy. In years to come, Pi-Hole evolved to be the one easy-to-use solution to your Ad problems.

Wanna read more about the latest Raspberry Pi 5? Read my blog covering the all new Raspberry Pi 5 https://dev.to/bhavesh_yadav/raspberry-pi-5-4c2l

Nowadays, thanks to new technologies like Docker and Pi-Hole itself, you can run it on almost any kind of modern computer.
💡🖥️ Pi-Hole is a nifty little software originally designed for Raspberry Pi, but now it can be run on almost any modern computer. It's an easy-to-use solution to your Ad problems.


How does Pi-Hole work?

In short, technically speaking, Pi-Hole is a DNS server with huge blocklists of ad servers that you deploy in your network and run your traffic through.

When you open a web page, let's say cnn.com, the DNS, or Domain Name System, in your device and network, will translate the youtube.com address to an IP address — the IP address is a representation of that address in numbers 🌐. The DNS translates the web address to an IP address.

Typically, ads on webpages are served from different URLs and servers, even if they appear on the same website. So when you introduce Pi-Hole to your network and open, for example, mentioned youtube.com, it will look into its vast database and translate all the ad-serving addresses or URLs to a numbered address that doesn't exist.

Basically, sending those requests into a black hole 🕳️- thus the name Pi-Hole. In the end, your device thinks those Ads don't exist and won't show them to you. It's a very simple idea. But an effective one.

Pi-Hole replaces ad-serving addresses with a numbered address that doesn't exist, effectively blocking ads.


Setting Up Pi-Hole

With the default configuration today, Pi-Hole has over 213,000 addresses in its blocklist. And you can expand it with more blocklists. But even the default one is more than enough in my experience.

Imagine, with a few clicks, all ads in your home are shut to hell. Not just on your phone. TV too, kids' computers, tablets. Everything. Of course, you can set it to work with only one device, but why would you do that? You can accomplish that in a different way.

What I see as the main benefit here is the capability to safeguard your whole network.


Installation

Okay, enough of theory. How can you make it work? Among other ways, there are two really easy ones. The first one is to install Pi-Hole the usual way on some hardware - if you have Raspberry Pi lying around or you have, let's say, a Debian Linux server running in your home somewhere, or it can be a virtual machine, you can do it this way.

Just follow these steps:

  1. Hop to the website Pi-Hole.
  2. Click on "Install Pi-Hole".
  3. Copy the provided oneliner command.
  4. Paste the command into the terminal/console 💻.

It will take care of the installation of Pi-Hole for you. Can't be any easier.


Only for Nerds

However, the way I like to handle my applications is through the containers and Docker 🐳. It's lightweight, clean, and solves a ton of things for me - but I'm not here to sell you Docker.

By the way, it's free technology. Let me show you how easily you can deploy Pi-Hole using Docker 🐳 and Portainer. I'll bet you can do it under maybe a minute. Let's do it.

Wanna know more about docker? Check my blog series on docker https://dev.to/bhavesh_yadav/series/25808 :)

Deploying Pi-Hole with Docker and Portainer

  1. Open Portainer.
  2. Choose a device you want to run Pi-Hole on (e.g., Raspberry Pi 3B).
  3. Go to "Stacks" and add a stack.
  4. Name the stack "pihole".
  5. Open pi-hole.net, hit "Docker install".
  6. Scroll up to the "Quickstart" section and copy it.
  7. Go back to Portainer and paste the copied text.
  8. Make a few changes:
  9. Ensure Pi-Hole does not interfere with your DHCP.
  10. Set the web interface to use port 8010.
  11. Set your location/timezone.
  12. Specify a web password.
  13. Deploy the stack.
  14. Wait for the container to start.
  15. Once the state says "healthy," go to the IP address of your Raspberry Pi (e.g., http://:8010/admin).
  16. Login using the specified web password.

If you want to know more about Portainer, just comment below ⬇️

The whole setup process took only a couple of minutes. And just like that, the Pi-Hole is up and running 🎉


Configuring Devices to Use Pi-Hole as a DNS Server

Now that Pi-Hole is running, the next step is to configure your devices or whole network to use Pi-Hole as a DNS server.

The best way to configure Pi-Hole as a DNS server is through your DHCP server or router in your network. This way, all the devices in your network will automatically use Pi-Hole. The following steps demonstrate how to set it up using the pfSense router:

  1. Open your router settings.
  2. Go to System -> General Setup.
  3. Set the DNS server to the IP address where your Pi-Hole is running.
  4. Enable "Use remote DNS Servers, ignore local DNS" to ensure Pi-Hole handles all DNS queries.
  5. Save the changes.
  6. Go to Services -> DNS Resolver.
  7. Enable "DNS Resolver", "DNSSEC Support", and "Enable Forwarding Mode."
  8. Save and apply the changes.

Note that this part is different for all routers just look for DNS settings, only the names will be different but the core concept is same only.

Now, All DNS queries in your network will be handled by Pi-Hole, blocking ads.


Enjoy Ad-Free Browsing

You can log in and fine-tune your Pi-Hole settings as per your requirements. From this point forward, know that you will be spammed a lot less with all the junk the internet is flooded with.

✅ Enjoy ad-free browsing!


Conclusion

With Pi-Hole, you can enjoy an ad-free browsing experience across your entire network, from your phones to your TVs and computers. No more annoying and intrusive ads. You can fine-tune your settings in Pi-Hole and explore its features further.

Thats it for today guys meet you in the next one.

Till then
Happy Coding!


Top comments (0)