How to change your Raspberry Pi Hostname
About: There may come a time where you will want to change your hostname on the Raspberry Pi. For example the default hostname when using Raspbian is ‘raspberrypi’. This is fine, however if you have 2 Raspberry Pi’s running on your network you will want to change the hostname to differentiate the Raspberry Pi’s on your network. This isn’t critical since they still will have different IP addresses but it will help you if you look at your network list on your router or when running certain commands that include the hostname.
I will show you two different ways to change your Raspberry Pi’s hostname. The first way is using SSH/Terminal which would be useful if you are running your Raspberry Pi headless and can connect to it using SSH. The second way is using the Raspbian desktop and is just a few clicks.
Objective: To demonstrate how to change the hostname on your Raspberry Pi
Material: You will need the following:
- Raspberry Pi (Click the link to check out the price on Amazon. Usually around $37 with free shipping)
Instructions: Let’s start off by showing you how to change the hostname using the terminal or using SSH
Start off by connecting to your Raspberry Pi over SSH or opening a new terminal and type the following command to open your host file
sudo nano /etc/hosts
Your hosts file should look similar to mine. Leave everything alone except the last line which says “raspberrypi”. This is the line we will be changing and I will change mine to “gardnr” which is a project I am currently working on and will be using my Raspberry Pi for this project. Go ahead and change the name to whatever you like and close the editor by hitting CTRL+X and then Y for Yes.
Now we need to edit the hostname file. Enter the following command:
sudo nano /etc/hostname
All you should see in here is “raspberrypi”. Change this to the same thing you changed it in the previous file. Again I am using “gardnr” in my example. Close the editor by hitting CTRL+X and then Y for Yes.
Finally we will commit the changes with the following command:
and now simply reboot for the changes to take effect.
Once the system reboots you can check your current hostname using the “hostname” command and verify the hostname on your router
How to change your Hostname using the Raspbian Desktop
This will be a lot easier if you are using the Raspbian GUI desktop view. Click on Menu > Preferences > Raspberry Pi Configuration
The Raspberry Pi Configuration box should pop and in the middle you will see the hostname textbox. Simply change this box to whatever hostname you want to use. Click OK and reboot.
Changing your hostname using the GUI is as easy as Pi 🙂 If you have any questions on how to change your hostname post a comment and I will help you out.