Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home IoT & Smart Home

mDNS on ESP32: Local Network Device Discovery Setup

mDNS on ESP32: Local Network Device Discovery Setup

March 11, 2026 /Posted byJayesh Jain / 0

Setting up mDNS on ESP32 for local network device discovery is one of the most practical skills any IoT developer can learn. Instead of hunting down your ESP32’s IP address every time it reconnects to Wi-Fi, mDNS (Multicast DNS) lets you access it using a friendly hostname like esp32sensor.local — from any browser or app on the same network. This tutorial covers everything from the basics of mDNS to a full working example with a web server and OTA updates, written specifically for the Indian maker community.

Table of Contents

  1. What is mDNS and How Does It Work?
  2. Hardware Setup for This Tutorial
  3. Basic mDNS Setup on ESP32 with Arduino
  4. Combining mDNS with ESP32 Web Server
  5. Using mDNS for OTA (Over-the-Air) Updates
  6. Advanced: mDNS Service Discovery for Multiple Devices
  7. Frequently Asked Questions

What is mDNS and How Does It Work?

mDNS stands for Multicast DNS, defined in RFC 6762. It is a zero-configuration networking protocol that resolves hostnames to IP addresses within a local network without the need for a central DNS server. When your ESP32 announces itself as mydevice.local, it broadcasts this name on the local network using multicast UDP packets on port 5353. Any other device on the same network — your phone, laptop, or Raspberry Pi — can then resolve mydevice.local to the ESP32’s IP address automatically.

mDNS is part of the broader Zeroconf ecosystem that also includes:

  • DNS-SD (DNS Service Discovery): Advertises services (HTTP, SSH, MQTT) alongside hostnames
  • Link-Local Addressing: Assigns IPs in the 169.254.x.x range when no DHCP server is present
  • Bonjour: Apple’s implementation of mDNS + DNS-SD (pre-installed on macOS)
  • Avahi: The Linux equivalent of Bonjour

On Windows 10 and later, mDNS is supported natively. On Android, you may need the Network Discovery feature or a third-party app like Service Browser. This is an important consideration for Indian developers building consumer IoT products targeted at Android users.

Hardware Setup for This Tutorial

You need minimal hardware for this tutorial since mDNS is a software feature:

  • Any ESP32 development board
  • Micro USB or USB-C cable for programming
  • 2.4 GHz Wi-Fi router
  • Optionally: a DHT11/DHT20 sensor to serve live data from the web server
Ai Thinker ESP32-C3-01M Wi-Fi + BLE Module

Ai Thinker ESP32-C3-01M Wi-Fi + BLE Module

A compact ESP32-C3 module with Wi-Fi and Bluetooth — ideal for mDNS-based local discovery projects where small form factor matters.

View on Zbotic

Basic mDNS Setup on ESP32 with Arduino

The ESP32 Arduino core includes the ESPmDNS library out of the box — no additional installation is needed. Here is the minimal code to get your ESP32 discoverable on the local network:

#include <WiFi.h>
#include <ESPmDNS.h>

const char* ssid     = "YourWiFiSSID";
const char* password = "YourWiFiPassword";
const char* hostname = "esp32sensor"; // Access at esp32sensor.local

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("nConnected! IP: " + WiFi.localIP().toString());

  if (!MDNS.begin(hostname)) {
    Serial.println("Error starting mDNS");
    return;
  }
  Serial.println("mDNS started: http://" + String(hostname) + ".local");
}

void loop() {}

After uploading and rebooting, open a browser on any device on the same Wi-Fi network and type http://esp32sensor.local. You will reach the ESP32 without knowing its IP address. This works on macOS, iOS, Windows 10+, and most Linux distributions immediately.

Important Notes:

  • The hostname must be unique on the network. If two ESP32s share the same hostname, mDNS resolution becomes unreliable.
  • mDNS only works on the local network (LAN). It does not work over the internet or across different subnets.
  • If your router has multicast isolation or AP isolation enabled (common on Indian ISP routers), mDNS packets will be blocked. Disable these settings if mDNS discovery fails.

Combining mDNS with ESP32 Web Server

The real power of mDNS comes when you combine it with an ESP32 web server. Users can open http://esp32sensor.local in their browser and see a live dashboard of sensor readings — no app installation required.

#include <WiFi.h>
#include <ESPmDNS.h>
#include <WebServer.h>
#include <DHT.h>

#define DHTPIN  4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
WebServer server(80);

void handleRoot() {
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  String html = "<h1>ESP32 Sensor</h1>";
  html += "<p>Temperature: " + String(t) + " &deg;C</p>";
  html += "<p>Humidity: " + String(h) + "%</p>";
  server.send(200, "text/html", html);
}

void setup() {
  dht.begin();
  WiFi.begin("SSID", "PASSWORD");
  while (WiFi.status() != WL_CONNECTED) delay(500);
  MDNS.begin("esp32sensor");
  MDNS.addService("http", "tcp", 80); // Advertise HTTP service
  server.on("/", handleRoot);
  server.on("/data", []() {
    String json = "{"temp":" + String(dht.readTemperature()) +
                  ","hum":" + String(dht.readHumidity()) + "}";
    server.send(200, "application/json", json);
  });
  server.begin();
}

void loop() { server.handleClient(); }

The MDNS.addService("http", "tcp", 80) call is crucial — it advertises the HTTP service via DNS-SD, allowing apps like Bonjour Browser to discover the web interface automatically without knowing the hostname in advance.

