{"id":103157,"date":"2021-04-21T14:56:40","date_gmt":"2021-04-21T14:56:40","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=103157"},"modified":"2024-06-11T09:08:51","modified_gmt":"2024-06-11T09:08:51","slug":"esp32-set-custom-hostname-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-set-custom-hostname-arduino\/","title":{"rendered":"ESP32 Setting a Custom Hostname (Arduino IDE)"},"content":{"rendered":"\n<p>By default, the hostname of the ESP32 is <span class=\"rnthl rntliteral\">espressif<\/span>. In this guide, you&#8217;ll learn how to set a custom hostname for your board.<\/p>\n\n\n\n<p class=\"rntbox rntclgreen\">To set a custom hostname for your board, call <span class=\"rnthl rntliteral\">WiFi.setHostname(YOUR_NEW_HOSTNAME);<\/span> before <span class=\"rnthl rntliteral\">WiFi.begin();<\/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\/2021\/04\/ESP32-Set-Custom-Hostname.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Setting a Custom Hostname Arduino IDE\" class=\"wp-image-103168\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Set-Custom-Hostname.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Set-Custom-Hostname.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Set-Custom-Hostname.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Set-Custom-Hostname.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Setting an ESP32 Hostname<\/h2>\n\n\n\n<p>Usually, the default ESP32 hostname is <span class=\"rnthl rntliteral\">espressif<\/span> or a similar name.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"615\" height=\"29\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Default-Hostname-1.png?resize=615%2C29&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Default hostname router\" class=\"wp-image-158701\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Default-Hostname-1.png?w=615&amp;quality=100&amp;strip=all&amp;ssl=1 615w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Default-Hostname-1.png?resize=300%2C14&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/figure><\/div>\n\n\n<p>There is a method provided by the <span class=\"rnthl rntliteral\">WiFi.h<\/span> library that allows you to set a custom hostname. <\/p>\n\n\n\n<p>First, start by defining your new hostname. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* hostname = \"esp32-node-temperature\";<\/code><\/pre>\n\n\n\n<p>Then, call the <span class=\"rnthl rntliteral\">WiFi.setHostname()<\/span> function before calling <span class=\"rnthl rntliteral\">WiFi.begin()<\/span>. You also need to call <span class=\"rnthl rntliteral\">WiFi.config()<\/span> as shown below:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);\nWiFi.setHostname(hostname.c_str()); \/\/define hostname<\/code><\/pre>\n\n\n\n<p>You can copy the complete example below (don&#8217;t forget to insert your network credentials):<\/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-set-custom-hostname-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\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\/\/ Change the hostname\nconst char* hostname = &quot;esp32-node-temperature&quot;;\n\nvoid initWiFi() {\n  WiFi.mode(WIFI_STA);\n  WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);\n  WiFi.setHostname(hostname);\n\n  WiFi.begin(ssid, password);\n  Serial.print(&quot;Connecting to WiFi...&quot;);\n  while (WiFi.status() != WL_CONNECTED) {\n    Serial.print('.');\n    delay(1000);\n  }\n  \n  Serial.print(&quot;\\nESP32 IP Address: &quot;);\n  Serial.println(WiFi.localIP());\n  Serial.print(&quot;ESP32 HostName: &quot;);\n  Serial.println(WiFi.getHostname());\n  Serial.print(&quot;RRSI: &quot;);\n  Serial.println(WiFi.RSSI());\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  initWiFi();\n}\n\nvoid loop() {\n  \/\/ put your main code here, to run repeatedly:\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_Set_Hostname.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>You can use this previous snippet of code in your projects to set a custom hostname for the ESP32. On the Serial Monitor, you should get the new ESP32 hostname.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/06\/ESP32-Change-Set-Custom-Hostname-Arduino-IDE-Code.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"905\" height=\"504\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/06\/ESP32-Change-Set-Custom-Hostname-Arduino-IDE-Code.png?resize=905%2C504&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-158700\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/06\/ESP32-Change-Set-Custom-Hostname-Arduino-IDE-Code.png?w=905&amp;quality=100&amp;strip=all&amp;ssl=1 905w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/06\/ESP32-Change-Set-Custom-Hostname-Arduino-IDE-Code.png?resize=300%2C167&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/06\/ESP32-Change-Set-Custom-Hostname-Arduino-IDE-Code.png?resize=768%2C428&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 905px) 100vw, 905px\" \/><\/a><\/figure><\/div>\n\n\n<p class=\"rntbox rntcred\"><strong>Important: <\/strong> you may need to restart your router for the changes to take effect.<\/p>\n\n\n\n<p>After this, if you go to your router settings, you&#8217;ll see the ESP32 with the custom hostname.<\/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=\"615\" height=\"29\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-New-Hostname-Changed-Router.png?resize=615%2C29&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 set custom hostname\" class=\"wp-image-158699\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-New-Hostname-Changed-Router.png?w=615&amp;quality=100&amp;strip=all&amp;ssl=1 615w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-New-Hostname-Changed-Router.png?resize=300%2C14&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\"><strong>Note:<\/strong> some routers don&#8217;t allow you to change the ESP32 hostname using this method. If that&#8217;s your case, you&#8217;ll need to change it manually on the router&#8217;s administration panel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you&#8217;ve learned how to set up a custom hostname for your ESP32. This can be useful to identify the devices connected to your network easily. For example, if you have multiple ESP32 boards connected simultaneously, it will be easier to identify them if they have a custom hostname.<\/p>\n\n\n\n<p>For more Wi-Fi related functions, we recommend the following tutorials:<\/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-wifimulti\/\">ESP32 WiFiMulti: Connect to the Strongest Wi-Fi Network (from a list of networks)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/solved-reconnect-esp32-to-wifi\/\">[SOLVED] Reconnect ESP32 to Wi-Fi Network After Lost Connection<\/a><\/li>\n<\/ul>\n\n\n\n<p>We hope you\u2019ve 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<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">More ESP32 Projects and Tutorials\u2026<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>By default, the hostname of the ESP32 is espressif. In this guide, you&#8217;ll learn how to set a custom hostname for your board. To set a custom hostname for your &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32 Setting a Custom Hostname (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-set-custom-hostname-arduino\/#more-103157\" aria-label=\"Read more about ESP32 Setting a Custom Hostname (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":103168,"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-103157","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\/2021\/04\/ESP32-Set-Custom-Hostname.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/103157","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=103157"}],"version-history":[{"count":1,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/103157\/revisions"}],"predecessor-version":[{"id":158702,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/103157\/revisions\/158702"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/103168"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=103157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=103157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=103157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}