Skip to content

About

Ultimate Privacy Guide: Pi-hole, Unbound, PiVPN, and DPI Bypass setup for Raspberry Pi and Debian/Ubuntu Linux systems.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ultimate Privacy Server (v2)

Pi-hole + Unbound (recursive or DNS-over-TLS) + Zapret (DPI bypass) + WireGuard + SQM on one small Linux box, acting as the real gateway of your home network.

Works with any home layout: two network cards, one network card + a managed switch (VLAN), or one network card and nothing else.

🌍 Languages: English (this page) · Türkçe · 中文


Contents

  1. What you are building
  2. Choose your topology
  3. Before you start
  4. Base system
  5. Pi-hole
  6. Unbound (recursive or DNS-over-TLS)
  7. Network setup per topology
  8. Firewall and DNS leak prevention
  9. Zapret (DPI bypass)
  10. zapret-guard (self-healing)
  11. WireGuard (PiVPN)
  12. SQM: low latency under load
  13. Hardening
  14. Checkpoints and outage logging
  15. Verification checklist
  16. Troubleshooting and known pitfalls
  17. What your ISP can still see

0) What you are building

Layer Tool What it does
DHCP + DNS + ad blocking Pi-hole Hands out addresses, blocks ads/trackers for every device
DNS resolution Unbound Recursive (no third party) or encrypted DoT to Quad9/Cloudflare (ISP can't read your DNS)
DPI bypass Zapret (nfqws) Gets around SNI/DPI-based blocking for every device behind the server
Self-repair zapret-guard Detects when zapret silently stops working and fixes it
Low latency SQM (HTB + fq_codel) Keeps ping low while the line is full
Remote access WireGuard (PiVPN) Your home network and ad blocking from anywhere
Safety net checkpoints, netwatch One-command rollback; logs that tell you if an outage is the ISP or you
Internet ── Modem ── Server (gateway) ── Switch / Wi-Fi ── all devices
                      │ Pi-hole → Unbound (DoT or recursive)
                      │ Zapret (+ zapret-guard)
                      │ SQM, firewall, WireGuard

Hardware: any Debian/Ubuntu machine with a gigabit Ethernet port is enough: a Raspberry Pi 4/5, a mini PC, or an old laptop (laptops have a built-in UPS and a screen for emergencies).


1) Choose your topology

A. Two NICs B. One NIC + managed switch (VLAN) C. One NIC, no managed switch
Extra hardware USB 3 gigabit adapter (~10 €) Managed / "easy smart" switch with 802.1Q (~25 €) none
Every device goes through the server automatically ✅ ✅ ❌ only devices you configure
Modem isolated from your LAN ✅ ✅ ❌
Speed full full (one gigabit cable carries both directions) lower (traffic crosses the same cable twice, "hairpin")
Difficulty easy medium easy
Server does DHCP yes (Pi-hole) yes (Pi-hole) no (modem keeps DHCP)

Recommendation: A or B. C is fine to start with or if you only want a few devices (your PC, your console) to use zapret.

Wiring:

A)  Modem ──[eth1 WAN] Server [eth0 LAN]── Switch/AP ── devices

B)  Modem ── port 1 (VLAN 10 untagged)
             Switch
    Server ── port 2 (VLAN 1 untagged + VLAN 10 tagged)
    devices ─ ports 3-8 (VLAN 1)

C)  Modem ── Switch/AP ── Server + devices   (same flat network)

🔑 Wi-Fi: In A and B, mesh / access points must be in bridge (AP) mode, not router mode. Otherwise they add a second NAT and their own DHCP. With mesh systems the primary unit must be connected first: a satellite alone gets an IP but shows red and broadcasts no Wi-Fi.


2) Before you start

