PiHole - Docker NAS Setup
Tags: synology, docker, nas, tutorial
Published: 2021-01-29 16:08:32

---
title: PiHole - Docker NAS Setup
published: true
date: 29/01/2021
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/u64of5z6jc5jrfmgclin.png
tags: synology,docker,nas,tutorial
canonical_url: https://chrisotto.dev/pihole-docker-nas/
series: Synology NAS Setup
---

Pi-hole is an awesome tool that let’s you block certain requests on your home network from devices. The way that Pi-hole does this by either hosting it on a Raspberry Pi or hosted on a machine on your network through Docker. Once that is done you set the IP address of the Pi-hole as your DNS server or if you can’t modify your DNS server due ISP restrictions you can set it as your DHCP server. This guide we’ll walk through setting up Pi-hole through Docker on a Synology NAS.

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#prerequisites-)Prerequisites 📃

- Download Docker from Package Center
  - In DSM head over to Package Center
  - Search for Docker
  - Install

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#create-folder-structure-)Create Folder Structure 📂

In DSM, open up the File Station:

- Installing docker creates a `docker` folder at the root of your volume
- Create a new folder in the `docker` folder for Portainer
  - I always create the folder based on the name of the image/container I’m setting up, in this case `pihole`
- In the `pihole` directory create two new folders `pihole` and `dnsmasq.d`
  - These folders will get mounted as volumes for the docker container later on

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#downloading-and-configuring-the-image-)Downloading and Configuring the Image 🚢

Open on `Docker` on your NAS. In the `Registry` tab search for pihole. The image that we’re looking for is the official Pi-hole image, `pihole/pihole`. Select the image and select Download or just double click it. Once the image has finished downloading, head on over to the `Images` tab and click Launch or again double click it.

Now you should be in the `Create Container` pop-over:

- Enter the container name, `pihole`
- Enable `Execute container using high privileges`
- Click Advanced Settings

In the `Advanced Settings` main tab:

- Enable `Enable auto-restart`

In the `Volume` tab, we’re going to add the folders we created to the volumes for container, make you match the mount path below:

| File/Folder | Mount Path |
| --- | --- |
| docker/pihole/dnsmasq.d | /etc/dnsmasq.d |
| docker/pihole/pihole | /etc/pihole |

  
In the `Network` tab:
- Enable `Use the same network as Docker Host`

Finally, in the `Environment` tab we need to set/change some of the default environment variables that come with the image. You’ll need to come up with a password for the web interface and that will get set for one of the variables. Also, decide on what port you want this to run on, the default is `8080` so if you have another application using that port pick a new one. Lastly, we’ll need to set one of variables to the IP address of your Synology NAS or IP address of where ever you are running the container:

| Variable | Value |
| --- | --- |
| WEBPASSWORD | [Create a password] |
| DNSMASQ\_LISTENING | local |
| WEB\_PORT | 8080 |
| ServerIP | [NAS IP or Machine IP] |

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#launch-the-container-)Launch the Container 🚀

With everything configured you’re now ready to click `Apply` and launch your new Pi-hole container. Once the container has started, head on over to `http://[YOUR IP ADDRESS]:[YOUR PORT]/admin`. You’ll need to login with the password that we set as the environment variables earlier.

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#router-changes-)Router Changes 📶

Pi-hole is running and ready to block traffic on your network, but you won’t see anything on the admin dashboard until you make the necessary changes to your router. This process is very specific to which router you have so I won’t detail it here as it will most likely be different for everyone. But login into your router and change the IP address of your DNS server to the IP address of your NAS. If you are not able to modify your DNS, then you can set Pi-hole to be your DHCP server.

One thing I have noticed with having the Pi-hole set as my DNS server on my router is that I only log traffic for one device. The router. Which makes sense because all traffic is coming to Pi-hole from the router. One way you could get more detailed information per device is using DHCP or individually changing the DNS per device on your network to the Pi-hole. I don’t really mind not seeing device specific statistics, so I left it as-is.

I hope you enjoyed this little guide and happy blocking, cheers! 🍻