Knowledge for the World

How to change the hostname of your Raspberry Pi

A hostname is the name of your computer on a network. Your computer can be reached by its IP address, but those are long and hard to remember. Setting a hostname is easier to remember, more convenient to type, and generally better for managing multiple devices on a network.

By default, the Raspberry Pi hostname is "raspberrypi", but if you have multiple Pi's on the same network you'll probably want to set a unique hostname for each.

1

First, you'll need to log into your Pi and edit the /etc/hosts file and add the desired hostname.

sudo nano /etc/hosts

You'll see a line like this:

127.0.1.1    raspberrypi

Replace raspberrypi with your desired hostname, save, and quit.

As an example, I'll set the hostname to howchoo1. So my /etc/hosts file would contain:

127.0.1.1    howchoo1
2

sudo nano /etc/hostname

By default, this file contains only the name raspberrypi. Again, replace this with your desired hostname. Updating this file will ensure that the hostname remains set upon the next reboot.

For my example I would replace raspberrypi with howchoo1.

3

If you'd like to reach the Pi by its hostname, you'll want to edit /etc/hosts on your local machine (not the Pi) and append the following:

<pi ip address> <hostname>

If necessary, learn how to find the IP address of your Raspberry Pi.

Now you can reach your Pi using the new hostname.

For our example, my entry would look like this:

192.168.1.181 howchoo1