I use this on Ubuntu 16.04, but as long as your systemd is recent enough, I don't see why this should not work for you.
- Set your IP address to a static one, using e.g. NetworkManager or by editing
/etc/network/interfaces
. Set127.0.0.1
as your DNS server. - Write the
/etc/systemd/system/pihole.service
file below. - Start and enable ("install") the systemd unit file by typing
sudo systemctl start pihole.service
andsudo systemctl enable pihole.service
. - Configure your other devices to use your computer's now static IP address as their DNS server.
Here's what you should put in /etc/systemd/system/pihole.service
:
[Unit]
Description=Pi-Hole Ad muncher
After=docker.service
[Service]
ExecStartPre=-/usr/bin/docker rm --force pihole
ExecStartPre=-/usr/bin/docker pull diginc/pi-hole:alpine
ExecStartPre=/bin/bash -c "/bin/systemctl set-environment IP=$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')"
ExecStartPre=/bin/bash -c "/bin/systemctl set-environment IPv6=$(ip -6 route get 2001:4860:4860::8888 | awk '{ print $10; exit }')"
ExecStartPre=/bin/mkdir -p /var/lib/pihole/config
ExecStartPre=/bin/mkdir -p /var/lib/pihole/dnsmasq.d
ExecStart=/usr/bin/docker run --name pihole -p 53:53/tcp -p 53:53/udp -p 80:80 -v "/var/lib/pihole/config:/etc/pihole/" -v "/var/lib/pihole/dnsmasq.d/:/etc/dnsmasq.d/" -e ServerIP="${IP}" -e ServerIPv6="${IPv6}" -e DNS1=9.9.9.9 -e DNS2=9.9.9.9 diginc/pi-hole:alpine
Restart=always
RemainAfterExit=no
RestartSec=10s
[Install]
WantedBy=multi-user.target
I have configured this to use the Quad 9 DNS servers instead of Google's, since Google is tracking us enough as it is. If you would rather have Google handle your DNS queries, by all means, just remove -e DNS1=9.9.9.9 -e DNS2=9.9.9.9
from the unit file. It will default to using Google's DNS service.
Thank you to the team behind Pi-hole (@pi-hole), and to the team behind the Docker version (@diginc).