You need: sudo access, router/modem admin access, and a way to reach the server if the network breaks (a monitor/keyboard, or the laptop's own screen).

⚠️ If you manage the server from a computer whose internet goes through the network you are changing, you will lose your session during the cutover. Keep that computer on a phone hotspot (Wi-Fi) and connect it to the LAN by cable with a temporary address (e.g. sudo ifconfig en7 alias 192.168.50.50/24 on macOS).

Example addresses used in this guide (change them to yours):

Name Example Meaning
MODEM_IP 192.168.1.1 modem / ISP router
SERVER_WAN_IP 192.168.1.2 server on the modem side (A/B) or its only IP (C)
LAN_NET 192.168.50.0/24 your home LAN behind the server (A/B)
SERVER_IP 192.168.50.1 server on the LAN = gateway + DNS (A/B)
VPN_NET 10.6.0.0/24 WireGuard clients

Find your interface names: ip -br link.


3) Base system

sudo apt update && sudo apt full-upgrade -y
sudo apt install -y curl git wget dnsutils iptables-persistent unbound ipset tcpdump bc

When iptables-persistent asks to save current rules, answer No for now.


4) Pi-hole

curl -sSL https://install.pi-hole.net | sudo bash
  • Upstream DNS choice is temporary (switched to Unbound in step 5).
  • Admin UI: http://SERVER_IP/admin
pihole status

DHCP is enabled later (step 6) for topologies A and B.


5) Unbound

5.1 Recursive mode (default)

sudo wget -qO /var/lib/unbound/root.hints https://www.internic.net/domain/named.root
sudo tee /etc/unbound/unbound.conf.d/pi-hole.conf >/dev/null <<'EOF'
server:
    interface: 127.0.0.1
    port: 5335
    do-ip4: yes
    do-ip6: no
    do-udp: yes
    do-tcp: yes
    root-hints: "/var/lib/unbound/root.hints"
    harden-glue: yes
    harden-dnssec-stripped: yes
    edns-buffer-size: 1472
    prefetch: yes
    qname-minimisation: yes
    private-address: 10.0.0.0/8
    private-address: 172.16.0.0/12
    private-address: 192.168.0.0/16
EOF
sudo unbound-checkconf && sudo systemctl restart unbound && sudo systemctl enable unbound
dig +short google.com @127.0.0.1 -p 5335

In Pi-hole: Settings → DNS → untick all upstreams → Custom 1 (IPv4): 127.0.0.1#5335.

5.2 Optional: DNS-over-TLS (hide DNS from your ISP)

In recursive mode no single company sees all your queries, but every query leaves your home unencrypted, so your ISP can read (and tamper with) them. DoT encrypts them to one resolver instead. It is also usually faster for uncached names (the resolver is close to you).

Recursive DoT (Quad9 + Cloudflare)
ISP sees your DNS yes no (only encrypted traffic to 9.9.9.9 / 1.1.1.1)
Who sees all queries nobody the resolver
Uncached lookup (typical) 50-300 ms 30-150 ms
DNSSEC local local

Check that port 853 is reachable, then install examples/unbound-dot.conf:

timeout 5 openssl s_client -connect 9.9.9.9:853 -brief </dev/null 2>&1 | grep -i verif
sudo cp examples/unbound-dot.conf /etc/unbound/unbound.conf.d/90-dot.conf
sudo unbound-checkconf && sudo systemctl restart unbound
dig +short google.com @127.0.0.1 -p 5335
dig dnssec-failed.org @127.0.0.1 -p 5335 | grep status    # SERVFAIL = DNSSEC works

Prove nothing leaves unencrypted (on the WAN interface, while you browse):

sudo timeout 20 tcpdump -ni WAN_IF port 53     # should print nothing

ECH (Encrypted Client Hello): with Pi-hole passing HTTPS (type 65) records, modern Chrome/Brave/Edge already encrypt the site name for sites that support ECH (most of Cloudflare). Test: open https://crypto.cloudflare.com/cdn-cgi/trace and look for sni=encrypted. Keep the browser's own "Secure DNS" off, so the browser keeps using Pi-hole.


6) Network setup per topology

