smileyworld

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: http://lancache.net

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 "yourdomain.com" but in the future via "yourdomain.com:81".

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 tonylawrence.com), this is relatively easy.

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

    ssh -p portnumber username@IPadress

    for example 
  2. ssh -p 22 tim@192.168.0.100
  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}};
    
    and
    
    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 https://mariushosting.com ) 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.
    Quote

    docker/pi-hole/dnsmasq.d-configs

    and

    docker/pi-hole/pihole-configs

    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
    Quote

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

    Set the Interface listening behavior in Settings/DNS to
    Quote

    Listen to all interfaces

    IMPORTANT, DO NOT FORWARD THE PORTS 53 AND 80 FROM YOUR ROUTER TO YOUR NAS!!!!
  20. Now we have to download the domain lists, which should be cached afterwards. Download the folder
    Quote

    cache-domain-master

    from  https://github.com/uklans/cache-domains 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 create-dnsmasq.sh which creates .config files for your pihole

  23. sudo ./create-dnsmasq.sh

    copy the created files from 

    Quote

    /lancache/setup/cache-domains-dnsmasq/scripts/output/dnsmasq

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

    Quote

    /volume1/docker/pi-hole/dnsmasq.d-configs/

     

  24. Finally, Lancache must be installed. The folder
    Quote

    docker-compose-master

    has to be downloaded from https://github.com/lancachenet/docker-compose and moved, for example, to
    Quote

    /volume2/lancache/docker-compose-master

    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:
    Quote

    LANCACHE_IP=local address of your NAS (in my case 192.168.0.100)
    DNS_BIND_IP=same here (in my case 192.168.0.100)
    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.
    exit
    exit

    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.

LanCache.jpeg

Install-pihole.pdf

Edited by smileyworld

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.

Guest
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.