🛡️

Setting up Network Protection with Pi-hole, Docker, and Flask

Jul 14, 2024

Setting up Network Protection with Pi-hole, Docker, and Flask

Introduction

  • Topics Covered: Pi-hole, Docker, Flask, Python, Linux, OpenDNS, Network Protection
  • Objective: Use technology to protect your family’s network from distractions and unwanted content
  • Prerequisite: Set up OpenDNS (covered in the first video)

Tools and Services

  • Pi-hole: Acts as a DNS sinkhole, blocking ads and unwanted websites
  • Docker: Containerization platform used to run Pi-hole
  • Flask: Used for web interfaces
  • Linux (Ubuntu): Operating system for running Docker
  • SSH Program (SolarPutty): For logging into remote machines
  • CBT Nuggets: Training platform for IT professionals (Sponsor of the video)
  • IFTTT: Service to automate tasks (e.g., using Alexa to control Pi-hole)

Setup Steps

1. Preparing the Linux Environment

  • Virtual Machine: Spin up a VM (Ubuntu) on a cloud provider or local machine
  • SSH into VM: Using SolarPutty
  • *Disable Ubuntu's native DNS resolver:
    • sudo systemctl stop systemd-resolved.service
    • sudo systemctl disable systemd-resolved.service
    • Edit /etc/resolv.conf to use a public DNS (e.g., Google DNS)*

2. Installing Docker

  • Update Repositories: sudo apt update
  • Install Docker: sudo apt install docker.io
  • Verify Installation: sudo docker --version

3. Running Pi-hole in Docker

  • Script Preparation: Use a Bash script from GitHub to run the Docker container
    • Save the script as pihole.sh
    • Make script executable: sudo chmod u+x pihole.sh
  • Run Script: sudo ./pihole.sh
  • Verify Pi-hole container running: sudo docker ps

4. Accessing Pi-hole

  • Web Interface: Access via VM’s public IP address and port 8080
  • Admin Panel: http://<IP Address>/admin
  • Log in Using Password: Provided by the script
  • Change Password: Log into the Docker container and run pihole -a -p
  • Set Upstream DNS: Navigate to DNS settings in the Pi-hole admin panel and set DNS servers (e.g., OpenDNS)

5. Testing and Validating

  • Point DNS to Pi-hole: Configure local device to use Pi-hole IP as DNS server
  • Test DNS Resolution: Use nslookup to validate the setup
  • Monitor Queries and Blocks: Use Pi-hole’s query log

Automation with Alexa and IFTTT

1. Setting up Python Scripts

  • Docker Container Scripts: Scripts for blocking and unblocking domains
    • block_domains.sh and unblock_domains.sh
  • Python Script: Network automation script (network.py)

2. Using IFTTT for Voice Control

  • Create IFTTT Applets: To trigger blocking/unblocking via webhooks
    • Webhook URL: Use the public IP and appropriate port/endpoint (block or unblock)
    • Configure Alexa Trigger: Set specific phrases to initiate blocking/unblocking

Conclusion and Community

  • Results: Efficiently block unwanted content and ads on the network using Pi-hole
  • Further Learning: Recommend CBT Nuggets for more IT training
  • Community Support: Join Discord server for additional help and sharing
  • Personal Experience: Author’s testimony on Pi-hole’s effectiveness

Final Thoughts

  • Encouragement: Continue learning and experimenting with IT tools and technologies
  • Contact Information: Subscribe and join the community for more content and support