# AdGuard Home

Great for blocking ads, icky stuff, inappropriate sites, etc.

## Install (Docker)
[This guide](https://hub.docker.com/r/adguard/adguardhome) does a pretty good job.  I've found good luck installing [Ubuntu Desktop](https://ubuntu.com/download/desktop) and then installing Docker using [these instructions](https://docs.docker.com/engine/install/ubuntu/).  At the time of writing, this was what we had to do:

Setup apt repo:

```
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
```

Install the stuff:
```
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y 
```

Test docker:
```
sudo docker run hello-world
```

## Run the AdGuard image
The install instructions will have you run something like this:

```
sudo docker run --name adguardhome\
    --restart unless-stopped\
    -v /my/own/workdir:/opt/adguardhome/work\
    -v /my/own/confdir:/opt/adguardhome/conf\
    -p 53:53/tcp -p 53:53/udp\
    -p 67:67/udp -p 68:68/udp\
    -p 80:80/tcp -p 443:443/tcp -p 443:443/udp -p 3000:3000/tcp\
    -p 853:853/tcp\
    -p 784:784/udp -p 853:853/udp -p 8853:8853/udp\
    -p 5443:5443/tcp -p 5443:5443/udp\
    -d adguard/adguardhome
```

For me, that caused this error:

```
docker: Error response from daemon: driver failed programming external connectivity on endpoint adguardhome (9473a90859399240342605cd1b24908bc4e3d422775f1ca376742d2bb6004b6b): failed to bind port 0.0.0.0:53/tcp: Error starting userland proxy: listen tcp4 0.0.0.0:53: bind: address already in use.
```

Googling that might take you to [this guide](https://github.com/AdguardTeam/AdGuardHome/wiki/FAQ#bindinuse) which actually says it's out of date and so you should go to [this KB](https://adguard-dns.io/kb/adguard-home/faq/#bindinuse) for the fix.  Read through that site for the most up to date information, but I'm just going to shortcut the commands for my own sake below.

Check if `systemd-resolved` is tying up port 53:

```
sudo lsof -i :53
```

You'll probably get:

```
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 14542 systemd-resolve 13u IPv4 86178 0t0 UDP 127.0.0.53:domain
systemd-r 14542 systemd-resolve 14u IPv4 86179 0t0 TCP 127.0.0.53:domain
```

Create this directory:

```
sudo mkdir -p /etc/systemd/resolved.conf.d
```

Deactivate `DNSStubListener`
```
sudo nano /etc/systemd/resolved.conf.d/adguardhome.conf
```

Put this content in that file:
```
[Resolve]
DNS=127.0.0.1
DNSStubListener=no
```

Add another `resolv.conf` file:

```
sudo mv /etc/resolv.conf /etc/resolv.conf.backup
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
```

Restart `DNSStubListener`:
```
sudo systemctl reload-or-restart systemd-resolved
```

Check if `systemd-resolved` is tying up port 53 - it *should not be now*:

```
sudo lsof -i :53
```

Then when you run the docker again you'll probably get:

```
sudo docker run --name adguardhome    --restart unless-stopped    -v /my/own/workdir:/opt/adguardhome/work    -v /my/own/confdir:/opt/adguardhome/conf    -p 53:53/tcp -p 53:53/udp    -p 67:67/udp -p 68:68/udp    -p 80:80/tcp -p 443:443/tcp -p 443:443/udp -p 3000:3000/tcp    -p 853:853/tcp    -p 784:784/udp -p 853:853/udp -p 8853:8853/udp    -p 5443:5443/tcp -p 5443:5443/udp    -d adguard/adguardhome
docker: Error response from daemon: Conflict. The container name "/adguardhome" is already in use by container "00f30d7f1b3ae422186519df0aba1211ab5d3a1aa95384732bbea6a419e4a597". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
```

So remove the container:

```
# stop if needed
# sudo docker stop adguardhome

# Then remove
sudo docker rm adguardhome
```

:::warning
This next "fix" is only if you DON'T want your AdGuard to be a DHCP server
:::

Run the Docker minus the DHCP service (port 68):

```
sudo docker run --name adguardhome \
    --restart unless-stopped \
    -v /my/own/workdir:/opt/adguardhome/work \
    -v /my/own/confdir:/opt/adguardhome/conf \
    -p 53:53/tcp -p 53:53/udp \
    -p 67:67/udp \
    -p 80:80/tcp -p 443:443/tcp -p 443:443/udp -p 3000:3000/tcp \
    -p 853:853/tcp \
    -p 784:784/udp -p 853:853/udp -p 8853:8853/udp \
    -p 5443:5443/tcp -p 5443:5443/udp \
    -d adguard/adguardhome
```
