{"id":182870,"date":"2026-01-08T11:11:39","date_gmt":"2026-01-08T11:11:39","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=182870"},"modified":"2026-01-08T11:27:27","modified_gmt":"2026-01-08T11:27:27","slug":"esp32-mdns-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-mdns-arduino\/","title":{"rendered":"ESP32: Set Up mDNS (Arduino IDE)"},"content":{"rendered":"\n<p>Learn how to set up Multicast DNS (mDNS) on your ESP32 programmed with the Arduino IDE. mDNS lets you refer to your ESP32 using a user-friendly name instead of its IP address. For instance, instead of having to type the ESP32 IP address to access a web server in your browser on your local network, you can simply use something like <span class=\"rnthl rntliteral\">http:\/\/esp32.local<\/span>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Set Up mDNS Arduino IDE\" class=\"wp-image-182963\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<div class=\"wp-block-group rntbox rntclgray\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p><strong>Recommended reading: <\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-useful-wi-fi-functions-arduino\/\">ESP32 Useful Wi-Fi Library Functions (Arduino IDE)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-web-server-beginners-guide\/\">Building an ESP32 Web Server: The Complete Guide for Beginners<\/a><\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">What is mDNS?<\/h2>\n\n\n\n<p>mDNS, or Multicast DNS, allows you to assign specific names to devices on your local network,  each associated with its specific IP address. This way, you can refer to them via that name instead of the IP address.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">mDNS for the ESP32<\/h3>\n\n\n\n<p>This way, instead of having to remember the specific IP addresses of several of your ESP32 boards on your network, you can simply give a name to each of them, for example <span class=\"rnthl rntliteral\">esp32-room<\/span>, <span class=\"rnthl rntliteral\">esp32-lights<\/span>. Then, you can access them on your network using <span class=\"rnthl rntliteral\">http:\/\/esp32-room.local<\/span>, for example, instead of having to memorize or write down the specific IP address for each board.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Set Up mDNS on an ESP32 (Arduino IDE)?<\/h2>\n\n\n\n<p>Setting up mDNS on an ESP32 programmed with Arduino IDE is quite simple and only requires you to add a few lines to your existing code.<\/p>\n\n\n\n<p><strong>1) <\/strong>First, include the <span class=\"rnthl rntliteral\">ESPmDNS<\/span> library.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;ESPmDNS.h&gt;<\/code><\/pre>\n\n\n\n<p><strong>2)<\/strong> In the <span class=\"rnthl rntliteral\">setup()<\/span> of your code, after connecting to your network, set mDNS using the following lines. Pass the hostname you want to the <span class=\"rnthl rntliteral\">begin()<\/span> function\u2014the one that will be used in the URL when you access an ESP32 web server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (!MDNS.begin(mdnsName)) {\n  Serial.println(\"Error setting up MDNS responder!\");\n  while(1) {\n    delay(1000);\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>3)<\/strong> Finally, advertise your ESP32&#8217;s HTTP web service (on TCP port 80).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>MDNS.addService(\"_http\", \"_tcp\", 80);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">ESP32 Web Server with mDNS<\/h2>\n\n\n\n<p>To show you how to implement mDNS, we&#8217;ll show you a basic &#8220;Hello World&#8221; web server with this feature implemented.<\/p>\n\n\n\n<p>To access this web server on your browser, instead of having to type your ESP32 IP address, you can type <span class=\"rnthl rntliteral\">http:\/\/myesp32.local<\/span><\/p>\n\n\n\n<p>Here&#8217;s the example code.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-mdns-arduino\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n#include &lt;WiFi.h&gt;\n#include &lt;WebServer.h&gt;\n#include &lt;ESPmDNS.h&gt;\n\n\/\/ Replace with your network credentials\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\n\n\/\/ mDNS name (customize this as needed)\nconst char* mdnsName = &quot;myesp32&quot;;\n\n\/\/ Create a web server object\nWebServer server(80);\n\n\/\/ Function to handle the root URL\nvoid handleRoot() {\n  String html = &quot;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;meta name=\\&quot;viewport\\&quot; content=\\&quot;width=device-width, initial-scale=1\\&quot;&gt;&quot;;\n  html += &quot;&lt;link rel=\\&quot;icon\\&quot; href=\\&quot;data:,\\&quot;&gt;&quot;;\n  html += &quot;&lt;style&gt;&quot;;\n  html += &quot;body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: white; color: #333; margin: 20px; }&quot;;\n  html += &quot;h1 { color: #4a5568; font-weight: 300; }&quot;;\n  html += &quot;&lt;\/style&gt;&lt;\/head&gt;&quot;;\n  html += &quot;&lt;body&gt;&quot;;\n  html += &quot;&lt;h1&gt;Hello World&lt;\/h1&gt;&quot;;\n  html += &quot;&lt;p&gt;ESP32 mDNS Demo.&lt;\/p&gt;&quot;;\n  html += &quot;&lt;\/body&gt;&lt;\/html&gt;&quot;;\n  server.send(200, &quot;text\/html&quot;, html);\n}\n\nvoid setup() {\n  Serial.begin(115200);\n\n  \/\/ Connect to Wi-Fi network\n  Serial.print(&quot;Connecting to &quot;);\n  Serial.println(ssid);\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(&quot;.&quot;);\n  }\n  Serial.println(&quot;&quot;);\n  Serial.println(&quot;WiFi connected.&quot;);\n  Serial.println(&quot;IP address: &quot;);\n  Serial.println(WiFi.localIP());\n\n  \/\/ Set mDNS\n  if (!MDNS.begin(mdnsName)) {\n    Serial.println(&quot;Error setting up MDNS responder!&quot;);\n    while(1) {\n      delay(1000);\n    }\n  }\n\n  \/\/ Add service to MDNS-SD\n  MDNS.addService(&quot;_http&quot;, &quot;_tcp&quot;, 80);\n  Serial.println(&quot;mDNS responder started. Access your ESP32 at http:\/\/&quot; + String(mdnsName) + &quot;.local&quot;);\n\n\n  \/\/ Set up the web server to handle route\n  server.on(&quot;\/&quot;, handleRoot);\n\n  \/\/ Start the web server\n  server.begin();\n  Serial.println(&quot;HTTP server started&quot;);\n}\n\nvoid loop() {\n  \/\/ Handle incoming client requests\n  server.handleClient();\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_mDNS.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How Does the Code Work?<\/h3>\n\n\n\n<p>To keep things simple, we&#8217;re creating the web server using the ESP32 core&#8217;s built-in <span class=\"rnthl rntliteral\">WebServer<\/span> library.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;WebServer.h&gt;<\/code><\/pre>\n\n\n\n<p>We already explained in great detail how to build simple web servers using that library in the following tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-web-server-beginners-guide\/\">Building an ESP32 Web Server: The Complete Guide for Beginners<\/a><\/li>\n<\/ul>\n\n\n\n<p>So, we&#8217;ll just explain the relevant parts of the code for this tutorial.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Including the mDNS Library<\/h4>\n\n\n\n<p>As we mentioned previously, you need to include the <span class=\"rnthl rntliteral\">ESPmDNS<\/span> library.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;ESPmDNS.h&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Network Credentials<\/h4>\n\n\n\n<p>Insert your network credentials on the following lines so that the ESP32 can connect to your local network.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">mDNS Hostname<\/h4>\n\n\n\n<p>Add your desired hostname. In our case, we&#8217;re calling it <span class=\"rnthl rntliteral\">myesp32<\/span>, but you can give a different name.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* mdnsName = \"myesp32\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Set Up mDNS<\/h4>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, after initializing Wi-Fi and printing the board&#8217;s IP address&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Connect to Wi-Fi network\nSerial.print(\"Connecting to \");\nSerial.println(ssid);\nWiFi.begin(ssid, password);\nwhile (WiFi.status() != WL_CONNECTED) {\n  delay(500);\n  Serial.print(\".\");\n}\nSerial.println(\"\");\nSerial.println(\"WiFi connected.\");\nSerial.println(\"IP address: \");\nSerial.println(WiFi.localIP());<\/code><\/pre>\n\n\n\n<p>&#8230;We set mDNS using the following lines of code:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set mDNS\nif (!MDNS.begin(mdnsName)) {\n  Serial.println(\"Error setting up MDNS responder!\");\n  while(1) {\n    delay(1000);\n  }\n}\n\n\/\/ Add service to MDNS-SD\nMDNS.addService(\"_http\", \"_tcp\", 80);\nSerial.println(\"mDNS responder started. Access your ESP32 at http:\/\/\" + String(mdnsName) + \".local\");<\/code><\/pre>\n\n\n\n<p>And that&#8217;s it. You can use this method for any of your IoT projects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Demonstration<\/h3>\n\n\n\n<p>Upload the previous code to your ESP32 board. Then, open the Serial Monitor at a baud rate of 115200 and press the ESP32 RST button so that it starts running the code.<\/p>\n\n\n\n<p>It will print the board IP address and the link to access the web server using the hostname you&#8217;ve given in the code. In my case, I&#8217;ll access the ESP32 web server at <strong><span class=\"rnthl rntliteral\">http:\/\/myesp32.local<\/span><\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"703\" height=\"251\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS-Serial-Monitor.png?resize=703%2C251&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Serial Monitor - mDNS hostname\" class=\"wp-image-182957\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS-Serial-Monitor.png?w=703&amp;quality=100&amp;strip=all&amp;ssl=1 703w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS-Serial-Monitor.png?resize=300%2C107&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><\/figure><\/div>\n\n\n<p>Open a browser on your local network, and type <span class=\"rnthl rntliteral\">http:\/\/myesp32.local<\/span>, or any other name you&#8217;ve given (you need to add the <span class=\"rnthl rntliteral\">.local<\/span> at the end), and you should get access to the web server.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"661\" height=\"352\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/accessing-ESP32-Web-Server-mDNS.jpg?resize=661%2C352&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 mDNS web server example\" class=\"wp-image-182958\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/accessing-ESP32-Web-Server-mDNS.jpg?w=661&amp;quality=100&amp;strip=all&amp;ssl=1 661w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/accessing-ESP32-Web-Server-mDNS.jpg?resize=300%2C160&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/figure><\/div>\n\n\n<p>This is just a simple web server for testing purposes, but this can be applied to any other web servers, web apps, and so on.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Multiple Devices with Same Hostname<\/h3>\n\n\n\n<p>When using the <span class=\"rnthl rntliteral\">ESPmDNS<\/span> library, if you give the same hostname as a device that already exists on the local network, the library will automatically handle that and add a suffix to the name. For example, if <span class=\"rnthl rntliteral\">esp32.local<\/span> already exists, it will rename it to <span class=\"rnthl rntliteral\">esp32-2.local<\/span>, and so on. The library does this in the background.<\/p>\n\n\n\n<p>To know what the actual hostname given to the device is, we need to use more low-level functions like <span class=\"rnthl rntliteral\">mdns_hostname_get()<\/span> included in the <span class=\"rnthl rntliteral\">mdns.h<\/span> library from ESP-IDF.<\/p>\n\n\n\n<p>The following code is similar to the previous example, but it uses the <span class=\"rnthl rntliteral\">mdns_hostname_get()<\/span> function to get the actual hostname given to the device. This is useful if you happen to mistakenly give the same hostname to multiple devices or if there is already another device with the same name on the network.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-mdns-arduino\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n#include &lt;WiFi.h&gt;\n#include &lt;WebServer.h&gt;\n#include &lt;ESPmDNS.h&gt;\n#include &lt;mdns.h&gt;     \/\/ For low-level mDNS functions from ESP-IDF\n\n\/\/ Replace with your network credentials\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\n\n\/\/ mDNS name (customize this as needed)\nconst char* mdnsName = &quot;myesp32&quot;;\n\n\/\/ Create a web server object\nWebServer server(80);\n\n\/\/ Function to handle the root URL\nvoid handleRoot() {\n  String html = &quot;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;meta name=\\&quot;viewport\\&quot; content=\\&quot;width=device-width, initial-scale=1\\&quot;&gt;&quot;;\n  html += &quot;&lt;link rel=\\&quot;icon\\&quot; href=\\&quot;data:,\\&quot;&gt;&quot;;\n  html += &quot;&lt;style&gt;&quot;;\n  html += &quot;body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: white; color: #333; margin: 20px; }&quot;;\n  html += &quot;h1 { color: #4a5568; font-weight: 300; }&quot;;\n  html += &quot;&lt;\/style&gt;&lt;\/head&gt;&quot;;\n  html += &quot;&lt;body&gt;&quot;;\n  html += &quot;&lt;h1&gt;Hello World&lt;\/h1&gt;&quot;;\n  html += &quot;&lt;p&gt;ESP32 mDNS Demo.&lt;\/p&gt;&quot;;\n  html += &quot;&lt;\/body&gt;&lt;\/html&gt;&quot;;\n  server.send(200, &quot;text\/html&quot;, html);\n}\n\nvoid setup() {\n  Serial.begin(115200);\n\n  \/\/ Connect to Wi-Fi network\n  Serial.print(&quot;Connecting to &quot;);\n  Serial.println(ssid);\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(&quot;.&quot;);\n  }\n  Serial.println(&quot;&quot;);\n  Serial.println(&quot;WiFi connected.&quot;);\n  Serial.println(&quot;IP address: &quot;);\n  Serial.println(WiFi.localIP());\n\n  \/\/ Set mDNS\n  if (!MDNS.begin(mdnsName)) {\n    Serial.println(&quot;Error setting up MDNS responder!&quot;);\n    while(1) {\n      delay(1000);\n    }\n  }\n\n  delay(5000);\n\n  \/\/ Add service to MDNS\n  MDNS.addService(&quot;_http&quot;, &quot;_tcp&quot;, 80);\n\n  \/\/ Retrieve and print the actual (resolved) hostname - checking if there are any conflicts in the network\n  char actualHostname[MDNS_NAME_BUF_LEN];  \/\/ MDNS_NAME_BUF_LEN is 64 from mdns.h\n  esp_err_t err = mdns_hostname_get(actualHostname);\n  if (err == ESP_OK) {\n    String actualName = String(actualHostname);\n    Serial.println(&quot;mDNS responder started. Given name: &quot; + String(mdnsName));\n    Serial.println(&quot;Current hostname: http:\/\/&quot; + actualName + &quot;.local&quot;);\n    if (actualName != mdnsName) {\n      Serial.println(&quot;Hostname renamed.&quot;);\n    }\n  } else {\n    Serial.println(&quot;Failed to retrieve current hostname (error: &quot; + String(err) + &quot;)&quot;);\n  }\n\n  \/\/ Set up the web server to handle route\n  server.on(&quot;\/&quot;, handleRoot);\n\n  \/\/ Start the web server\n  server.begin();\n  Serial.println(&quot;HTTP server started&quot;);\n}\n\nvoid loop() {\n  \/\/ Handle incoming client requests\n  server.handleClient();\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_mDNS_Check_Conflicts.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How Does the Code Work?<\/h4>\n\n\n\n<p>In this code, we include the <span class=\"rnthl rntliteral\">mdns.h<\/span> library from ESP-IDF.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;mdns.h&gt;     \/\/ For low-level mDNS functions from ESP-IDF<\/code><\/pre>\n\n\n\n<p>After setting up mDNS on the ESP32, we use the <span class=\"rnthl rntliteral\">mdns_hostname_get()<\/span> function to get the actual hostname given to the device.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Retrieve and print the actual (resolved) hostname - checking if there are any conflicts in the network\nchar actualHostname&#091;MDNS_NAME_BUF_LEN];  \/\/ MDNS_NAME_BUF_LEN is 64 from mdns.h\nesp_err_t err = mdns_hostname_get(actualHostname);\nif (err == ESP_OK) {\n  String actualName = String(actualHostname);\n  Serial.println(\"mDNS responder started. Given name: \" + String(mdnsName));\n  Serial.println(\"Current hostname: http:\/\/\" + actualName + \".local\");\n  if (actualName != mdnsName) {\n    Serial.println(\"Hostname renamed.\");\n  }\n} else {\n  Serial.println(\"Failed to retrieve current hostname (error: \" + String(err) + \")\");\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Testing the Code<\/h4>\n\n\n\n<p>To test this code, you need to keep the previous code running on another board. Then, upload this new code to a different board.<\/p>\n\n\n\n<p>Since we&#8217;re trying to use the <span class=\"rnthl rntliteral\">myesp32<\/span> hostname that was already taken by the previous device, the library will automatically change the hostname to <span class=\"rnthl rntliteral\">myesp32-2<\/span>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"249\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-get-mDNS-hostname-Serial-Monitor.png?resize=666%2C249&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 get mDNS hostname and print in the Serial Monitor\" class=\"wp-image-183013\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-get-mDNS-hostname-Serial-Monitor.png?w=666&amp;quality=100&amp;strip=all&amp;ssl=1 666w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-get-mDNS-hostname-Serial-Monitor.png?resize=300%2C112&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/figure><\/div>\n\n\n<p>In the same way, you can access the web server on <span class=\"rnthl rntliteral\">http:\/\/myesp32-2.local<\/span> on your web browser.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"688\" height=\"332\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS-web-server-2.jpg?resize=688%2C332&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 mDNS web server\" class=\"wp-image-183014\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS-web-server-2.jpg?w=688&amp;quality=100&amp;strip=all&amp;ssl=1 688w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS-web-server-2.jpg?resize=300%2C145&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned how to use and set up mDNS on your ESP32 boards programmed with Arduino IDE. mDNS allows you to assign specific hostnames to your devices on your local network. This way, you can refer to them using the hostname, which is more user-friendly, rather than the IP address.<\/p>\n\n\n\n<p>Using the <span class=\"rnthl rntliteral\">mDNS.h<\/span> library, it is quite easy to add this feature to your ESP32 web server projects.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this tutorial useful.<\/p>\n\n\n\n<p>Learn more about the ESP32 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE (eBook)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">All our ESP32 Projects and Guides<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to set up Multicast DNS (mDNS) on your ESP32 programmed with the Arduino IDE. mDNS lets you refer to your ESP32 using a user-friendly name instead of its &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32: Set Up mDNS (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-mdns-arduino\/#more-182870\" aria-label=\"Read more about ESP32: Set Up mDNS (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":182963,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[276,281,277,299,264],"tags":[],"class_list":["post-182870","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-esp32-project","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/ESP32-mDNS.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/182870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=182870"}],"version-history":[{"count":10,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/182870\/revisions"}],"predecessor-version":[{"id":187014,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/182870\/revisions\/187014"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/182963"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=182870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=182870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=182870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}