6.1 Common: modem side

  • Keep the modem in router mode with DHCP on (it will only serve the server's WAN side in A/B).
  • Give the server's WAN MAC a DHCP reservation in the modem (SERVER_WAN_IP).
  • Port forward UDP 51820 → SERVER_WAN_IP for WireGuard (no DMZ needed).
  • Turn the modem's own Wi-Fi off if your access points do Wi-Fi.
  • Leave the modem's DNS setting automatic. In A/B the modem cannot reach your LAN, so pointing its DNS to the server breaks the modem's own lookups.

6.2 Topology A: two NICs

  1. Plug the USB adapter into a USB 3 port; the modem goes to one NIC, your switch/AP to the other.
  2. Adapt examples/netplan-dual-nic.yaml → /etc/netplan/01-netcfg.yaml, then sudo netplan try (auto-reverts if you lose the connection).
  3. Continue with 6.4 Pi-hole DHCP.

6.3 Topology B: one NIC + managed switch (VLAN)

Switch (TP-Link Easy Smart and similar; menu names vary). Do it in this order, the switch refuses to remove a port from VLAN 1 while its PVID is 1:

  1. VLAN → 802.1Q VLAN: Enable, Apply.
  2. Add VLAN 10 ("WAN"): modem port untagged, server port tagged, all others not member. Add/Modify.
  3. 802.1Q PVID: set the modem port's PVID to 10.
  4. Edit VLAN 1: modem port not member, all other ports untagged.
  5. Newer firmware saves automatically; older ones have Save Config. Then download a config backup (System Tools → Backup).

Your switch will now get its management IP from the server's DHCP on VLAN 1.

Server: adapt examples/netplan-vlan.yaml.

Safe cutover with automatic rollback:

# on the server, as root: schedule a rollback in 10 minutes, then apply
sudo cp /etc/netplan/01-netcfg.yaml /root/netplan.before
sudo systemd-run --on-active=600 --unit=net-rollback \
  sh -c 'cp /root/netplan.before /etc/netplan/01-netcfg.yaml && netplan apply'
sudo cp ~/netplan-vlan.yaml /etc/netplan/01-netcfg.yaml && sudo netplan apply
# reconnect to the NEW address; if everything works, cancel the rollback:
sudo systemctl stop net-rollback.timer

If the server's NIC uses hardware VLAN offload and you see rx error messages in dmesg, try sudo ethtool -K eth0 rxvlan off txvlan off.

6.4 Pi-hole DHCP (A and B)

Pi-hole → Settings → DHCP: enable, range e.g. 192.168.50.100-250, router SERVER_IP. Or from the shell:

sudo pihole-FTL --config dhcp.active true
sudo pihole-FTL --config dhcp.start 192.168.50.100
sudo pihole-FTL --config dhcp.end 192.168.50.250
sudo pihole-FTL --config dhcp.router 192.168.50.1
sudo pihole-FTL --config dhcp.netmask 255.255.255.0
# fixed addresses: "MAC,IP,name"
sudo pihole-FTL --config dhcp.hosts '["aa:bb:cc:dd:ee:01,192.168.50.2,switch","aa:bb:cc:dd:ee:02,192.168.50.3,ap-main"]'

Tip: give access points the IP that matches their switch port number; easy to remember.

6.5 Topology C: one NIC, no managed switch

The server is just another device on the modem's network. You decide which devices use it:

  • Per device: set gateway and DNS to SERVER_WAN_IP manually on the devices you want (PC, console, TV).
  • DNS for everyone: many modems let you set the DHCP DNS server to SERVER_WAN_IP; then every device gets ad blocking, but only the devices from the previous point get zapret.

⛔ Never set the modem's DHCP gateway to the server in this topology. The server itself takes its address from that DHCP, picks itself as gateway, and the whole house loses internet.

Cost of C: forwarded traffic enters and leaves through the same cable. Use MODE=single in SQM (step 11) to keep it smooth.


7) Firewall and DNS leak prevention

