Menu Close

Change the HostName of Raspberry Pi

Change hostname of a Raspberry Pi

You now are the proud owner of a Raspberry Pi and you have installed the OS.
It’s connected to your network and it still has its default name of raspberrypi.
It’s time for you to change this default Raspberry Pi Hostname by something unique on your network and meaningfull to you, such as OpenHABServer for my home automation Raspbery Pi.

This post may contain affiliate links.  If you make a purchase I may get a commission at no cost to you.  Please see the Disclaimer for additional information.

 

Equipment

Raspberry Pi 2 or Newer (2, 3, 3B+ or 4)
32GB MicroSD card (if you don’t buy a Raspberry Pi kit)
Keyboard (if not using SSH)
Mouse (if not using SSH)
USB Keyboard and mouse combo (if not using SSH)
HDMI Cable (if not using SSH, Raspberry Pi 3B+ and lower)
HDMI Adapter (if not using SSH, Raspberry Pi 3B+ and lower)
Mini HDMI Cable (if not using SSH, Raspberry Pi 4)
Mini HDMI Adapter (if not using SSH, Raspberry Pi 4)
Ethernet Cable (if no Wi-Fi is availlable)
Wi-Fi Dongle (optional)
Raspberry Pi Case(optional)

There are 2 ways to handle the Raspberry Pi Hostname change either via the edition of text files or the Graphic User Interface.

Editing Text Files

In the case that you have an headless Raspberry pi, the easiest way to modify is to use an SSH connection or the Terminal. In the case you would prefer to go via the desktop, you can use TeamViewer to navigate to the file and edit them.

Once in the terminal or SSH, you could use directly the command

hostnamectl set-hostname [name]

However that would only be a temporary solution since it doesnt’ update /etc/hosts  and will cause issues in the case you would be using some networking services who rely on that /etc/hosts.

The solution you should use is to update manualy 2 files: /etc/hostname and /etc/hosts.

Change /etc/hostname

To do that easily, use the nano editor via the terminal or SSH using the following command:

sudo nano /etc/hostname

Change the current default name raspberrypi to the chosen hostname.
Once that is done, save the file using CTRL+O and exit the file with CTRL+X.

Change /etc/hosts

Once you complete the update of the first file, you still need to update the second one. This can be done with:

sudo nano /etc/hosts

Again, change the default host name raspberrypi with your chosen hostname.
Once that is done, save the file using CTRL+O and exit the file with CTRL+X.

Reboot your Raspberry Pi

For all changes to take effect you need to reboot your Raspberry Pi with the following command

sudo reboot

Once the Raspberry Pi completes the reboot, it will appear on your network whit it’s new hostname!

Via the Raspbian Graphic User Interface

You can also update the Raspberry Pi hostname directly from the interface.
You first need to connect your Raspberry Pi to a monitor or to use TeamViewer to connect remotely to the Raspbian UI.

Go to the Rapsberry Pi Configuration and then in System.

Once in there you can simply change the Hostname to the unique one you have chosen.

Once you have change the hostname, click OK.

The Raspberry Pi will ask you if you want to Reboot, simply click Yes.

Once the Raspberry Pi completes the reboot, it will appear on your network with it’s new hostname!

 

Enjoyed this post?

Follow us on Pinterest for additional awesome ideas!​

Some posts on this blog contain affiliate links.
At no additional charge to you, I receive a small commission whenever a product is purchased through these links. The Dreaming Dad is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com.