Changing the hostname of your #RaspberryPi

For those people who (like me) have more than one Pi, and even for those who have more than one SD card, the ability to change the hostname is invaluable. Here’s how you do it.

You need to change two files.

Firstly, edit (using nano, or other editor) the file
/etc/hostname

Change whatever is currently in there to the name you want. For this example, we’ll set our Pi to have the name ‘banana’. So, ‘banana’ (without the quotes) is the only thing that should be in that file. Save it.

Secondly, edit the file
/etc/hosts

Change the ‘127.0.0.1’ line to (for our example):

127.0.0.1     banana

That’s it! Reboot and you should get a login prompt with your new hostname.

2 comments for “Changing the hostname of your #RaspberryPi

  1. Good stuff Mike. I flip my SD cards around and play with different ones quite a bit so I’ve taken to using a slightly different approach. Each Pi now has a reserved IP in the router, linked to its MAC address. It’s effectively static but still using DHCP. So then I just have a profile in ConnectBot (android) or Tunnelier/Putty (Windows) for each Pi. Pi1, Pi2, Pi3. Although after yesterday I only have 2.9 Pis instead of 3 😉

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.