Background
Right. I was googling about ideas for how to do a system-wide ad-block, and realised that it could probably be used to filter other things from the net as well. As is nearly always the case with these things, someone has already done all of the hard work, and all we need to do is assemble the right pieces of the jigsaw. I’m basing this on an Orange Pi computer, but it should be easily adaptable if you want to use a Raspberry Pi instead.
To get how all of this works, you need to have a basic understanding how your network works at home. Fortunately it isn’t that complicated, and if you use some familiar concepts as analogies (phone numbers and phone books) it’s easy to grasp. I’m going to write this from a perspective of getting the filtering up and running on a simple home network that has a modem/router and a few devices connected to it, via Ethernet and Wifi.
Oh, and for now I will assume a Windows based environment for setting all of this up. The only thing that is different, though, is that on Mac or Linux you don’t need Win32DiskImager or Putty – there are commands available natively (dd and ssh) that do the same thing.
IP Addresses
Think of an IP address as your device’s phone number. Your device can either have its IP address assigned automatically (usually by your router) by something called DHCP, or you can assign an IP address manually. When you assign an IP address manually you have to specify at least four things for your internet to work. The address, the netmask (let’s not get in to this right now!), the gateway address (the IP of your router), and the IP address of your DNS server (this is where the magic is going to happen a bit later!).
DHCP
I don’t think there’s any benefit in going in to detail about DHCP beyond the fact that it’s what hands out your IP addresses with all of the correct details automatically. The DHCP server keeps track of all the devices that have been given an IP address, when that happened, and the name of the device. It does all this based on MAC addresses. You don’t really need to know anything about MAC addresses other than that they’re supposed to be unique for every networking device that has ever been made and will be made. MAC addressing is a 48-bit space, so there are 281,474,976,710,656 possible MAC addresses. Should last a while.
DNS
Right. This is where the magic that ties together the whole Internet happens. Without DNS, we probably wouldn’t have the modern Internet. Think of DNS like a big, dynamic phone book. Every site on the Internet that you can get to has an IP address. But remembering IP addresses is difficult. It’s way easier to have a phone book where you can look up the IP address of bitterswede.com and get the answer 103.9.170.230. And because of some smart people in 1984, DNS happens automatically and quietly in the background for you.
I probably need some sort of tangent warning. Maybe italics to signify things you can skip. There aren’t many IPv4 addresses left – there were only 4,294,967,296 in the first place, give or take. Thanks to DNS, we can have multiple websites sharing the same IP address. So while, this website points to 103.9.170.230, so do many others. There are some smarts in the server that looks at the domain name that’s been entered, and then shunts the user to the right web page on the server.