AdGuard Home DNS-block

AdGuard Home is a network-level program designed to block ads and trackers. It's an alternative to Pi-hole, and is more polished and stable, and it's also much easier to install than Pi-hole.

AdGuard Home is a network-level program designed to block ads and trackers. After configuring it, it will work on ALL devices on the network, without needing to install any additional software in each device. With the rise of IoT (Internet of Things) and the number of connected devices, it becomes more essential to control all the network.

AdGuard is similar to another ad and tracker blocker called PiHole, and they have the same function. I've used both, and AdGuard is simply much easier to install and configure. Further, the webpage to control the configuration is much more polished and fast. As there's a company behind this product, it's more stable and comes as one package, contrary to PiHole, which installs many programs.

curl -s -S -L https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh -s -- -v

The program resides in: /opt/AdGuardHome/AdGuardHome

We create a user to run adguard: useradd adguard; groupadd adguard; usermod -aG adguard adguard

and do a chown -R adguard:adguard /opt/AdGuardHome/AdGuardHome

Also we give it permission to use the necessary port 53 for DNS: sudo setcap 'CAP_NET_BIND_SERVICE=+eip CAP_NET_RAW=+eip' /opt/AdGuardHome/AdGuardHome

It's possible to start Adguard manually just running/executing the program, but it's better to create a service. For those who use Runit, use the following script:

/etc/sv/adguard/run:

#!/bin/sh
exec 2>&1
exec chpst -u adguard:adguard /opt/AdGuardHome/AdGuardHome

/etc/sv/adguard/stop:

#!/bin/sh

exec chpst -u adguard:adguard /opt/AdGuardHome/AdGuardHome -s stop

/etc/sv/adguard/log/run: (if you have installed the services from cloux): ln -s -t . ../../svlogd/run If not, you can use the following:

#!/bin/sh
##Copyright: Cloux <cloux@rote.ch>
##License: CC0/Public Domain
##Comment: adapted from https://github.com/cloux/runit-base
exec 2>&1

# Get service name (the upper directory name)
UPDIR=$(dirname $PWD)
SERVICE=${UPDIR##*/}
RUNITLOG=/var/log/runit
LOGDIR=$RUNITLOG/$SERVICE
BUFFER=2048
LOGUSER=_runit-log

#Read conf file
if [ -r ./conf ]; then
    . ./conf
fi
if [ -r /etc/sv/svlogd/conf ] && [ ! -r ./conf ]; then
      . /etc/sv/svlogd/conf
fi

[ ! -d "$LOGDIR" ] && install -m 750 -o $LOGUSER -g adm -d "$LOGDIR"
if [ ! -e "$LOGDIR/.pkg"  ] && [ -e "$UPDIR/.meta/pkg" ]; then
	cp "$UPDIR/.meta/pkg" "$LOGDIR/.pkg"
fi

# manage svlogd config file
if [ -f "$PWD"/log.config ]; then
  install -Tm 0644 -o $LOGUSER "$PWD"/log.config "$LOGDIR"/config
fi
if [ -f /etc/sv/svlogd/log.config ] && [ ! -f "$PWD"/log.config ]; then
  install -Tm 0644 -o $LOGUSER /etc/sv/svlogd/log.config "$LOGDIR"/config
fi

exec chpst -u ${LOGUSER} svlogd -tt -b $BUFFER "$LOGDIR"