DHT11 Temperature and Humidity Sensor with LED

DHT11 Temperature And Humidity Sensor Module with LED

This DHT11 module comes with a built-in LED indicator, making it easy to see when data is being read — great for the mDNS web server project.

View on Zbotic

Using mDNS for OTA (Over-the-Air) Updates

One of the best uses of mDNS with ESP32 is enabling OTA firmware updates. The ArduinoOTA library uses mDNS internally to advertise the device to the Arduino IDE. Once configured, you can upload new firmware wirelessly — no USB cable needed.

#include <ArduinoOTA.h>
// (WiFi.begin and MDNS.begin as before)

void setupOTA() {
  ArduinoOTA.setHostname("esp32sensor"); // Same as mDNS hostname
  ArduinoOTA.setPassword("admin123");    // Protect OTA with a password
  ArduinoOTA.onStart([]() { Serial.println("OTA Start"); });
  ArduinoOTA.onEnd([]()   { Serial.println("OTA End"); });
  ArduinoOTA.begin();
}

void loop() {
  ArduinoOTA.handle(); // Must be called in loop
  server.handleClient();
}

In the Arduino IDE, go to Tools → Port and you will see esp32sensor.local listed as a network port once the ESP32 is running. Select it and upload as normal. This is extremely useful in India where physical access to deployed devices (e.g., ceiling-mounted sensors in a factory) is difficult.

Advanced: mDNS Service Discovery for Multiple Devices

When you have multiple ESP32 devices on the same network, mDNS service discovery lets you find all of them programmatically. This is the foundation of self-configuring IoT networks used in smart home installations.

// On a central ESP32 or Raspberry Pi — discover all HTTP services
int n = MDNS.queryService("http", "tcp");
for (int i = 0; i < n; i++) {
  Serial.printf("Device %d: %s at %s:%dn",
    i, MDNS.hostname(i).c_str(),
    MDNS.IP(i).toString().c_str(),
    MDNS.port(i));
}

This approach is used in home automation systems where a central coordinator (like a Raspberry Pi running Home Assistant) automatically discovers and registers new ESP32 sensor nodes without manual IP configuration — a huge advantage over static IP setups common in older IoT designs.

DHT20 SIP Packaged Temperature and Humidity Sensor

DHT20 SIP Packaged Temperature and Humidity Sensor

The DHT20 uses I2C instead of single-wire, making it easier to add multiple sensors to a single ESP32 node in a multi-device mDNS network.

View on Zbotic

Frequently Asked Questions

Does mDNS work on Android smartphones?

Android supports mDNS for some system services, but browser-based .local hostname resolution was added in Android 12+. For older Android devices, use the Network Scanner app or build a Bluetooth/BLE discovery mechanism as an alternative for consumer-facing products.

Why does esp32sensor.local not resolve on my Windows PC?

Windows requires the Bonjour service (installed with iTunes or Apple devices) or the built-in mDNS responder introduced in Windows 10 version 1803. Make sure your Windows is updated. Also confirm that your firewall is not blocking UDP port 5353.

Can I use mDNS on ESP32 without Wi-Fi (e.g., Ethernet)?

Yes. mDNS works on any IP-based network interface. If you add a W5500 Ethernet module to your ESP32, you can run mDNS over Ethernet using the same ESPmDNS library with the appropriate network interface initialisation.

How many mDNS services can one ESP32 advertise?

There is no hard limit in the ESPmDNS library. In practice, advertising 3–5 services (HTTP, MQTT, OTA, custom) on a single ESP32 works reliably. Beyond that, you may see increased multicast traffic impacting network performance on congested Wi-Fi networks.

Build Your Local IoT Network Today

Find the ESP32 boards, sensors, and expansion modules you need at Zbotic.in — shipped fast across all major Indian cities.

Shop IoT Components on Zbotic

Tags: Arduino, Device Discovery, ESP32, Local Network, mDNS
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
ESP32 Wroom vs Wrover: Flash a...
blog esp32 wroom vs wrover flash and psram differences explained 595385
blog esp32 deep sleep long battery life for remote sensors 595389
ESP32 Deep Sleep: Long Battery...

Related posts

Svg%3E
Read more

IoT Home Insurance Sensor Kit: Leak, Smoke, and Motion

April 1, 2026 0
Table of Contents IoT and Home Insurance Water Leak Detection Smoke and Fire Detection Motion and Intrusion Sensing Building the... Continue reading
Svg%3E
Read more

IoT Pet Tracker: GPS Collar with Geofencing Alerts

April 1, 2026 0
Table of Contents Introduction and Overview Hardware Components Required GPS Module Integration with ESP32 Cloud Platform Setup Real-Time Tracking Dashboard... Continue reading
Svg%3E
Read more

IoT Aquaponics Controller: Fish and Plant Automation

April 1, 2026 0
Table of Contents The Water Monitoring Challenge in India Sensor Technologies for Water Building the Sensor Node Data Transmission and... Continue reading
Svg%3E
Read more

IoT Composting Monitor: Temperature and Moisture Tracking

April 1, 2026 0
Table of Contents Why Temperature Monitoring Matters Sensor Selection Guide Hardware Assembly and Wiring Firmware Development Cloud Data Logging Alert... Continue reading
Svg%3E
Read more

IoT Beehive Monitor: Weight, Temperature, and Humidity

April 1, 2026 0
Table of Contents Why Monitor Beehives Weight Measurement System Temperature and Humidity Sensing Building the Monitor Data Analysis for Bee... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now