For A and B, review the variables in examples/firewall.sh, then:

sudo ./examples/firewall.sh

It adds: NAT, a WAN input guard (only WireGuard, DHCP from the modem, ICMP and established traffic are accepted from the modem side), a block on new connections from WAN into LAN/containers, a redirect so devices with hard-coded DNS (8.8.8.8 ...) are answered by Pi-hole, and a block on devices' own DoT (853).

Save the rules without zapret's rules (zapret adds its own at boot):

sudo systemctl stop zapret 2>/dev/null; sudo netfilter-persistent save; sudo systemctl start zapret 2>/dev/null

Topology C: only enable forwarding and NAT:

echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-forward.conf && sudo sysctl --system
sudo iptables -t nat -C POSTROUTING -o eth0 -j MASQUERADE 2>/dev/null || sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo netfilter-persistent save

8) Zapret (DPI bypass)

8.1 Install

git clone https://github.com/bol-van/zapret.git ~/zapret && cd ~/zapret
sudo ./install_easy.sh

8.2 Configure /opt/zapret/config

FWTYPE=iptables
NFQWS_ENABLE=1
NFQWS_PORTS_TCP=80,443
NFQWS_PORTS_UDP=443
MODE_FILTER=none
DISABLE_IPV6=1
# A/B: WAN = modem side, LAN = home side (+ wg0 for VPN clients)
IFACE_WAN=eth0.10
IFACE_LAN="wg0 eth0"
# C: the same interface for both
# IFACE_WAN=eth0
# IFACE_LAN="wg0 eth0"
NFQWS_OPT="--filter-tcp=80,443 --dpi-desync=fake --dpi-desync-ttl=3"
sudo systemctl restart zapret && sudo systemctl enable zapret
sudo iptables -t mangle -S | grep -c NFQUEUE    # > 0

8.3 Fix the boot order (important!)

netfilter-persistent loads rules.v4 at boot and flushes the tables. If zapret started first, its rules are gone: zapret looks active but does nothing. Because its rules use --queue-bypass, traffic then passes silently instead of failing, and blocked sites just stop opening after a reboot.

sudo mkdir -p /etc/systemd/system/zapret.service.d
sudo cp examples/zapret-after-netfilter.conf /etc/systemd/system/zapret.service.d/
ls /etc/systemd/system/netfilter-persistent.service.d/ 2>/dev/null   # remove anything with After=zapret.service
sudo systemctl daemon-reload

Reboot, then check sudo iptables -t mangle -S | grep -c NFQUEUE is > 0.

Rules of thumb:

  • always restart with sudo systemctl restart zapret (not the init script directly)
  • save iptables rules while zapret is stopped

8.4 Pick a strategy (measure, don't guess)

DPI differs per ISP, per line and sometimes per hour. Measure with many attempts:

sudo ./scripts/zapret-bench.sh 100      # edit TESTS first: sites blocked on YOUR network

Typical results on one cable ISP (100 attempts each):

Strategy Success TLS handshake
zapret off 50% (one client type slipped through) –
multisplit (4 split points) 60-68% –
multisplit (52 split points) 100% ~2× slower
fake TTL 3 100% fast
fake TTL 4/5/6 100% fast
fake + autottl 100% fast, but broke WhatsApp/Facebook/Instagram

Recommended: fake TTL 3, with multisplit (many split points) as a fallback.

Test sites that are NOT blocked, too. autottl passed every DPI test, yet it broke all Meta sites (WhatsApp Web loaded unstyled, Facebook/Instagram timed out): Meta's caches sit only ~6 hops away inside the ISP, so the fake packet reached Meta's servers instead of dying at the DPI box. A low fixed TTL (3) dies inside the ISP before any server. Quick check: stop zapret, and if a site works then but not with zapret on, the strategy is breaking it. zapret-bench.sh and zapret-guard test web.whatsapp.com for this (MUST_WORK_URLS).

Also test a small ClientHello: some apps (e.g. the Discord updater) send tiny TLS hellos that slip past weak split strategies:

curl -s -o /dev/null -w '%{http_code}\n' --tlsv1.2 --tls-max 1.2 --no-alpn \
     --ciphers ECDHE-RSA-AES128-GCM-SHA256 https://updates.discord.com

000 = blocked, any other code = passed.

Note: a site that does not support ECH (for example Discord) always needs zapret, even when your browser uses ECH elsewhere.


9) zapret-guard (self-healing)

