Changing Your Host Name on a Raspberry Pi

The host name, which is the UNIX equivalent to Windows’ “Computer Name”, is an easy way to access your computer from your local network without figuring out what it’s IP is. On Raspbian, the default host name is simply raspberrypi. For example, if you have Samba installed, you can access it from your Windows computers with \raspberrypi, or you can access your web server with http://raspberrypi.local.

But what if you had more than one Raspberry Pi on your network? Or if you just wanted to make it a little more personal? Well there’s two easy ways for you to change it.

Temporary Method

This method is temporary and it will reset back when your restart your Pi. In a shell, use the following command:

sudo hostname "MyPi"

where MyPi is your host name.

You can also just call hostname to get your current host name, if you wanted to use it in a script or just to check if it worked.


Permanent Method

This method is more permanent, as in it will stay to what you change it even after you restart. You can always just change it back using the same method if you start feeling nostalgic. In a shell, enter:

sudo nano /etc/hostname

That takes you to the nano text editor where you can change that first line to the host name you want. Once you are done, press ctrl+x to exit, press “y” to confirm that you want to save, and Enter to save it under the same file name.

At this point you’ll want to edit your hosts file so that the system recognizes the hostname to be itself. In the shell, enter:

sudo nano /etc/hosts

and replace "raspberrypi" with what you just put in /etc/hostname and exit/save with ctrl+x, y, Enter. Now once you restart, your new host name will be whatever you chose.


Both of these methods require root privileges and work on a lot of UNIX-based systems, including most Linux systems like Raspbian or even Android.


Leave a Reply

Your email address will not be published. Required fields are marked *