ESP32 Setting a Custom Hostname (Arduino IDE) | Random Nerd Tutorials (2024)

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

ESP32 Setting a Custom Hostname (Arduino IDE) | Random Nerd Tutorials (1)

Setting an ESP32 Hostname

The default ESP32 hostname is espressif.

ESP32 Setting a Custom Hostname (Arduino IDE) | Random Nerd Tutorials (2)

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:

/* 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>// 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";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());}void setup() { Serial.begin(115200); initWiFi(); Serial.print("RRSI: "); Serial.println(WiFi.RSSI());}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.

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 Setting a Custom Hostname (Arduino IDE) | Random Nerd Tutorials (3)

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:

We hope you’ve found this tutorial useful.

Learn more about the ESP32 with our resources:

ESP32 Setting a Custom Hostname (Arduino IDE) | Random Nerd Tutorials (2024)
Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 6200

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.