M.D.Risser

Blocking Ads While Tethered

If you’ve ever used your cell phone to give your laptop an internet connection (a.k.a. tethering), then you know how valuable bandwidth is. Exceed that bandwidth and your facing additional charges for you cell phone plan. So how do you maximize your bandwidth? One of the simplest ways is to block ads on the sites that you visit.

Now I know that some sites display ads to keep the site running, and that’s all well and good. But you need to mind your budget as well.

You could block ads using browser extensions, but many sites are now detecting those extensions and demanding that you turn off the extensions to visit their site. Fine, but now your sucking up precious bandwidth pulling down ads. So, how do you get around this?

The answer is surprisingly simple. you need a Pi-Hole. Pi-Hole is a DNS sinkhole, or blackhole, the purpose of which is to block ads. And it doesn’t require any browser extensions or client-side software.

What happens is, basically, when your browser processes a page you are visiting and it encounters an ad, the ad has a URL directing the browser where to go to pull down the ad content. This URL usually contains a hostname, and your computer needs to know where to go (resolve the hostname) to get that content.

To help make this a little more clear, let’s look at a very simplified example. For our example let’s call the hostname ad-server.foobar-ads.com.

When your computer is tethered to your phone it most likely gets its IP address via DHCP, (Dynamic Host Configuration protocol), in addition to the IP address it is given other information, including where to send queries about hostnames (nameservers).

Your computer, not knowing the IP address for ad-server.foobar-ads.com, sends out a DNS (Domain Name Service) request to its primary nameserver which basically says, “Where is ad-server.foobar-ads.com?” A DNS server (nameserver) then sends back a response saying, “ad-server.foobar-ads.com is at 1.1.1.1.” Armed with this information your computer can then request the content from ad-server.foobar-ads.com with an IP address of 1.1.1.1, and in the process use up some of your precious bandwidth. (There is a lot more that goes on, but that’s outside the scope of this post.)

How Pi-Hole works is simple. You simply point to a Pi-Hole server as your primary nameserver (let’s say your pi-hole server is at 192.168.100.100), so your computers query for ad-server.foobar-ads.com goes to it. Pi-Hole then looks through several lists of known adservers and domains. If it finds ad-server.foobar-ads.com in a list, it returns a response saying that ad-server.foobar-ads.com is at 192.168.100.100. And when your computer tries to get the ad content, nothing is returned, saving you some precious bandwidth. If the hostname queried is not in one of the lists, pi-hole then forwards your request on to another name server, which then sends the reply back to pi-hole, which in turn sends it back to your computer. (This is another simplified look at what happens, but, it suffices for our purposes here.)

Now, to save even more bandwidth, I’m going to show you how to run pi-hole on your own computer so that those requests don’t have to go out on to the internet, unless the hostname or domain name doesn’t appear in one of the lists.

Your going to need, a minimal Ubuntu Server (or any other Linux distribution of your choice), VirtualBox, and an internet connection. I’m not going to walk you through installing VirtualBox, creating a virtual machine or a Linux distro, there are plenty of great guides out there that do that already. In fact, you can find installation instructions for VirtualBox here, creating a virtual machine here, and installing Ubuntu Server here.

What I will tell you is that when you create your virtual machine, you only need about 1GB of memory (fig. 1) and maybe 32GB of hard drive, you could probably get away with less, but that’s how I have mine setup (fig. 2). You’ll also need two NICs in the VM, one set to NAT or Bridged (fig. 3), the second set to Host-Only (fig. 4).

Figure 1
Figure 2
Figure 3
Figure 4

Once you have VirtualBox installed, a VM created and a Linux distro installed on the VM, log into the VM, then on you computer go to https://pi-hole.net. The folks over there have been nice enough to create a nice installer for pi-hole, all you have to do is enter the command found on the homepage and let it do it’s thing (fig. 5).

Pi-Hole Homepage Screenshot
Figure 5

I do recommend running the command as root so that there are no permissions issues. You can do this either by modifying the command itself, or issuing the command

sudo su <enter>

(where <enter> means pressing the “Enter” key) and then running the command they give you. To modify the command you can do something like issuing the following command (fig. 6):

sudo curl -sSL https://install.pi-hole.net | sudo bash <enter>
Figure 6

Be sure to check the Pi-Hole homepage first, just incase the command changes.

Let the installer run its course (fig. 7), answering any questions that pop-up along the way (fig. 8).

Figure 7
Figure 8

And if you can, please consider donating to these fine folks (fig. 9).

Figure 9

A couple of notes, 1) mostly, the defaults are perfect including setting your DHCP address to static (fig. 10), 2) if you want to use your own nameservers, instead of selecting from the list (sorry, forgot to grab a screenshot), make sure you select “Custom” 3) I highly recommend that you install the web interface when prompted (fig. 11 & 12) write down the admin password the installer gives you (fig. 13), you’ll need it to login to the web interface (fig. 14) (but we haven’t gotten to that point yet).

Figure 10
Figure 11
Figure 12
Figure 13
Figure 14
Figure 15

Now we need to verify that everything is running as expected. We need to find out the IP address of the Host-Only NIC. On your Pi-Hole server, enter the command:

ip address

This will list, naturally, the IP addresses of your NICs (fig. 16).

Figure 16

If you’re not sure which NIC is your Host-Only NIC, there are a couple of ways to check. First, if you set up one of your NICs as NAT, try to browse to the IP addresses for your NICs, the one that you can reach is the Host-Only NIC. Second, if you set one of your NICs up as Bridged, it’s IP address will be in the same subnet as your computer. It is beyond the scope of this article to walk you through determining your computer’s IP address, and if you don’t know how, a quick search of the internet will turn up many links to help you out.

In my case, I know that enp0s8, the second NIC listed in fig. 16, is my Host-Only NIC. Make a note of the IP address of YOUR Host Only NIC, make sure everything is working by pointing your browser to that IP address/admin, in my case it would be http://10.0.50.101/admin. Once you’re sure you can connect, go into the settings for your computer, and over-ride the DHCP nameservers, setting your Host-Only NIC as your primary nameserver. Again, it is beyond the scope of this post to walk you through that if you don’t already know how, so DuckDuckGo it.

Now, the only caviat, is that you’ll need to make sure that this VM is running in order for it to block ads, but that’s simple enough to do.

That’s it, there you have it, you now shouldn’t see any ads on pages you visit, when the Pi-Hole VM is running, and you’ll save some of your precious tethering bandwidth in the process.

I hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top