Below is a step-by-step guide on installing AdGuard on Ubuntu with LetsEncrypt HTTPS encryption. We will also implement AdGuard-Sync to enable the syncing of two different AdGuard servers so that only one has to be updated. Portainer will be installed for the monitoring and management of AdGuard-Sync so we can see if we have any issues.
Install AdGuard
curl -sSL https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh
Create New Resolve Configuration to Use AdGuard
sudo mkdir /etc/systemd/resolved.conf.d
sudo nano /etc/systemd/resolved.conf.d/adguardhome.conf
Edit adguardhome.conf to only have the below line.
[Resolve]
DNS=127.0.0.1
DNSStubListener=no
Move resolve.conf and restart systemd
sudo mv /etc/resolv.conf /etc/resolv.conf.backup
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
sudo systemctl reload-or-restart systemd-resolved
Now AdGuard is working and ready to use except we want to add a few more tools. If your going to use AdGuard-Sync go ahead and repeat the above steps to create a second server that will become our secondary DNS.
Let’s Install Docker (Only on Primary DNS)
Install Prerequisites
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
Install Docker’s GPG Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Selection of Docker’s Stable Repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Install Certbot (Repeat on both DNS Servers)
sudo apt install certbot
Certify with LetsEncrypt
sudo certbot certonly --agree-tos --manual --preferred-challenges=dns -d domain.yourdomain.com
sudo certbot certonly --agree-tos --manual --preferred-challenges=dns -d domain2.yourdomain.com
Install Docker Compose on Primary DNS
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Run Compose for Portainer on Primary DNS
Create Portainer Data Volume on Primary DNS
sudo docker volume create portainer_data
Run Portainer on Primary DNS
sudo docker run -d -p 8000:8000 -p 9443:9443 --name portainer \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
cr.portainer.io/portainer/portainer-ce:2.9.3
Create Docker-Compose for AdGuard-Sync on Primary DNS
---
version: "2.1"
services:
adguardhome-sync:
image: quay.io/bakito/adguardhome-sync
container_name: adguardhome-sync
command: run
environment:
- ORIGIN_URL=http://IP.Of.Server:80
- ORIGIN_USERNAME=AdGuard-Username
- ORIGIN_PASSWORD=AdGuard-Password
- REPLICA_URL=http://IP.Of.Server:80
- REPLICA_USERNAME=AdGuard-Username
- REPLICA_PASSWORD=AdGuard-Password
- CRON=*/1 * * * * # run every 1 minutes
- RUNONSTART=true
- FEATURES_GENERALSETTINGS=true
- FEATURES_QUERYLOGCONFIG=true
- FEATURES_STATSCONFIG=true
- FEATURES_CLIENTSETTINGS=true
- FEATURES_SERVICES=true
- FEATURES_FILTERS=true
- FEATURES_DNS_SERVERCONFIG=true
- FEATURES_DNS_ACCESSLISTS=true
- FEATURES_DNS_REWRITES=true
ports:
- 8080:8080
restart: unless-stopped
Enable Compose for AdGuard-Sync
docker-compose up -d
Verify logs in portainer to make sure adguard-sync is properly configured and working.