ESP8266 NodeMCU Setting a Custom Hostname (Arduino IDE)
By default, the hostname of an ESP8266 NodeMCU board isESP-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, callWiFi.hostname(YOUR_NEW_HOSTNAME); beforeWiFi.begin();

Setting an ESP8266 NodeMCU Hostname
The default ESP8266 hostname isESP-XXXXXX.

There is a method provided by theESP8266WiFi.h library that allows you to set a custom hostname.
First, start by defining your new hostname. For example:
String newHostname = "ESP8266Node";Then, call theWiFi.hostname() function before callingWiFi.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:}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.

Recommended Resources
Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.
Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.
Arduino Step-by-Step Projects »Build 25 Arduino projects with our course, even with no prior experience!
What to Read Next…
Enjoyed this project? Stay updated by subscribing our newsletter!
11 thoughts on “ESP8266 NodeMCU Setting a Custom Hostname (Arduino IDE)”
Thanks for your useful tutorials
Replythank you for great tutorials
ReplyThe device list in router interface may require removing browser cookie for the router to show the changes.
ReplyI copy pasted the code, tried it and it works, but when I scan the network there is a dot (.) added to the end of the hostname and I have to put that dot to access the ESP8266. Am I the only one with that issue and how can I solve it ?
Thank you
ReplyDoesn’t work with my ASUS router.
ReplyHow can I set the hostname when using the ESP8266WiFiMulti.h library?
ReplyDoesn’t work with modem Archer VR1600v, tried reboot and clearing cookies. Connections name remains ‘Unknown’ but mac and ip are correct.
ReplyI tryed chance host name but code didnt work at my network.
Reply
I try , start wifi begin and connect network after change the network name it worked.
Thank you.Many thanks for your useful tutorials, i learnt a lot from them.
Reply
What if i use the wifiManger library to manage the wifi connection, how can i set the custom hostname?work like charm witch macchange also after
Reply









