이집트의 한 개발자가 단돈 5달러 저렴한 마이크로컨트롤러 ESP32-C3를 이용해 53만 개 이상의 광고 도메인을 차단하는 DNS 필터링 기기를 제작했습니다. 제한된 메모리 용량을 극복하기 위해 FNV-1a 해시 알고리즘으로 도메인 목록을 압축하고 이진 탐색으로 처리하여 10ms의 매우 빠른 응답 속도를 구현했습니다. 복잡한 설정 없이도 네트워크 전체에 초저비용의 광고 차단 백업 환경을 구축할 수 있는 훌륭한 사례입니다.
번역된 본문
하드웨어 기반의 광고 차단 DNS 필터를 얼마나 저렴하게 만들 수 있을까요? 버려진 중고 부품을 주워 쓴다면 '공짜'일 수도 있습니다. 하지만 그런 운이 없다면 어떨까요? RAM 가격이 폭등하는 시대에 라즈베리 파이(Raspberry Pi) 하나는 수백 달러나 할 수 있습니다. 하지만 사실 그렇게 성능이 좋은 기기가 꼭 필요한 것은 아닙니다. 실제로 단돈 5달러짜리 마이크로컨트롤러를 사용해 50만 개 이상의 도메인을 차단하고 약 10ms의 지연 시간(latency)을 갖는 완벽하게 작동하는 광고 차단 필터를 만들 수 있습니다.
이집트의 풀스택 개발자인 ZedAxis(GitHub 아이디 @M-Abozaid)가 이미 이러한 기기를 만들었기 때문에 이것이 가능하다는 것을 알고 있습니다. 그는 ESP32-C3 'SuperMini' 보드를 사용하여 자신의 홈 네트워크에 광고 차단 기능을 제공하는 보조 DNS를 구축했습니다. 그의 주 라우터는 DHCP 주소 할당 및 DNS 해석을 관리하고 통합된 광고 차단 기능을 제공하는 라즈베리 파이 전용 소프트웨어인 파이홀(Pi-hole)입니다. 이 SuperMini 기기는 파이홀이 재부팅되거나 사용할 수 없을 때 보조 역할을 합니다. 엄밀히 말해 우리가 ZedAxis의 작품이 작동하는 것을 직접 본 것은 아니지만, 작동하지 않을 이유는 없습니다. Wi-Fi가 내장된 임베디드 마이크로컨트롤러인 ESP32 제품군은 이미 검증된 기기이며, 이러한 기능은 결코 ESP32의 성능 범위를 벗어나는 것이 아닙니다.
실제로 이 특별한 트릭은 상위 모델에서 발견되는 8MB의 PSRAM이 없는 비용 절감형 칩인 ESP32-C3의 사용을 가능하게 합니다. (ESP32에는 매우 다양한 변형 모델이 있습니다.) ZedAxis가 사용한 ESP32-C3은 400KB의 RAM과 4MB의 플래시 메모리만 가지고 있습니다. 이 제한된 사양으로는 실제 크기의 일반 텍스트 블록리스트(차단 목록)를 저장할 수 없었습니다. 데이터 양이 너무 많기 때문입니다. 그래서 그는 기업가 정신을 가진 해커들이라면 누구나 할 벽한 일을 했습니다. 데이터 크기를 줄이기 위해 데이터 해싱을 시작한 것입니다. 32비트는 너무 많은 충돌을 발생시키고 64비트는 공간을 너무 많이 낭비하기 때문에 40비트 FNV-1a 해시를 사용하여 약 537,000개의 도메인을 기기의 플래시 메모리에 저장할 수 있었습니다.
하지만 진정으로 영리한 부분은 해싱 자체가 아닙니다. 도메인 자체를 저장하는 대신, 빌드 과정에서 하나 이상의 공개 차단 목록을 다운로드한 뒤 중복된 항목과 주석을 제거합니다. 그런 다음 남은 각 도메인을 40비트 값으로 해시하여 결과 목록을 정렬하고 완성된 데이터베이스를 ESP32의 플래시 메모리에 기록합니다. DNS 쿼리가 들어오면 기기는 요청된 호스트 이름을 동일한 방식으로 해시하여 정렬된 해시 테이블에 대해 이진 탐색을 수행합니다. 일치하는 항목을 찾으면 요청이 차단됩니다. 그렇지 않으면 쿼리가 상위 해석기(upstream resolver)로 전달됩니다. ZedAxis에 따르면 완성된 펌웨어는 RAM 약 50KB만 사용하며 차단된 조회를 약 10밀리초 만에 응답합니다.
설계에는 또 다른 멋진 타협이 숨어 있습니다. 일반적으로 ESP32는 무선 펌웨어 업데이트(OTA) 중 플래시 실패로 인해 기기가 부팅되지 않는 위험 없이 업데이트를 수행할 수 있도록 펌웨어 전체 복사본 두 개를 저장할 수 있는 충분한 플래시 메모리를 예약해 둡니다. 만약 무선 펌웨어 업데이트가 필요 없다면, 그 두 번째 펌웨어 파티션을 차단 목록 데이터베이스 용도로 재활용할 수 있습니다. OTA를 지원하도록 설정한 상태에서는 약 250,000개의 도메인 차단으로 제한됩니다. 하지만 OTA 기능을 포기하면 패스트푸드 점심 한 끼 가격으로 살 수 있는 이 마이크로컨트롤러에서 차단할 수 있는 도메인 수가 약 537,000개로 크게 증가합니다. ZedAxis는 가격을 2달러라고 언급했으나, 필자는 약 5달러 미만으로 SuperMini 보드를 찾을 수 있었습니다. 하지만 이 가격이라면 그 차이를 두고 말다툼할 필요는 없을 것입니다.
물론 이 기기는 정식 파이홀(Pi-hole)이나 AdGuard Home 설치를 완전히 대체하기 위한 것은 아닙니다. 이 ESP32 프로젝트는 기본적인 대시보드를 제공하지만, 해당 플랫폼들을 매력적으로 만드는 클라이언트별 상세 통계, 과거 쿼리 로그 또는 다양하고 세밀한 설정 기능 등은 제공하지 않습니다.
Copy link Facebook X Whatsapp Reddit Pinterest Flipboard Email Share this article 5 Join the conversation Follow us Add us as a preferred source on Google Newsletter Subscribe to our newsletter How cheap can you build a hardware-based ad-blocking DNS filter? "Free," if you're willing to salvage some used hardware that's being thrown away. What if you aren't so lucky? In the era of the RAMageddon, even a Raspberry Pi will cost you a couple hundred bucks. But you know, you don't even need something that powerful. In fact, you can use a $5 microcontroller to build a fully functional ad-blocking filter with over 500,000 domains blocked and around 10ms latency. We know that's possible because Egyptian full-stack developer ZedAxis (@M-Abozaid on GitHub) has already built one. Using an ESP32-C3 "SuperMini" board, he's created a backup DNS for his home network that still provides ad blocking. His primary router is a Pi-hole, which is a Raspberry Pi running specialized software to manage DHCP addressing and DNS resolution with integrated ad-blocking. The SuperMini serves as a backup when the Pi-Hole is rebooting or otherwise unavailable. Strictly speaking, we haven't seen ZedAxis' creation in action, but there's no reason to believe it doesn't work. The ESP32 family of embedded Wi-Fi-enabled microcontrollers is a well-known quantity , and this functionality is by no means outside the realm of its capabilities. In fact, this specific trick allows the use of the ESP32-C3, which is a cost-reduced version of the chip that doesn't have the 8MB of PSRAM found on some higher-end models. (There are MANY variants of the ESP32 .) Latest Videos From Watch full video here: Instead, the ESP32-C3 used by ZedAxis has just 400KB of RAM, and 4MB of flash memory. With these limited specifications, he wasn't able to store a plaintext blocklist of any real size; it's simply too much data. So, he did what any enterprising hacker would do: he started hashing the data to reduce its size. Using 40-bit FNV-1a hashes, because 32-bit would give too many collisions and 64-bit wastes too much space, he can store some 537,000 domains in the flash memory of the device. The clever part isn't really the hashing, though. Rather than storing the domains themselves, the build process downloads one or more public blocklists, strips out duplicate entries and comments, hashes each remaining domain into a 40-bit value, sorts the resulting list, and writes the finished database into the ESP32's flash memory. When a DNS query arrives , the device hashes the requested hostname the same way and performs a binary search against the sorted hash table. If it finds a match, the request is blocked. Otherwise, the query is forwarded to an upstream resolver. According to ZedAxis, the finished firmware uses only around 50KB of RAM while answering blocked lookups in roughly 10 milliseconds. I built a $2 ad-blocker for my whole network - YouTube Watch On There's another neat compromise hiding in the design, too. The ESP32 normally reserves enough flash memory to hold two complete copies of its firmware, allowing over-the-air (OTA) updates without risking a failed flash leaving the device unbootable. If you don't care about wireless firmware updates, you can reclaim that second firmware partition for the blocklist database instead. With OTA support enabled, the project tops out at around 250,000 blocked domains. Give up OTA, and that jumps to roughly 537,000 domains on a microcontroller that you can usually buy for the price of a fast-food lunch . ZedAxis describes the price as $2; I wasn't able to find SuperMini boards any cheaper than about $5 US, but at that price there's not much need to quibble about the difference. Of course, this isn't meant to replace a proper Pi-hole or AdGuard Home installation. The ESP32 project has a rudimentary dashboard, but it doesn't provide detailed per-client statistics, historical query logs, or all the knobs and dials that make those platforms attractive. Instead, it's designed as a tiny insurance policy. It sits quietly on the network, sips only a few dozen milliamps of power, and if the primary DNS server disappears for a reboot or a power outage, clients still get filtered DNS responses instead of falling back to whatever resolver the router happens to have configured. Stay On the Cutting Edge: Get the Tom's Hardware Newsletter Get Tom's Hardware's best news and in-depth reviews, straight to your inbox. Contact me with news and offers from other Future brands Receive email from us on behalf of our trusted partners or sponsors My favorite detail is that ZedAxis powers the whole thing from the USB port on the back of his ISP-provided fiber gateway, a Huawei OptiXstar home fiber gateway. The USB connection isn't carrying any data; the totality of the integration is the router saying "here's 5 volts" and the ESP32 replying "thanks." It's just that the port is a convenient power source for a device so small it practically disappears behind the router. All communications are carried out through the ESP32's integrated Wi-Fi adapter. I have no idea whether projects like this will ever become common. Probably not, because most people who want network-wide ad blocking will still buy a Raspberry Pi, a used mini PC, or run AdGuard Home in a virtual machine. Still, it's refreshing to see somebody look at a $5 microcontroller with 400KB of RAM and decide, "Sure, that'll do." Follow Tom's Hardware on Google News , or add us as a preferred source , to get our latest news, analysis, & reviews in your feeds. See all comments (5) Zak Killian Contributor Zak is a freelance contributor to Tom's Hardware with decades of PC benchmarking experience who has also written for HotHardware and The Tech Report. A modern-day Renaissance man, he may not be an expert on anything, but he knows just a little about nearly everything. 5 Comments Comment from the forums no matter how cheap a project is purported to be , as long as it requires you to either own a 3d printer, or get someone to print it for you, IT IS NOT CHEAP . Reply wakuwaku said: no matter how cheap a project is purported to be , as long as it requires you to either own a 3d printer, or get someone to print it for you, IT IS NOT CHEAP . An ever increasing number of people can get cheap access to a 3D printer through libraries (since nobody reads anymore) or makerspaces. Reply Firefox + Ghostery +Malwarebytes Browser guard, makes it simple. No hardware needed. Spybot Anti Beacon takes care of windows telemetry. Simple and effective. Reply FireFox + UBlock Origin do it without a 3d printer. But nevertheless, kudos!! Reply wakuwaku said: no matter how cheap a project is purported to be , as long as it requires you to either own a 3d printer, or get someone to print it for you, IT IS NOT CHEAP . I print LOTS of things for friends and coworkers for $0. Reply View All 5 Comments Show more comments