Detects "zapret running but not working" and repairs it: checks every 3 minutes, restarts zapret, falls back through strategies, leaves zapret alone if you stopped it on purpose, and does nothing during an ISP outage.

sudo install -m 755 scripts/zapret-guard /usr/local/sbin/zapret-guard
sudo install -m 644 scripts/zapret-guard.default /etc/default/zapret-guard   # edit TEST_URLS / MUST_WORK_URLS
sudo install -m 644 scripts/zapret-guard.service scripts/zapret-guard.timer /etc/systemd/system/
sudo systemctl daemon-reload && sudo systemctl enable --now zapret-guard.timer
sudo zapret-guard --status

Calibrate once: the test must fail with zapret off.

sudo systemctl stop zapret; curl -s -o /dev/null -w '%{http_code}\n' https://discord.com   # expect 000
sudo systemctl start zapret

Simulate the boot-order failure and watch it heal (within ~3 minutes):

sudo iptables -t mangle -S | grep NFQUEUE | sed 's/^-A /-D /' | while read -r r; do sudo iptables -t mangle $r; done
tail -f /var/log/zapret-guard.log

10) WireGuard (PiVPN)

curl -L https://install.pivpn.io | sudo bash      # choose WireGuard, port 51820, DNS = Pi-hole
pivpn add && pivpn -qr
  • Port forward UDP 51820 in the modem (6.1). A/B: set IPv4dev in /etc/pivpn/wireguard/setupVars.conf to the WAN interface.
  • Use a dynamic DNS name (e.g. DuckDNS) as the endpoint if your public IP changes.

CGNAT check: compare the WAN IP shown in the modem with curl https://api.ipify.org. If they differ, or the modem shows 100.64.x.x - 100.127.x.x, you are behind CGNAT and no inbound VPN will work. Ask your ISP for a public IP (often free on request; it can be lost again when you move or change plans).


11) SQM: low latency under load

Shape slightly below your real line speed so the queue forms on the server (where fq_codel keeps it short) instead of in the modem.

  1. Measure the raw line on the server without SQM, e.g. a big download while reading /sys/class/net/WAN_IF/statistics/rx_bytes every 0.25 s. On cable (DOCSIS) the download limit is applied at the ISP's CMTS and the upload limit inside your modem, often with a short burst at the start.
  2. Start with ~90-95% of the measured values:
sudo install -m 755 scripts/sqm.sh /usr/local/sbin/sqm.sh
sudo install -m 644 scripts/sqm.default /etc/default/privacy-sqm      # set MODE, interfaces, DOWN, UP
sudo install -m 644 scripts/sqm.service /etc/systemd/system/
sudo install -m 755 scripts/50-sqm-dispatcher /etc/NetworkManager/dispatcher.d/50-sqm
sudo systemctl daemon-reload && sudo systemctl enable --now sqm
  1. Test with a wired client (Waveform bufferbloat test, networkQuality on macOS, or ping during a speed test). Aim for +0-10 ms under load. Change rates live with sudo tc class change dev WAN_IF parent 1: classid 1:30 htb rate 9000kbit ceil 9000kbit quantum 1514.

