Why Run AdGuard Home on an Unrooted Phone?
An old flagship like the Samsung Galaxy Note 20 Ultra has fast ARM64 cores, 12 GB of RAM, Wi-Fi 6, and a built-in battery backup. Turning it into a local AdGuard Home server is a great way to reuse idle hardware—but on an unrooted Android phone, you hit three immediate limits:
- No native Docker: Stock Android kernels lack the namespace and cgroup features Docker needs.
- No port 53: Non-root Termux apps lack
CAP_NET_BIND_SERVICE, so nothing can bind to ports below1024—including standard DNS (53). - User-mode networking & DHCP limits: QEMU on unrooted ARM64 uses software emulation (TCG) and SLIRP networking (
hostfwd), and standard DHCP (Option 6) can't point clients at a custom DNS port like8053.
My workaround: run an Alpine Linux VM inside Termux with qemu-system-aarch64, forward host port 8053 to port 53 in the AdGuard Home container, and use a UniFi Gateway DNAT rule with inter-VLAN routing to transparently redirect LAN port 53 traffic to 192.168.20.67:8053.
End-to-End Network & Execution Topology
Here is the verified packet path from a LAN client (like an Arch Linux workstation) through the UniFi Gateway and QEMU/Alpine stack out to Quad9 and Cloudflare:
[LAN Clients: 192.168.0.0/24]
│ (Standard UDP/TCP Port 53 Queries, e.g. to 1.1.1.1:53)
▼
[UniFi Gateway: Default (1) Interface]
│ (DNAT Rule: Intercept Port 53 -> Translate to 192.168.20.67:8053)
│ (L3 Inter-VLAN Routing preserves Client Source IP — no SNAT required)
▼
[Isolated Services VLAN: 192.168.20.0/24]
│
▼
[Samsung Note 20 Ultra (Termux): 192.168.20.67]
│ (QEMU SLIRP hostfwd: TCP/UDP :8053 -> :53, TCP :3000 -> :3000)
▼
[Alpine Linux VM (aarch64): 10.0.2.15]
│ (Docker Bridge Port Mapping)
▼
[AdGuard Home Container]
│ (Egress via DoT Port 853 / IP-Pinned DoH Port 443)
▼
[Quad9 (9.9.9.9) / Cloudflare (1.1.1.1) Upstreams]
Phase 1: Provisioning the Alpine Linux VM in Termux
Booting Alpine Linux aarch64 under QEMU on Termux runs into two common snags:
- UEFI is slow and breaks on MBR: Emulating
QEMU_EFI.fdunder TCG takes 60–90 seconds just to show output, andsetup-alpineformats/dev/vda1(/boot) asext4instead of FAT32—dropping UEFI straight into aShell>prompt. - The ISO ramdisk lacks
ext4.ko: Skipping UEFI with-kerneland-initrdboots in seconds, but the installer ISO'sinitramfs-ltsonly includesloopandsquashfsdrivers. Booting your installedext4root disk (/dev/vda3) with it fails withmount: mounting /dev/vda3 on /sysroot failed: Invalid argument.
The fix is simple: finish setup-alpine first, then extract the newly built initramfs-lts (which includes ext4.ko) from partition 1 (0.img) of the qcow2 disk.
1. Install QEMU and Prepare the Base Image in Termux
pkg update && pkg install qemu-system-aarch64-headless qemu-utils p7zip curl openssh -y
mkdir -p ~/alpine-docker && cd ~/alpine-docker
# Allocate a 10GB dynamic qcow2 disk
qemu-img create -f qcow2 alpine.img 10G
# Pull Alpine 3.20 aarch64 Standard ISO and extract the live kernel/ramdisk
curl -L -o alpine.iso https://dl-cdn.alpinelinux.org/alpine/v3.20/releases/aarch64/alpine-standard-3.20.3-aarch64.iso
7z e alpine.iso "*vmlinuz*" "*initramfs*" -r -y
2. Boot the Installer via Direct Serial Console
Attach the ISO as vda (read-only) and your target qcow2 image as vdb:
qemu-system-aarch64 \
-M virt \
-cpu cortex-a57 \
-smp 2 \
-m 1024 \
-nographic \
-serial mon:stdio \
-kernel vmlinuz-lts \
-initrd initramfs-lts \
-append "console=ttyAMA0" \
-drive if=virtio,format=raw,file=alpine.iso,readonly=on \
-drive if=virtio,format=qcow2,file=alpine.img \
-netdev user,id=net0 \
-device virtio-net-pci,netdev=net0
Log in as root, run setup-alpine, set eth0 to DHCP, and install (sys) to vdb. Before shutting down, run blkid and copy the UUID of your ext4 root partition (vdb3, which becomes vda3 once the ISO is removed), then run poweroff.
3. Extract the Installed Kernel and ext4-Capable Initramfs
cd ~/alpine-docker
7z x alpine.img 0.img -y
7z e 0.img "vmlinuz-lts" "initramfs-lts" -y
rm -f 0.img
(Note: 7-Zip prints ERROR: Dangerous link path was ignored : boot : . because Alpine creates a /boot/boot -> . symlink. You can ignore this.)
4. Create the Production Startup Script (start-alpine.sh)
cat << 'EOF' > ~/alpine-docker/start-alpine.sh
#!/data/data/com.termux/files/usr/bin/bash
cd ~/alpine-docker
qemu-system-aarch64 \
-M virt \
-cpu cortex-a57 \
-smp 2 \
-m 2048 \
-nographic \
-serial mon:stdio \
-kernel vmlinuz-lts \
-initrd initramfs-lts \
-append "root=UUID=6958c41b-8296-4fd5-bd6b-e3b8506aa583 modules=ext4 rootfstype=ext4 console=ttyAMA0" \
-drive if=virtio,format=qcow2,file=alpine.img \
-netdev user,id=net0,ipv4=on,hostfwd=tcp::8053-:53,hostfwd=udp::8053-:53,hostfwd=tcp::3000-:3000,hostfwd=tcp::2222-:22 \
-device virtio-net-pci,netdev=net0
EOF
chmod +x ~/alpine-docker/start-alpine.sh
Phase 2: Deploying Docker & AdGuard Home (and the Port 80 Gotcha)
Inside the booted Alpine VM, enable the community repo, start Docker via OpenRC, and launch AdGuard Home:
setup-apkrepos -c -1
apk update && apk add docker
rc-update add docker default
service docker start
docker run -d \
--name adguard \
--restart unless-stopped \
-v /opt/adguard/work:/opt/adguardhome/work \
-v /opt/adguard/conf:/opt/adguardhome/conf \
-p 53:53/tcp -p 53:53/udp \
-p 3000:3000/tcp \
adguard/adguardhome:latest
Watch out for Port 80 in the setup wizard: When you open http://<Phone_IP>:3000, AdGuard defaults the permanent admin UI to port 80. Since QEMU only forwards 3000 -> 3000 (and unrooted Android can't bind port 80), keeping that default locks you out as soon as setup finishes. Change the admin port to 3000 in the wizard—or fix AdGuardHome.yaml afterward:
docker stop adguard
sed -i 's/address: 0.0.0.0:80/address: 0.0.0.0:3000/' /opt/adguard/conf/AdGuardHome.yaml
sed -i 's/bind_port: 80/bind_port: 3000/' /opt/adguard/conf/AdGuardHome.yaml
docker start adguard
Troubleshooting the UniFi DNAT & Bootstrap Recursion Loop
Once AdGuard Home was listening on <Phone_IP>:8053, I added a UniFi DNAT rule redirecting LAN port 53 traffic to the phone on port 8053. Right away, Test upstreams in AdGuard failed for every protocol:
Server "1.1.1.1:53": could not be used, please check that you've written it correctly
Server "9.9.9.9:53": could not be used, please check that you've written it correctly
Server "https://cloudflare-dns.com:443/dns-query": could not be used, please check that you've written it correctly
Server "https://dns.quad9.net:443/dns-query": could not be used, please check that you've written it correctly
Server "quic://dns.quad9.net:853": could not be used, please check that you've written it correctly
Why this happened (a bootstrap DNS loop):
- The DNAT rule matched
Source: Anyon port53, so UniFi caught outbound port53queries from the Note 20 Ultra itself and looped them right back to:8053. - Even for DoH (
https://dns.quad9.net/dns-query), AdGuard first had to resolvedns.quad9.netvia its Bootstrap DNS over plain UDP53—which UniFi intercepted and sent back to AdGuard. tls://9.9.9.9worked immediately (port853, no port-53 bootstrap needed), whilehttps://9.9.9.9/dns-queryfailed TLS verification because Go'scrypto/tlsexpects the hostname (dns.quad9.net) in SNI to match the certificate SAN.
The fix — Pin upstream IPs in AdGuard Home: Appending #<IP> tells AdGuard to connect straight to the IP without a port-53 lookup while still sending the hostname in TLS SNI:
# Quad9 (Malware blocking + DNSSEC, pinned IP avoids port 53 bootstrap lookup)
tls://9.9.9.9
https://dns.quad9.net/dns-query#9.9.9.9
quic://dns.quad9.net#9.9.9.9
# Cloudflare (Secondary fallback, pinned IP)
tls://1.1.1.1
https://cloudflare-dns.com/dns-query#1.1.1.1
Why Same-Subnet Masquerade Broke Client Analytics & Android Private DNS
At first, keeping the phone on the main LAN (192.168.0.67/24) forced me to add a Masquerade (Hairpin SNAT) rule alongside DNAT. Without SNAT, the phone saw the client's local 192.168.0.x IP and replied directly over Wi-Fi from 192.168.0.67:8053, which the client dropped because it was expecting a reply from 1.1.1.1:53.
That same-subnet + Masquerade setup caused two headaches:
- 1. Android Private DNS failed closed: Even with Private DNS set to
dns.quad9.net(port853), Android'sDnsResolverstill sends plain UDP53probes on Wi-Fi reconnect, DHCP renewal, and wake-from-sleep to resolve the Private DNS host andconnectivitycheck.gstatic.com. When the screen locked and One UI throttled background threads, looping those probes into QEMU took >2 seconds—causing Android to time out and drop all DNS on the phone. - 2. No per-client logs: Masquerade rewrote every client's source IP to the router (
192.168.0.1), so AdGuard logged 100% of queries under the gateway.
The fix — Move the phone to an isolated Services VLAN (192.168.20.0/24):
- Scoping DNAT strictly to the
Default (1)LAN (192.168.0.0/24) keeps the phone's own port-53 probes on VLAN 20 completely out of the rule. - Because the phone (
192.168.20.67) and LAN clients (192.168.0.x) are on different subnets, return packets route cleanly through the UniFi Gateway at Layer 3. You can delete the Masquerade rule, and AdGuard Home sees every client's real IP.
Phase 3: Final UniFi Gateway VLAN & DNAT Configuration
1. Turn Off Built-in UniFi DNS Interception (which runs in PREROUTING before custom NAT rules):
- Settings > Networks > Default > Content Filtering:
None - Settings > Security > General > DNS Shield:
Off - Settings > Security > Ad Blocking:
Off
2. Move the Phone to VLAN 20 via Virtual Network Override (No Extra SSID Needed):
- Create a
Servicesnetwork under Settings > Networks > New Virtual Network with Gateway192.168.20.1/24and VLAN ID20. - Open Client Devices -> Samsung Note 20 Ultra -> Settings > Network, enable Virtual Network Override -> Services (
192.168.20.0/24), reserve fixed IP192.168.20.67, and reconnect Wi-Fi. - Delete or disable any Hairpin/Masquerade SNAT rule under Settings > Routing > NAT.
3. Add the Destination NAT (DNAT) Rule (Settings > Routing > NAT):
- Rule Type:
Dest. NAT| Interface:Default (1)(192.168.0.0/24) - Translated IP:
192.168.20.67| Translated Port:8053 - Protocol:
TCP/UDP| Source:Any| Destination:Any, Port53
(Note: Because the gateway answers queries sent to 192.168.0.1:53 via local dnsmasq before DNAT runs, set your Default network's DHCP DNS Server to an external trigger IP like 1.1.1.1 so client queries enter routing and get redirected to 192.168.20.67:8053.)
4. Enable Reverse DNS (rDNS) & Keep Termux Awake:
- In AdGuard Home (
http://192.168.20.67:3000 -> Settings > DNS settings), set Private reverse DNS servers to192.168.0.1and enable client IP reverse resolution so hostnames show up in logs. - Set Termux > App Info > Battery to Unrestricted, and start the VM with a wake lock:
termux-wake-lock
nohup ~/alpine-docker/start-alpine.sh > ~/alpine-docker/qemu.log 2>&1 &
Verification From a LAN Workstation
From an Arch Linux workstation on the main LAN (192.168.0.0/24), three dig checks confirm transparent DNAT, local AdGuard blocking, and upstream Quad9 malware filtering:
# 1. Verify transparent DNAT interception (queries 1.1.1.1:53, answered by AdGuard on 192.168.20.67:8053)
dig @1.1.1.1 cnn.com
# 2. Verify local AdGuard filter list sinkholing (returns 0.0.0.0)
dig @1.1.1.1 doubleclick.net
# 3. Verify Quad9 upstream malware sinkholing
dig @1.1.1.1 bad.horse
The AdGuard Home dashboard at http://192.168.20.67:3000 now logs sub-25ms response times with real LAN client IPs and hostnames.