Baking a pie to block ads
By: Vatsal Mishra
Tags: Raspberry Pi, Adblock, DNS, Computers, Servers

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

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

What?

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 Google.com? 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

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?

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

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)

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)

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

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:

No more pesky, annoying ads 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!