Notes from real tests:

  • Wi-Fi adds its own latency spikes. On macOS, Sidecar / iPhone mirroring / AirDrop (AWDL) cause regular ~100 ms spikes every 0.5 s; test by cable.
  • Cable upload capacity can drop in the evening below your limit. Then shaping can't help (the queue is at the ISP). Confirm with netwatch (step 13) before lowering limits; do sweeps at a quiet time.
  • Download-side "unloaded" latency in web tests depends on where their server is; compare with ping 1.1.1.1.

12) Hardening

See examples/hardening.md:

  • SSH keys only (phone shortcuts can use keys too)
  • automatic security updates without automatic reboots
  • no IPv6 on the WAN side, ICMP redirects off
  • never put the sudo password into automations, bots or AI agents; give passwordless sudo to one root-owned script instead
  • remove your user from docker/lxd groups if not needed (= root)

13) Checkpoints and outage logging

Checkpoints: snapshot all network/security config before every change and return with one command.

sudo install -m 755 scripts/checkpoint scripts/checkpoint-restore /usr/local/sbin/
sudo checkpoint CP0 "working base"
sudo checkpoint --list
sudo checkpoint-restore CP0          # saves the current state first, then reboots

netwatch: logs outages and tells you whether it was the ISP, the modem side or your LAN, which is useful evidence when you call your ISP.

mkdir -p ~/netwatch ~/.config/systemd/user
cp scripts/netwatch.sh ~/netwatch/ && chmod +x ~/netwatch/netwatch.sh
cp scripts/netwatch.service ~/.config/systemd/user/     # set your targets in it
loginctl enable-linger "$USER" && systemctl --user enable --now netwatch
grep -E 'STARTED|ENDED' ~/netwatch/netwatch.log

14) Verification checklist

On the server:

sudo systemctl is-active pihole-FTL unbound zapret zapret-guard.timer sqm netfilter-persistent
dig +short cloudflare.com @127.0.0.1
sudo zapret-guard --status
sudo iptables -t nat -S POSTROUTING | grep MASQ

On a client:

  • gets an address from Pi-hole, gateway and DNS = SERVER_IP (A/B)
  • traceroute 1.1.1.1: first hop server, second hop modem
  • blocked site opens; https://crypto.cloudflare.com/cdn-cgi/trace shows sni=encrypted
  • dig @8.8.8.8 example.com is answered fast (redirected to Pi-hole)
  • after a reboot of the server everything still works (the real test)

15) Troubleshooting and known pitfalls

Symptom Likely cause / fix
Blocked sites stop opening after a reboot, zapret "active" boot order (8.3); iptables -t mangle -S | grep NFQUEUE empty
zapret-guard repairs then zapret dies something restarts zapret via the init script inside a oneshot unit; always systemctl restart zapret
Whole house offline (C) modem DHCP gateway was set to the server; set it back to the modem
Mesh unit red, no Wi-Fi it is a satellite; connect the primary unit first
Two DHCP servers fighting AP/mesh still in router mode; switch to bridge/AP mode
Admin UI of modem blank in browser a local proxy (e.g. SpoofDPI on your PC) is in the way; exclude local networks from it
DoT: no resolution port 853 blocked: test with openssl s_client; check #hostname in forward-addr
Inbound WireGuard never connects CGNAT (10) or missing port forward
Latency spikes only on Wi-Fi AWDL/Sidecar, weak signal; test by cable

Rollback: sudo checkpoint-restore <name>; for VLAN problems you can also disable 802.1Q on the switch (or factory-reset it) to return to a flat network.


16) What your ISP can still see

Without this setup With it
DNS queries visible hidden (DoT)
Site name (SNI) visible hidden on ECH sites; DPI blocks bypassed by zapret
Destination IPs, timing, volume visible still visible
Content (HTTPS) encrypted encrypted

Hiding destination IPs requires tunnelling all traffic to a server outside your ISP (VPN), which adds latency. This guide deliberately stays without one.


License

See LICENSE.

About

Ultimate Privacy Guide: Pi-hole, Unbound, PiVPN, and DPI Bypass setup for Raspberry Pi and Debian/Ubuntu Linux systems.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages