Movatterモバイル変換


[0]ホーム

URL:


Skip to content
HOMEESP32ESP8266ESP32-CAMRASPBERRY PIMICROPYTHONRPi PICOARDUINOREVIEWS

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();

ESP8266 NodeMCU Setting a Custom Hostname Arduino IDE

Setting an ESP8266 NodeMCU Hostname

The default ESP8266 hostname isESP-XXXXXX.

Setting ESP8266 Hostname

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:}

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.

ESP8266 Custom Hostname Serial Monitor Arduino IDE

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.

ESP8266 Custom Hostname Arduino IDE

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:

Thanks for reading.



SMART HOME with Raspberry Pi ESP32 and ESP8266 Node-RED InfluxDB eBook
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

11 thoughts on “ESP8266 NodeMCU Setting a Custom Hostname (Arduino IDE)”

  1. Thanks for your useful tutorials

    Reply
  2. thank you for great tutorials

    Reply
  3. The device list in router interface may require removing browser cookie for the router to show the changes.

    Reply
  4. I 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

    Reply
    • Did it work after restarting the router or just after uploading the code? I have many people working in an organization so cannot take risk to restart the router.

      Reply
  5. Doesn’t work with my ASUS router.

    Reply
  6. How can I set the hostname when using the ESP8266WiFiMulti.h library?

    Reply
  7. Doesn’t work with modem Archer VR1600v, tried reboot and clearing cookies. Connections name remains ‘Unknown’ but mac and ip are correct.

    Reply
  8. I tryed chance host name but code didnt work at my network.
    I try , start wifi begin and connect network after change the network name it worked.
    Thank you.

    Reply
  9. Many thanks for your useful tutorials, i learnt a lot from them.
    What if i use the wifiManger library to manage the wifi connection, how can i set the custom hostname?

    Reply
  10. work like charm witch macchange also after

    Reply

Leave a CommentCancel reply

Learn ESP8266

ESP8266 Introduction

ESP8266 Arduino IDE

ESP8266 Arduino IDE 2.0

VS Code and PlatformIO

ESP8266 Pinout

ESP8266 Inputs Outputs

ESP8266 PWM

ESP8266 Analog Inputs

ESP8266 Interrupts Timers

ESP8266 Deep Sleep

Protocols

ESP8266 Web Server

ESP8266 MQTT

ESP8266 ESP-NOW

ESP8266 Wi-Fi

ESP8266 WebSocket

ESP8266 ESP-MESH

ESP8266 Email

ESP8266 HTTP GET POST

HTTP GET Web APIs

HTTP POST Web APIs

ESP-NOW One-to-Many

ESP-NOW Many-to-One

ESP-NOW Two-Way

ESP-NOW ESP8266 + ESP32

ESP-NOW + Wi-Fi Web Server

Server-Sent Events

Web Servers

Output Web Server

PWM Slider Web Server

PWM Multiple Sliders Web Server

Async Web Server

Relay Web Server

DHT Web Server

BME280 Web Server

BME680 Web Server

DS18B20 Web Server

Plot/Chart Web Server

Chart Multiple Series Web Server

SPIFFS Web Server

Thermostat Web Server

Input Fields Web Server

Images Web Server

RGB LED Web Server

Momentary Switch Web Server

Physical Button Web Server

Timer/Pulse Web Server

Gauges Web Server

HTTP Auth Web Server

ESP8266 WiFiManager

Stepper Motor WebSocket

DIY Cloud

ESP8266 Weather Station

Control GPIOs

View Sensor Readings

ESP8266 MySQL

ESP8266 PHP Email

Cloud Node-RED Dashboard

Cloud MQTT Broker

Firebase

Firebase Realtime Database

Firebase Web App

Firebase Authentication

Firebase BME280

Firebase Web App Sensor Readings

Modules and Sensors

ESP8266 Relay Module

ESP8266 PIR

ESP8266 HC-SR04

ESP8266 AC PIR

ESP8266 Reed Switch

ESP8266 DHT11/DHT22

ESP8266 BME280

ESP8266 BME680

ESP8266 DS18B20

ESP8266 BMP388

ESP8266 Mains Voltage

ESP8266 Stepper Motor

ESP8266 I2C Multiplexer

Displays

ESP8266 OLED

ESP8266 LCD

ESP8266 Nextion

OLED Temperature

MQTT

ESP8266 MQTT

MQTT Output RPi

MQTT DHT RPi

MQTT SQLite RPi

MQTT DHT11/DHT22

MQTT BME280

MQTT BME680

MQTT DS18B20

ESP8266 MPU-6050

Other Projects

ESP8266 Alexa

ESP8266 Google Sheets

Multisensor Shield

Multisensor Shield Node-RED

ESP8266 Daily Task

ESP8266 Wi-Fi Button

Latching Power Circuit

Telegram Control Outputs

Telegram Sensor Readings

Telegram Detect Motion

Telegram Group

Telegram Door Monitor

ESP8266 WebSerial

Useful Guides

ESP8266 Troubleshooting

ESP8266 Access Point

ESP8266 Fixed IP Address

ESP8266 MAC Address

ESP8266 Reconnect Wi-Fi

ESP8266 Hostname

ESP8266 OTA

ESP8266 OTA Arduino

ESP8266 OTA VS Code

ESP8266 Solar Panels

ESP8266 Voltage Regulator

ESP8266 ThingSpeak

ESP8266 Install SPIFFS

ESP8266 Install LittleFS

ESP8266 Time and Date

ESP8266 Epoch Time

ESP8266 JSON

VS Code and PlatformIO

VS Code LittleFS

VS Code Workspaces

Learn More

Learn ESP32

Learn ESP8266

Learn ESP32-CAM

Learn MicroPython

Learn Arduino

Build Web Servers eBook

ESP8266 eBook »

Affiliate Disclosure:Random Nerd Tutorials is a participant in affiliate advertising programs designed to provide a means for us to earn fees by linking to Amazon, eBay, AliExpress, and other sites. We might be compensated for referring traffic and business to these companies.



Learn ESP32 with Arduino IDE eBook » Complete guide to program the ESP32 with Arduino IDE!



SMART HOME with Raspberry Pi, ESP32, and ESP8266 » learn how to build a complete home automation system.



Learn Raspberry Pi Pico/Pico W with MicroPython​ » The complete getting started guide to get the most out of the the Raspberry Pi Pico/Pico W (RP2040) microcontroller board using MicroPython programming language.



🔥 Learn LVGL: Build GUIs for ESP32 Projects​ » Learn how to build Graphical User Interfaces (GUIs) for ESP32 Projects using LVGL (Light Versatile Graphics Library) with the Arduino IDE.

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.


[8]ページ先頭

©2009-2025 Movatter.jp