Over the years, as the technologies have advanced, so has the online businesses. There are new marketing strategies in place to make businesses bloom. One such marketing strategy is to pick up the information stored on your browsers’ storage and show relevant ads. For people who are more concerned about their online privacy, these ads are a no go for them. Many use adblocker plugins built into the browsers or use a covert network such as tor to not let these ads retrieve any pieces of information. But this is only limited to browsers. What about the ads that we see on every other mobile app? The ones that suddenly pops-up while playing a game or using a freeware app. Though I am not against having these ads as it is a way of making money for the businesses, for the folks who are more concerned about their online privacy, there is the solution that I shall be discussing in this blog post. It is called Pi-Hole.
Now, there are multiple ways to do this. You can either install it on your own computer if you are using Linux or a small raspberry Pi system. Most routers won’t support setting your Primary and Secondary DNS for the internet settings to a private IP address in the same LAN as the router. If you need to set this up to configure on your router, then you can use a public server from a hosting provider that has Linux host such as Amazon EC2, Azure Virtual Machine, or any other private hosting providers. This might incur an additional cost for running these servers online. Please ensure to check the cost associated with the servers before running it online.
In this tutorial, I would demonstrate how to set this up on Raspberry Pi. Make sure you have the latest Raspbian OS installed and updated on your Raspberry Pi. An ethernet connection from Raspberry Pi to your Router is preferred, as this would require you to configure a static IP address to your Raspberry Pi. Setting a static IP address is out of scope for this tutorial, but you follow this guide to set a static IP address to your Raspberry Pi.
The steps to set-up Pi-Hole is as below.
Step 1: Login via SSH or directly to Raspberry Pi, if it has Monitor, Keyboard, and Mouse connected. Open terminal if logged in directly to the Pi. In your bash prompt on terminal or SSH session, run the below command.
$: curl -sSL https://install.pi-hole.net | bash
Step 2: Go through the installation and you will be prompted with multiple questions. Select the default options in the majority of them. For selecting DNS, you can select DNS from the provided list or add a custom DNS provided by your ISP by selecting the “Custom” at the end of the list. These are the upstream DNS servers that Pi-Hole shall use to resolve the IP addresses for the domains. Once, your DNS is set up, the setup will prompt you if you need to enable a web admin interface, select “Yes”, and do the same for the “Lighttpd” installation. Once the setup is complete, the setup will show you an auto-generated password for your web-based admin panel login. Make sure you make a note of it. It will look something like shown in the figure below.
Step 3: To change the auto-generated password, you can use the below-mentioned command and use the newly set password for web console login.
$: sudo pihole -a -p
Step 4: Now the Pi-Hole is configured, but is not blocking any ads since it is not configured to be used as a DNS. Change the primary DNS in each of your devices where you need to block the ads with the IP of your raspberry pi as illustrated in the screenshot below.
Now, you can enjoy all the apps without any ads. This is very effective, though it might not completely remove all the ads as it fetches the list of blacklisted domains from multiple sources. In my future blog, I will show you how you can block ads that are not part of the blacklist domain. You can browse web console and view the statistics for Pi-Hole.
That was as simple as that. Now, if you don’t want to enter DNS servers in each of your devices and manage it from the router itself, you will need to perform the above steps on an external server such as Amazon EC2 instance, Azure Virtual Machine, or any other third party hosted server. Ensure to set an appropriate DNS server on your external server setup. The best option is to select one from the list provided instead of having a custom DNS server in the hosted environment setup. In your router Internet settings, you will need to change the DNS server to the IP address of your own server and then you can skip Step 4 as it will implement this over the entire network. With Pi-Hole, you can even add custom DNS entries for your own systems.
I hope this blog post was helpful. Please comment and let me know if this works for you.