Baking a pie to block ads

Vatsal Mishra
6 min readDec 27, 2020

Part 1: Introduction to servers, raspberry pi and DNS based ad-blockers.

Yes, that’s the tiny board capable of big things!


What is a server?
A server is just a computer which “serves” other computers which connect to it (also known as clients). It might have a different hardware/software as compared to conventional computers, but in the end, it’s just that; a computer dedicated to serving other computers which connect to it.

Searching for something on That request goes to a server, it processes it and returns the result to your device (your PC, mobile device etc.).
Watching a movie on Netflix? That request goes to Netflix’s servers and it serves the request by streaming that movie to your device.
Even opening up a simple website sends a request to that website’s servers and it returns the webpage to the browser, thereby “serving" that client. I can go on and on about servers, but I think you get the point.
There are different types of servers for different purposes:

  • File servers (FileZilla, Samba etc.)
  • Web servers (Apache, Nginx etc.)
  • Print servers (Mostly printers in offices which the employees use)
  • DNS servers (Cloudfare, Google DNS servers, OpenDNS etc.)
  • Mail servers (SMTP, POP3, IMAP servers etc.)
    Gmail, Yahoo, Hotmail etc. are clients which make use of these mail servers to send and receive emails. All of these companies have their own POP/SMTP/IMAP servers
  • Database serversc(Microsoft SQL Server, MySQL servers, PostgreSQL servers etc.)

There are definitely more, and every type of server is usually built, customized and optimized to serve a particular purpose but for personal use you can go for a general purpose server usually made from a re-purposed laptop,desktop or a Raspberry Pi (which is what we will be doing here).
You can read more about servers here.

What is a Raspberry Pi?

So many pis!

A Raspberry Pi is an ultra portable single board computer which can be used for almost anything, from creating your own little ad-block server to a fully functional smart mirror (like in those fancy sci-fi movies).
One of the common uses for this board is to set up your own general purpose server which can be used for services like blocking ads on your network, setting up your own cloud storage service (like Dropbox, Google Drive etc.), creating your own media streaming service (like Netflix) etc. The limit is your imagination, and probably the processing power of the board. You can always use multiple pis(or pies?) and build a cluster to get more power and even rival more expensive systems.

What am I making?

Block ads on your network!

I will be starting with a network wide ad-blocking server and it can be categorized as DNS server (pi-hole if you want to be specific). Although for personal use, I can probably give it more functions as well.
DNS or Domain Name System is basically like a phonebook for the internet. Whenever you type a website name, the request goes to a DNS server which looks up the IP address of that website and then serves it to your browser. If the browser has a cached version, then this step is not required. You can read more about DNS and how it works here.

So whenever you see an ad on your device, this is an oversimplified version of how that happens:

  • Step 1: You type in the website address in your browser
  • Step 2: The website starts loading and there are certain ad slots on the page (usually the top or the sides, but there can be ones in the middle as well)
  • Step 3: The ad slots send a request to the ad servers to display the ads (DNS lookup for the ad servers happen here)
  • Step 4: The ad is displayed
Image courtesy:

This personal ad-blocking server works by blocking all DNS lookups for known ad servers so basically the browser will just see a blank slot or an error message in the ad slot (this ad-block server basically works in step 3). This serves 2 main purposes:

  1. No more pesky, annoying ads
  2. No more activity tracking by the embedded codes in those ads

Our primary objective is blocking ads but this can also be used to block any kinds of websites by adding on to the list.

This is the first post in a series of articles about building and maintaining your own server(s) over which you have complete control. No more issues related to privacy, data security, user tracking and other such annoyances. Continue to the “Why” section for more details.

My objective is to use open-source solutions for everything and spend as little as possible. The intended audience doesn’t need to have background in programming or networking, but any relevant experience is definitely a plus!


Why am I doing this?
There are multiple reasons. I’m doing this because:

  • I want to learn about computer networks, system administration, servers and Linux in general.
  • I want to have complete control and visibility over my data and network with as little third party interference as possible. When you are using services by a third party, you are willingly giving up a lot of control and your data to them which they can use however they want and may not treat it like you would. Obviously, with anything connected to the internet there are always risks, but the objective here is to minimize that. Having your own server makes sure that the data only stays between your server and your client (your smartphone, your desktop/laptop).
  • The dopamine rush you get from creating something from scratch and using it everyday and maybe even sharing it with your friends and family.
  • Basically this quote:
    “If you want to get something done right, you have to do it yourself”

Why am I using a pi?
Again, multiple reasons as follows:

  • Cost: The latest model of the Raspberry Pi costs ~$35 (might be slight variations depending on where you live) which is really low as compared to the super high cost of computers which are typically used for these purposes.
  • Portability: It’s one of the smallest all purpose computing devices which you can buy and use for your server needs. It’s the size of a credit card and you can carry it in your pocket wherever you go!
  • Open source OS: I can write another full post about this but basically the OS for RPi is based on the Linux kernel which is completely open source. There is a Linux distro called Raspbian which is built specifically for the Raspberry Pi and works really well. Anyone even remotely familiar with Linux (or even new to it) can find themselves at home with it and apart from this, there are other, more popular Linux distros like Ubuntu, Kali, Kodi, OSMC etc. which again, are built by the respective organisations and contributors for this beautiful computing board. I will be using Ubuntu server and Raspbian for my projects because I’m comfortable with Debian based systems but you can go for other distros as well and most of the things in my guide should work (apart from maybe some terminal command differences) regardless of what distro you decide to go with.

Why don’t I just use Adblock+ or Ublock Origin instead of this?
Because you have to install either a browser extension or an app and even if you do that, it will only work for that particular browser or device.
What this server does is, create a network wide ad-blocking service which will block ads/websites on ANY device/browser using your network/router without installing any third party app or extension which also means that your data is not going through or being logged by anyone else.


I have no deadlines for this. My day job doesn’t give me a lot of free time so I will be writing whenever a milestone is completed.


I’m currently working as a data analyst at Google and I have over 5 years of experience working in analytics and I have a degree in electrical and electronics engineering.
I love tinkering and building stuff in my free time, hence this project.

That’s it for part 1 of this series. The next post will be about setting up your Raspberry Pi, so stay tuned!

Also, I’m really new to this so if there are any experts reading this, constructive feedback is always welcome!