ESP8266 NodeMCU Setting A Custom Hostname (Arduino IDE)
Maybe your like
By default, the hostname of an ESP8266 NodeMCU board is ESP-XXXXXX where the Xs represents the last six characters of its MAC address. In this tutorial, you’ll learn how to set a custom hostname for your board.
To set a custom hostname for your board, call WiFi.hostname(YOUR_NEW_HOSTNAME); before WiFi.begin();

Setting an ESP8266 NodeMCU Hostname
The default ESP8266 hostname is ESP-XXXXXX.

There is a method provided by the ESP8266WiFi.h library that allows you to set a custom hostname.
First, start by defining your new hostname. For example:
String newHostname = "ESP8266Node";Then, call the WiFi.hostname() function before calling WiFi.begin().
WiFi.hostname(newHostname.c_str());You can copy the complete example below:
/* Rui Santos Complete project details at https://RandomNerdTutorials.com/esp8266-nodemcu-set-custom-hostname-arduino/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ #include <ESP8266WiFi.h> // Replace with your network credentials (STATION) const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD"; String newHostname = "ESP8266Node"; void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); //Get Current Hostname Serial.printf("Default hostname: %s\n", WiFi.hostname().c_str()); //Set new hostname WiFi.hostname(newHostname.c_str()); //Get Current Hostname Serial.printf("New hostname: %s\n", WiFi.hostname().c_str()); //Init Wi-Fi WiFi.begin(ssid, password); Serial.print("Connecting to WiFi .."); while (WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(1000); } Serial.println(WiFi.localIP()); Serial.print("RRSI: "); Serial.println(WiFi.RSSI()); } void loop() { // put your main code here, to run repeatedly: }View raw code
After uploading the code to your board, open the Serial Monitor at a baud rate of 115200.
It should print the previous hostname and the new hostname.

You can use this previous snippet of code in your projects to set a custom hostname to the ESP8266 NodeMCU boards.
Important: you may need to restart your router for the changes to take effect on the router settings.
After this, if you go to your router settings, you’ll see the ESP8266 with the custom hostname.

Wrapping Up
In this tutorial, you’ve learned how to set up a custom hostname for your ESP8266 NodeMCU boards. This can be useful to identify the devices connected to your network easily. For example, if you have multiple boards connected simultaneously, it will be easier to identify them if they have a custom hostname.
We hope you’ve found this tutorial useful.
Learn more about the ESP8266 with our resources:
- Build ESP8266 Web Servers with Arduino IDE (eBook)
- Home Automation using ESP8266
- More ESP8266 Projects and Tutorials…
Thanks for reading.
Tag » Arduino Wifi Device Name
-
ESP32 Setting A Custom Hostname (Arduino IDE)
-
Setting ESP32 Custom Hostname With Arduino IDE
-
ESP32 Hostname - Français - Arduino Forum
-
WiFiNINA - tHostname() - Arduino Reference
-
Getting Started With The Arduino Uno WiFi
-
WiFiNINA - Arduino Reference
-
How To Set ESP32 Custom Hostname Using Arduino IDE?
-
How To Set Host Name? · Issue #2826 · Esp8266/Arduino - GitHub
-
ESP32 Arduino: Getting Station Interface Hostname - Techtutorialsx
-
ESP32 Fails On Set Wifi Hostname - Stack Overflow
-
Change The Name Of The Device In STA Mode - ESP32 Forum
-
ESP8266WiFi Library - ESP8266 Arduino Core Documentation
-
Get Started With The Arduino MKR WiFi 1010 - AllThingsTalk
-
ESP8266 - Wikipedia