Skip to main content
Adguard on a Pi

Adguard on a Pi

·777 words·4 mins
Neelakantan C A
Author
Neelakantan C A
Table of Contents

In a recent post, we setup docker on a Raspberry Pi. In this post, we will look into how we can use docker to run a few nice to have services, at home in a quick and easy manner.

Docker Containers & Images
#

Docker containers are an entire application packaged to be run in an isolated environment. A docker image is in a way, like the blueprint to build a container (ie) using one image we could deploy multiple different containers running the same service.

Now this is all fine and dandy, however we now have a problem, where do we get these docker images ?

Well that’s easy, a whole bunch of images can be found on this site hosted by Docker.

To get these images onto our computer we can run the following command in the terminal:

docker pull <image name>

To get rid of any image we not longer want, we run the command:

docker rmi <image name>
Please by aware that starting a container requires the image for that container to be present.

Once we have are image, we can create a container from it by running the command:

docker run <options> <image name>

Setting up Adguard
#

Before we run any commands or set anything up, we need to understand what exactly we are doing.

The first and major question would be what is adguard and why should we set it up ?

What is Adguard ?
#

Adguard is an opensource DNS sinkhole hosted on Github. Now that explains everything and nothing depending on your networking knowledge, so let me explain what a DNS sinkhole is.

To do this we must first understand a small amount of networking, so grab a notebook and follow along.

Every device connected to the internet has an address the same way every house an address. So if your computer needs to connect to https://blog.reith77.tk, your computer needs the address of the server on which the website is hosted (running).

Now unlike the human addressing system, computers use IP address. An IP address is a set of 4 numbers from 0-255 split by a ’ . '

So an example IP address would be 192.168.1.1

Since IP addresses often change and are bought and sold commercially, we can’t hard code the address of every website or service we would like to access, nor is it practical to connect to a website by typing in a IP address.

To get around this, Domain Name System (DNS) was introduced. DNS basically convert between hostnames (Eg: https://www.google.com ) and their IP addresses.

So when a computer wants to connect to a website and doesn’t know it’s IP address, it contacts a DNS server, generally hosted on port 53 (this will be important later), and gets the address for that website and establishes a conncetion.

So we’ve figured out what DNS is, but what is a DNS sinkhole ? A DNS sinkhole is basically a blackhole for DNS queries. Let’s assume that we don’t want anyone to connect to https://youtube.com. Well whenever a DNS request for youtube is made, we could send them to an address like 0.0.0.0, now since youtube clearly doesn’t live at this address, no computer using your DNS will be able to connect.

Installing Adguard
#

To install adguard we will obviously be using docker.

We will first require the docker image for adguard home.

docker pull adguard/adguardhome

Once we have our image we can create a folder on our raspberry pi, for all our adguard related files (Ex: ~/Adguard).

Within this folder, we need to create a file named docker-compose.yml and copy paste the following contents into the file.

services:
  adguard:
    container_name: Adguard
    restart: unless-stopped
    image: adguard/adguardhome
    volumes:
      - ./work:/opt/adguardhome/work
      - ./conf:/opt/adguardhome/conf
    ports: 
      - 53:53/tcp
      - 53:53/udp
      - 80:80/tcp
      - 443:443/tcp
      - 443:443/udp
      - 3000:3000/tcp

Once we have this file created, we need to ensure we run the command in the same directory or folder which that file is is.

The first command run below may vary for you depending on what folder you decided to use. Once you have opened the terminal in the proper folder, the second command can be run.
cd ~/Adgaurd
docker-compose up -d

This should have started the adguard server, and you should now be able to access the dashboard for adguard at http://<YOUR RASPBERRY PI ADDRESS>:80. To learn more about how to configure Adguard checkout this wiki

If you would like to stop running adguard at any point, all we need to do is open a terminal at the same folder and run the following command

docker-compose down

Have fun and let me know how it goes !!!