Amazon Cyber Monday deals See deals →ad

Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

Raspberry Pi Pico Pi-hole: Step-by-Step Setup

Turning a Raspberry Pi Pico into a Pi-hole is a clever way to block ads and trackers across your entire home network using a tiny, low-power device. While the classic Pi-hole runs on a full Linux system (like a Raspberry Pi 4), the Pico’s RP2040 chip can’t run Linux. Instead, we use the Pico W (the version with Wi‑Fi) and a lightweight DNS server written in MicroPython or C. This guide shows you how to set up a basic Pi‑hole on a Pico W that filters DNS queries for ad and tracking domains. You’ll need some basic familiarity with the command line and wiring, but no prior Pi‑hole experience is required.

What You’ll Need

  • Raspberry Pi Pico W (the non‑W Pico has no Wi‑Fi, so it won’t work)
  • Micro‑USB cable (data, not charge‑only)
  • A computer (Windows, macOS, or Linux) to program the Pico
  • Optional: a breadboard and jumper wires if you want to add an LED indicator
  • Access to your router’s admin page (to change DNS settings)

Step-by-Step

  1. Install MicroPython on the Pico W. Download the latest MicroPython UF2 file for the Pico W from the official Raspberry Pi Pico page. Hold the BOOTSEL button on the Pico while plugging it into your computer via USB. A drive named “RPI‑RP2” appears. Drag the UF2 file onto that drive. The Pico reboots and now runs MicroPython.
  2. Connect to the Pico’s serial console. Use a terminal program like Thonny (simplest for beginners), or any serial terminal (e.g., PuTTY, screen). In Thonny, select the correct port (usually shows “MicroPython (Raspberry Pi Pico)”). You should see a Python prompt (>>>).
  3. Write the Pi‑hole script. You’ll need a DNS server that listens on port 53 and responds to queries. A basic implementation in MicroPython is about 150 lines. You can write it directly in Thonny, but it’s easier to create a file named main.py that runs on boot. The script will:
    – Set the Pico’s Wi‑Fi to connect to your network.
    – Open a UDP socket on port 53.
    – For each incoming DNS query, check the requested domain against a blocklist.
    – If blocked, return a false IP (e.g., 0.0.0.0). If allowed, forward the query to a public DNS like 1.1.1.1.
    (You can find open‑source examples online, but be sure to adapt them to your network.)
  4. Create a blocklist. You need a list of ad and tracking domains. A common source is the “StevenBlack/hosts” list, but you can also use a smaller custom list. Store it as a text file on the Pico’s file system, or embed it in the script. For a Pico, keep the list under 1,000 domains to avoid memory issues.
  5. Set a static IP for the Pico. In the script, configure the Pico to use a fixed IP address (e.g., 192.168.1.50) so you can point your router to it. Use the network.WLAN interface and set the IP manually.
  6. Run the script. Save the script as main.py on the Pico. Reset the Pico (unplug/replug). It will boot, connect to Wi‑Fi, and start the DNS server. Check the serial console for a message like “Pi‑hole running on 192.168.1.50”.
  7. Configure your router to use the Pico as DNS. Log into your router’s admin panel, find the DHCP settings, and set the DNS server to the Pico’s IP address. Save and reboot your router (or wait for DHCP leases to renew). After that, all devices on your network will send DNS queries to the Pico.
  8. Test it. From any device, open a browser and visit a site that shows your DNS server (like dnsleaktest.com) to verify it’s the Pico. Then try visiting a site that uses ads—ads should be blocked.

Common Mistakes

  • Using a Pico (non‑W) instead of a Pico W. The original Pico has no Wi‑Fi, so it cannot serve as a network DNS server.
  • Forgetting to set a static IP. If the Pico gets a dynamic IP, it may change, and your router will point to a dead address.
  • Blocking too many domains. The Pico has limited RAM (264KB). A massive blocklist can cause crashes or slow responses.
  • Not opening port 53 on the Pico. The script must bind to port 53. If it fails, check that no other service is using that port (unlikely, but possible if you run something else).
  • Pointing the router to the wrong IP. Double‑check the IP you set in the script matches what you enter in the router.

Tips

  • Use a micro‑USB cable that supports data. Some cables are charge‑only and won’t allow serial communication.
  • Keep your blocklist small and curated. Start with a list of 100–200 well‑known ad domains to avoid performance issues.
  • Add a status LED to the Pico (GPIO pin 25 is built‑in). Blink it when a query is blocked—it’s a fun visual.
  • Use Thonny’s “Save to Pico” feature to transfer files. It’s easier than using a separate file manager.
  • If you want more features, consider using the Pico W with CircuitPython and an existing DNS library, but MicroPython is lighter.

Troubleshooting

  • The Pico doesn’t connect to Wi‑Fi. Check your SSID and password in the script. Make sure you’re using the correct 2.4GHz network—the Pico W does not support 5GHz.
  • Port 53 is already in use. On the Pico, nothing else should be using it, but if you have a test script running, stop it. In MicroPython, you might get an OSError. Reboot the Pico and try again.
  • DNS queries time out. If the Pico is not responding, check that it has power and is running. Use the serial console to see errors. Also verify that the Pico’s IP is reachable from your computer (ping it).
  • Ads are still showing. Your router may be caching DNS, or the Pico’s blocklist is incomplete. Flush your device’s DNS cache (e.g., ipconfig /flushdns on Windows) and try again.
  • The Pico resets randomly. This is often due to power issues. Use a good quality USB power supply (5V, 500mA or more).

Frequently Asked Questions

Can I use a regular Raspberry Pi Pico (without W) for Pi‑hole?
No. The non‑W Pico lacks Wi‑Fi, so it cannot receive DNS queries from your network. You’d need an Ethernet shield or a USB Wi‑Fi adapter, but those aren’t well‑supported on the Pico.

Will this block ads on all my devices?
Yes, if you set your router’s DNS to the Pico, every device that uses DHCP (most devices) will be affected. However, devices with hard‑coded DNS settings (like some smart TVs) may bypass it.

How many domains can I block?
It depends on available RAM. A typical Pico W has 264KB of RAM. A blocklist of 1,000 domains uses roughly 20–30KB, so you can go up to a few thousand, but performance may degrade. Stick to under 5,000 for stability.

Does this replace a full Pi‑hole on a Raspberry Pi 4?
No. The Pico version is a simplified DNS blocker. It lacks the web interface, statistics, and advanced filtering of the full Pi‑hole. It’s a fun, low‑cost experiment, but for a serious home network, a Raspberry Pi 4 or an old PC is better.

Can I update the blocklist without reprogramming?
Yes, you can store the blocklist as a separate file (e.g., blocklist.txt) on the Pico’s file system. Then you can edit that file via Thonny or a file manager without changing the main script.

Is it safe to run this 24/7?
Yes, the Pico W draws very little power (around 100mA) and runs cool. Just make sure it’s on a stable power source and the micro‑USB connection is secure.

Raspberry Pi Pico Pi-hole: Step-by-Step Setup
Scroll to top