This tutorial provides step-by-step instructions on how to set up your esp8266/esp32 as a DNS provider using MicroPython. By following these steps, you'll transform your esp8266/esp32 into a DNS mixer, allowing it to handle DNS requests from connected devices and forward them to randomly selected DNS providers.
Before starting, ensure you have the following:
- An esp8266/esp32 device with MicroPython support.
- A computer with a MicroSD card reader (optional, for flashing MicroPython firmware).
If your esp8266/esp32 doesn't have MicroPython installed, you'll need to flash the MicroPython firmware onto it. Follow these steps to do it manually or u can simply use thonny ide.
Visit the MicroPython download page and download the latest esp8266/esp32 firmware.
Use a tool like esptool to flash the MicroPython firmware onto your esp8266/esp32. Here's a sample command:
esptool.py --chip esp8266/esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 firmware.bin
Replace /dev/ttyUSB0
with the correct port for your esp8266/esp32 device, and esp8266/esp3
with your actual device ESP32
or ESP8266
Use a tool like picocom or minicom to connect to your esp8266/esp32. For example:
picocom /dev/ttyUSB0 -b 115200
Replace /dev/ttyUSB0
with the correct port for your esp8266/esp32 device.
Edit the micropython file to configure your WiFi settings, DNS providers, and LED pin:
wifi_ssid = "your_wifi_ssid"
wifi_password = "your_wifi_password"
static_ip = "your_static_ip"
dns_providers_ipv4 = ["9.9.9.9", "149.112.112.112", "1.0.0.1","94.140.14.14", "1.1.1.1", "8.8.8.8"]
led_pin = machine.Pin(your_led_pin_number, machine.Pin.OUT)
Copy the DNS mixer code to your esp8266/esp32. You can use a tool like rshell or ampy for this. For example:
ampy -p /dev/ttyUSB0 put main.py
this will make the code to be executed on the next boot automaticaly.
note : dont forget to name it as main.py
on saving it into the device.
Now that your esp8266/esp32 is acting as a DNS provider, you can test DNS resolution from devices connected to the same network. Configure the DNS settings on your devices to use the static IP address you set for the esp8266/esp32 (your_static_ip
).
Observe the LED on the esp8266/esp32 for indications:
- Blink for 0.1 seconds on a new DNS request.
- Blink for half second on a failed DNS request.
- Blink three times fast when connected to the router.
Congratulations! You have successfully set up your esp8266/esp32 as a DNS provider using MicroPython. Feel free to explore the code and customize it further to suit your needs.