WiFi Set Hostname
#include <WiFi.h>
Intro Setting an ESP32 HostName Example Wrapping Up

ESP32 Setting a Custom Hostname Arduino IDE

Setting an ESP32 Hostname
The default ESP32 hostname is espressif. 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: String 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 hostname You can copy the complete example below:
Example
/*H******************************************************* Rui Santos 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> //************************* DEFINES ************************************ //************************* PROTOTYPES ************************************ void initWiFi(); //************************* VARIABLES ************************************ // REPLACE WITH YOUR NETWORK CREDENTIALS (STATION) const char *ssid = "REPLACE_WITH_YOUR_SSID"; const char *password = "REPLACE_WITH_YOUR_PASSWORD"; String hostname = "ESP32 Node Temperature"; /*F******************************************************************** * **********************************************************************/ void setup() { Serial.begin( BAUD ); initWiFi(); Serial.print( "RRSI: " ); Serial.println( WiFi.RSSI() ); } /*F******************************************************************** * **********************************************************************/ void loop() { // put your main code here, to run repeatedly: } /*F******************************************************************** * **********************************************************************/ void initWiFi() { WiFi.mode( WIFI_STA ); WiFi.config( INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); WiFi.setHostname( hostname.c_str()); // define hostname // wifi_station_set_hostname( hostname.c_str() ); WiFi.begin( ssid, password ); Serial.print( "Connecting to WiFi .." ); while( WiFi.status() != WL_CONNECTED) { Serial.print( '.' ); delay( 1000 ); } Serial.println( WiFi.localIP() ); } You can use this previous snippet of code in your projects to set a custom hostname for the ESP32. 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. ESP32 Custom Hostname setting Arduino IDE
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 reading the following tutorial: ESP32 Useful Wi-Fi Library Functions (Arduino IDE)