Table of Contents
Pi-hole on Synology
Pi-hole is an ad-blocking DNS server for internal networks. It is available on http://www.pi-hole.net. There is no Synology package available at this time, so it needs to be installed via Debian chroot environment. This guide is adapted from https://discourse.pi-hole.net/t/how-do-i-install-pi-hole-on-a-synology-nas/
Debian chroot
Add the Synocommunity package source via DSM and install Debian chroot:
Add source: Package Center > Settings > Package Sources > add: http://packages.synocommunity.com/ In Package Center > Community > Install Debian Chroot
Open a terminal/use putty, ssh to your NAS
On the command line, make sure you are root.
sudo su -
Login with your admin password.
/var/packages/debian-chroot/scripts/start-stop-status start /var/packages/debian-chroot/scripts/start-stop-status chroot
You may receive a locale error, can be ignored - the prompt should have changed.
Now you are on the chroot prompt, which enables you to install many packages that are available for Debian.
After installing chroot and entering it, run ps aux and if you see the following processes…
root 30894 0.0 0.2 3040 560 ? S 08:25 0:00 /bin/sh /var/packages/debian-chroot/scripts/postinst root 30896 0.0 0.2 1552 620 ? S 08:25 0:00 /bin/sh /debootstrap/debootstrap --second-stage
You should probably wait until they're complete to ensure your new chroot environment is consistent. This might take about 5-10 minutes.
Enter one by one:
apt-get update apt-get upgrade apt-get install locales sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen && locale-gen
This may take a while (5-10 minutes depending on CPU speed)
dpkg-reconfigure tzdata apt-get install curl mount /proc cat /proc/mounts > /etc/mtab
This is to fix a filesystem issue.
Install Pi-hole
apt-get install lighttpd
Port 80 is already in use, so modify lighttpd config:
curl -L https://install.pi-hole.net | bash
Just follow the steps…
change admin password if desired:
pihole -a -p
vi /etc/lighttpd/lighttpd.conf
modify server.port = xxxx to a suitable port (higher than 1023)
crontab /etc/cron.d/pihole crontab -l
Verify that you see several entries for pihole.
service cron restart service lighttpd restart
This will restart the webserver and cron with the new config.
Now you should be able to access it with your browser on http://ip:port/admin/
If you see the admin page of Pi-hole you can modify your devices: change the DNS IP address to the NAS IP.
Autostart after reboot
As nothing in chroot is started automatically we need to make a startup script that survives a reboot:
exit (from chroot - should still be root)
Create an RC script (this file assumes that you use /volume1):
vi /usr/local/etc/rc.d/S99pihole.sh
- /usr/local/etc/rc.d/S99pihole.sh
#!/bin/sh . /etc.defaults/rc.subr case $1 in start) /var/packages/debian-chroot/scripts/start-stop-status start chroot /volume1/@appstore/debian-chroot/var/chroottarget service cron start chroot /volume1/@appstore/debian-chroot/var/chroottarget service lighttpd start chroot /volume1/@appstore/debian-chroot/var/chroottarget service pihole-FTL start ;; stop) chroot /volume1/@appstore/debian-chroot/var/chroottarget service cron stop chroot /volume1/@appstore/debian-chroot/var/chroottarget service lighttpd stop chroot /volume1/@appstore/debian-chroot/var/chroottarget service pihole-FTL stop /var/packages/debian-chroot/scripts/start-stop-status stop ;; restart) $0 stop sleep 1 $0 start ;; *) echo "Usage: $0 start|stop|restart" ;; esac
chmod +x /usr/local/etc/rc.d/S99pihole.sh
Test the script:
/usr/local/etc/rc.d/S99pihole.sh restart
If succesful, pi-hole and all the services should automatically start after a reboot.
To get into chroot from your dsm you can use /var/packages/debian-chroot/scripts/start-stop-status chroot
or to enable ssh in chroot, follow this blog post: https://markpith.wordpress.com/2015/10/26/debian-chroot-on-synology-nas/
If you are using dhcp in your network, configure your router to use the DNS on your NAS.
Update Pi-hole
from chroot:
#Log into Chroot sudo /var/packages/debian-chroot/scripts/start-stop-status chroot #Regular update fails on synology due to not being able to check disk space, use override option 'do not follow recommendations' instead. #pihole -up curl -L https://install.pi-hole.net | bash /dev/stdin --i_do_not_follow_recommendations #change the webserver port again: #vi /etc/lighttpd/lighttpd.conf - change the port sed -i 's/server.port\(.*\)= 80/server.port\1= 2080/g' /etc/lighttpd/lighttpd.conf service lighttpd restart service pihole-FTL restart #leave chroot exit #update might require: cd /etc/.pihole git pull
to reconfigure pihole's main details, use:
pihole -r service pihole-FTL restart