This time I show how you can run an ad-blocker locally with Docker.

Background

The project Docker Pi-hole, part of the Pi-hole project, contains some examples how you can start a local DNS server that blocks any host request which is part of a blacklist.

This blacklist contains entries for hosts that are generally used for advertising or spam.

Given the massive quantity of these hosts, it is almost impossible to keep track of all.

Additionally, they generate approximately 20% to 30% additional traffic, making the loading of web pages slower and may pose data privacy issues from a legal standpoint under certain circumstances.

Setup Ad-Blocker

The following example is based on official docker-compose.yml.example file and is a very simplified version of it:

services:
  pihole:
    image: pihole/pihole:latest
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "5979:80/tcp"
    environment:
      TZ: 'Europe/Berlin'
      WEBPASSWORD: 'My_SECRET-P@ssword1234!#'
    volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
    restart: unless-stopped

Save this content to a docker-compose.yml file at a location of your choice and run

docker-compose up -d

from this location. This will start and run the ad-blocker in background.

After this Docker image has been boot up you should be able to access the web interface via http://localhost:5979/admin/ using the password defined with WEBPASSWORD.

Setup DNS servers

The following subsections describe how to adjust the DNS settings of an operating system so that they apply globally for all applications using these settings. This is why you have to keep in mind, that some application like Chrome-like browsers use their own settings!

VERY IMPORTANT: Remember your current settings in order to restore them if access does not work anymore!

Windows

  • open Control Panel
  • open Network and Sharing Center
  • choose the connection(s) which give you access to the Internet
  • open adapter settings
  • choose Internet Protocol Version 4 (TCP/IPv4)
  • choose Use the following DNS server addresses
  • set Preferred DNS server to 127.0.0.1
  • (optional) if you want you can set Alternate DNS server to one of these servers:
    • 208.67.222.222 (OpenDNS)
    • 208.67.220.220 (OpenDNS)
    • 1.1.1.1 (Cloudfare)
    • 1.0.0.1 (Cloudfare)
    • 8.8.8.8 (Google)
    • 8.8.4.4 (Google)

MacOS

Follow this official support page by Apple to update your DNS settings.

Add the following entries:

  • primary (required) entry: 127.0.0.1
  • additional (optional):
    • 208.67.222.222 (OpenDNS)
    • 208.67.220.220 (OpenDNS)
    • 1.1.1.1 (Cloudfare)
    • 1.0.0.1 (Cloudfare)
    • 8.8.8.8 (Google)
    • 8.8.4.4 (Google)

Linux

The following might work on most and common Debian distributions like Ubuntu:

  • open /etc/resolvconf/resolv.conf.d/head with an editor like vi or nano
  • add at least 127.0.0.1 entry
  • (optional) if you want you can add one of these additional servers:
    • 208.67.222.222 (OpenDNS)
    • 208.67.220.220 (OpenDNS)
    • 1.1.1.1 (Cloudfare)
    • 1.0.0.1 (Cloudfare)
    • 8.8.8.8 (Google)
    • 8.8.4.4 (Google)
  • save the new content
  • execute sudo resolvconf --enable-updates
  • execute sudo resolvconf -u
  • check /etc/resolv.conf file if new entries have been loaded

Test it out

Now open a website of your choice and have a look at the statistics if your settings are working.

Conclusion

You see, you do not need a Raspberry Pi for cool and useful features 😊

If you like the project, you can support it of course.

Have fun trying it out! 🎉