Tutorial: Lancache combined with Pi-hole

Recommended Posts

Posted (edited)

My curiosity to look for further applications for my Xpenology NAS led me to lancache, which enables content (such as games, windows and mac updates) that was downloaded once from the Internet to be available locally (via my NAS) the second time and save internet bandwidth. Further information regarding lancache can be found here:

However, since I already have a Pihole (tracking and advertising blocker) in use, I had to find a way to let them communicate with each other. In order to save resources, I decided against operating the Lancache in a virtual machine and using docker. Therefore, below I share my approach for those who are interested.


ATTENTION, with this procedure the ports 80 and 443 in DSM are assigned to another port, since the two ports are required for the lancache. This means that if you host a website it will no longer be accessible via "" but in the future via "".

Furthermore, I do not accept any liability for any data loss or damage caused by using this tutorial(s).


So let's start.

First, ports 80 and 443 must be released. Thanks to Tony Lawrence's instructions (see, this is relatively easy.

  1. Connect to the NAS via SSH. In macOS you can do this via the terminal app with this line

    ssh -p portnumber username@IPadress

    for example 
  2. ssh -p 22 tim@
  3. Check which applications are currently using the port with the command
  4. sudo netstat -lntup | grep ":80"
  5. sudo netstat -lntup | grep ":443"
  6. Now three files have to be edited. The vi editor is used for this purpose 
  7. Enter the command
  8. sudo vi /usr/syno/share/nginx/server.mustache


  9. Press i once (for insert) and replace the values 80 and 443 with 81 and 444, respectively. It should look like this afterwards.
  10. listen 81{{#reuseport}} reuseport{{/reuseport}};
    listen [::]:81{{#reuseport}} reuseport{{/reuseport}};
    listen 444 ssl{{#https.http2}} http2{{/https.http2}}{{#reuseport}} reuseport{{/reuseport}};
    listen [::]:444 ssl{{#https.http2}} http2{{/https.http2}}{{#reuseport}} reuseport{{/reuseport}};
  11. Then write :wq (for write and quit) and confirm with enter. Do the same with those two files:
  12. sudo vi /usr/syno/share/nginx/DSM.mustache
  13. sudo vi /usr/syno/share/nginx/WWWService.mustache
  14. Next, nginx must be restarted with the command:
  15. sudo -i synoservice --restart nginx
    Now you can check whether the ports are really no longer in use with
  16. sudo netstat -lntup | grep ":80"
    sudo netstat -lntup | grep ":443"

    If nothing shows up anymore, then we successfully freed the ports and this means the first of three steps is done.

  17. Then docker must be installed from the package center in DSM. Pihole has to be downloaded, adjusted and started as shown in the attached "Install-pihole.pdf" file. Thanks to Marius Bogdan Lixandru (see ) for his instructions, which were slightly adapted for installing pihole with lancache.
  18. It is important that you create the following folder structure on your NAS.




    We need the folder /etc/dnsmasq.d later on to put some .conf files in there.
  19. Take the password from the protocol of the Docker container (as described in the pdf) and login as admin to

    ip-of-your-nas:8181/admin (e.g.

    Set the Interface listening behavior in Settings/DNS to

    Listen to all interfaces

  20. Now we have to download the domain lists, which should be cached afterwards. Download the folder


    from and copy the folder to your NAS. (e.g. /volumes2/lancache)
  21. Then use ssh and change the directory to scripts
  22. cd /volumes2/lancache/cache-domain-master/scripts

    Run the script which creates .config files for your pihole

  23. sudo ./

    copy the created files from 



    to your pihole dnsmasq.d-configs folder (which is in my case as follows)




  24. Finally, Lancache must be installed. The folder


    has to be downloaded from and moved, for example, to


    on your NAS.
  25. Change to the /volume2/lancache/docker-compose-master folder via SSH
  26. cd /volume2/lancache/docker-compose-master
  27. Edit the .env file within the folder
  28. vi .env
  29. Set the three variables:

    LANCACHE_IP=local address of your NAS (in my case
    DNS_BIND_IP=same here (in my case
    CACHE_ROOT=/your/desired/path (in my case /volume2/lancache/)


  30. Next login as root in SSH via 
  31. sudo -i
  32. Change the directory to your docker-compose-master folder, which is in my case
  33. cd /volume2/lancache/docker-compose-master
  34. Run
  35. docker-compose up -d
    You will get two successfully installed docker container and one error. This is because the pihole already occupies the port 53. We can ignore this message and move on.

    Due to the fact that we use pihole as DNS service you can now delete the docker container lancache-dns.

  36. Now change the DNS server on your router to the IP address of your NAS.
  37. Flush DNS entries of running PCs or reboot them and you should get a decent lancache performance, depending on your xpenology / network setup.

Feel free to correct me if I wrote something incorrectly or didn't explain it well enough.



Edited by smileyworld

Share this post

Link to post
Share on other sites

Would you happen to have the PDF that is supposed to be attached? I've followed this tutorial and it feels like the only thing I'm missing is the tweaked setup to my pi-hole container, because I'm using the host network as instructed in the marius hosting tutorial.


Any advice to that part of the process would be much appreciated!

Share this post

Link to post
Share on other sites
Posted (edited)
1 hour ago, cvsickle said:

Would you happen to have the PDF that is supposed to be attached?

Install-pihole.pdf  is attached and download is working

Edited by IG-88
  • Like 1

Share this post

Link to post
Share on other sites
On 8/16/2020 at 1:46 AM, IG-88 said:

Install-pihole.pdf  is attached and download is working


Thanks! I realized after I made an account that I needed an account to download attachments. Sorry for bugging you, and thanks so much for this guide.

  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.