ESP32 Setting A Custom Hostname (Arduino IDE)
Maybe your like
By default, the hostname of the ESP32 is espressif. In this guide, you’ll learn how to set a custom hostname for your board.
To set a custom hostname for your board, call WiFi.setHostname(YOUR_NEW_HOSTNAME); before WiFi.begin();

Setting an ESP32 Hostname
Usually, the default ESP32 hostname is espressif or a similar name.

There is a method provided by the WiFi.h library that allows you to set a custom hostname.
First, start by defining your new hostname. For example:
const char* hostname = "esp32-node-temperature";Then, call the WiFi.setHostname() function before calling WiFi.begin(). You also need to call WiFi.config() as shown below:
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); WiFi.setHostname(hostname.c_str()); //define hostnameYou can copy the complete example below (don’t forget to insert your network credentials):
/* Rui Santos & Sara Santos - Random Nerd Tutorials Complete project details at https://RandomNerdTutorials.com/esp32-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 <WiFi.h> // Replace with your network credentials const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Change the hostname const char* hostname = "esp32-node-temperature"; void initWiFi() { WiFi.mode(WIFI_STA); WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); WiFi.setHostname(hostname); WiFi.begin(ssid, password); Serial.print("Connecting to WiFi..."); while (WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(1000); } Serial.print("\nESP32 IP Address: "); Serial.println(WiFi.localIP()); Serial.print("ESP32 HostName: "); Serial.println(WiFi.getHostname()); Serial.print("RRSI: "); Serial.println(WiFi.RSSI()); } void setup() { Serial.begin(115200); initWiFi(); } void loop() { // put your main code here, to run repeatedly: }View raw code
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.

Important: you may need to restart your router for the changes to take effect.
After this, if you go to your router settings, you’ll see the ESP32 with the custom hostname.

Note: some routers don’t allow you to change the ESP32 hostname using this method. If that’s your case, you’ll need to change it manually on the router’s administration panel.
Wrapping Up
In this tutorial, you’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.
For more Wi-Fi related functions, we recommend the following tutorials:
- ESP32 Useful Wi-Fi Library Functions (Arduino IDE)
- ESP32 WiFiMulti: Connect to the Strongest Wi-Fi Network (from a list of networks)
- [SOLVED] Reconnect ESP32 to Wi-Fi Network After Lost Connection
We hope you’ve found this tutorial useful.
Learn more about the ESP32 with our resources:
- Learn ESP32 with Arduino IDE
- Build Web Servers with ESP32 and ESP8266
- More ESP32 Projects and Tutorials…
Tag » Arduino Wifi Device Name
-
ESP8266 NodeMCU 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