Contents
Have you ever run into these problems?
- You want to resolve custom domain names on your local network, but that means fiddling with the hosts settings on your router?
- You want to block ads, but cannot find a lightweight embedded DNS solution?
- You want to learn the DNS protocol, but complex C implementations put you off?
Today we are sharing the microdns library, written by a developer: it can create a Wi-Fi hotspot, listens on the standard port 53, supports wildcard resolution, and even comes with a web admin page! Best of all, it is pure MicroPython, so beginners can read it and get it running.

Project introduction
This small project is at version 0.0.1, and its core features are already complete:
- ✅ AP-mode hotspot: creates a Wi-Fi network named ESP32_DNS_Server in one step, password 12345678; devices connect to it directly
- ✅ Standard DNS service: listens on UDP port 53, fully supports A record (IPv4) queries and follows the DNS protocol specification
- ✅ Wildcard resolution: supports wildcards such as *.local, resolving every subdomain at once
- ✅ Web admin page: open it in a browser to see the server status, no commands to type
- ✅ Lightweight, pure Python: the core code is only 300 lines with no complex dependencies, so ESP32 memory is no problem
- ✅ MIT open-source license: change it and use it freely, commercial use included
Quick start
All the files are already organised here. Follow the steps and even a beginner can get it working on the first try. You need:
- An ESP32 development board (any maker will do; I used an ESP32-S3)
- MicroPython firmware already flashed (if you do not know how, see my earlier tutorial)
- The mpremote tool installed (used to transfer files to the ESP32)
First install the microdns package with mpremote (you can also transfer the files directly). The library is on upypi: https://upypi.net/
Search for: microdns
Open the package's detail page and copy the install command:
# Local install
mpremote mip install https://upypi.net/pkgs/microdns/0.0.1
# Remote install (on the board)
mip.install("https://upypi.net/pkgs/microdns/0.0.1")
Then transfer these files to the ESP32's root directory:
- main_with_web.py (the complete version with the web interface)
- microdns.py (the DNS core module)
- web_server.py (the web interface)
- dns_list.py (the domain configuration file)
For details on usage, see: https://upypi.net/zh/pkgs/microdns
The package README, shown as two screenshots in the original article, reads:
- Upload the files to the ESP32: upload all files to the ESP32's root directory.
- Start the server:
exec(open('main_with_web.py').read()) - Connect to the Wi-Fi network: SSID ESP32_DNS_Server, password 12345678, IP address 192.168.4.1.
- Configure DNS: set the device's DNS server address to 192.168.4.1.
- Open the web page: in a browser, visit http://www.example.com.
DNS records can be changed in dns_list.py:
self.dns_records = {
'example.com': '192.168.4.1',
'www.example.com': '192.168.4.1',
'test.com': '192.168.4.1',
'*.local': '192.168.4.1', # wildcard match
}
The AP settings can be changed in main.py:
ap.config(essid='ESP32_DNS_Server', password='12345678')
ap.ifconfig(('192.168.4.1', '255.255.255.0', '192.168.4.1', '8.8.8.8'))
Testing:
# 1. Test with nslookup
nslookup example.com 192.168.4.1
# 2. Test with ping
ping example.com
# 3. Test with dig
Advanced tests: DNS hijacking and NCSI spoofing
Test goals
On top of basic DNS resolution, we carried out two advanced experiments:
- DNS hijacking: force domains such as baidu.com, visited on a public Wi-Fi network, to resolve to a custom notice page on the ESP32, simulating a "public Wi-Fi phishing" scenario.
- NCSI spoofing: intercept Windows' network check requests, so that after connecting to the ESP32 hotspot the device shows "Connected, secured" instead of "No Internet", making the disguise more convincing.
Test 1: DNS hijacking demo: visiting Baidu lands on a notice page
- Connect the device to the ESP32 hotspot ESP32_DNS_Server and set its DNS address to 192.168.4.1.
- Type baidu.com in the browser and watch where the page goes.
Screenshot (in the original article, with Chinese labels): the browser address bar shows Baidu's address, with a "Not secure" warning next to it; the page itself is the ESP32's information-security notice ("Protect personal information, build a happy home together"), because the hijacked DNS resolved baidu.com to our notice page.

The browser address bar still shows baidu.com, but the page has been hijacked to the ESP32's information-security notice page, and the browser shows a "Not secure" warning at the top (as expected for unencrypted HTTP).
The ESP32's DNS server resolves baidu.com to its own IP, 192.168.4.1, while the web server listens on port 80 and returns a custom HTML page. This is the typical public Wi-Fi DNS hijacking scenario, and it is the educational demo we use to teach network security.
Test 2: NCSI spoofing: fooling the Windows network check
Windows decides whether the network is connected by visiting dns.msftncsi.com and www.msftconnecttest.com/connecttest.txt, so we need the ESP32 to "play along" with this check.
Add the NCSI domains to dns_list.py:
DNS_LIST = {
# ... other domains
'dns.msftncsi.com': '192.168.4.1',
'www.msftconnecttest.com': '192.168.4.1',
}
Add a response for /connecttest.txt in web_server.py:
@app.route('/connecttest.txt')
def connecttest():
return 'Microsoft Connect Test', 200, {'Content-Type': 'text/plain'}
The terminal log shows that the NCSI check requests sent by Windows were intercepted and answered by the ESP32:
[dns] DNS query received: dns.msftncsi.com (type: 1)
[dns] Resolved dns.msftncsi.com -> 192.168.4.1
[dns] DNS query received: www.msftconnecttest.com (type: 1)
[dns] Resolved www.msftconnecttest.com -> 192.168.4.1
[web]Generated response: [('Content-Type', 'text/plain')]
What else can you do with it?
This project is only a prototype for now, and there is plenty more to tinker with:
- 🚀 DNS forwarding: forward unmatched domains to 8.8.8.8 for a mixed "local + internet" resolution mode
- 📦 Caching: cache DNS queries to avoid repeated lookups and speed things up
- 🛡️ Ad blocking: resolve ad domains to 0.0.0.0 for ad-free browsing
- 📝 More record types: support AAAA (IPv6), CNAME and other records, closer to a real DNS server
- 🎨 A nicer web interface: give the web page a more modern style and add statistics charts