By default the Raspberry Pi has its hostname set to “raspberrypi”. This appears as part of the command prompt when you open a terminal window. It only takes a few minutes and you’ve got a choice of two methods.
I sometimes change the hostname so that when I list devices on my home network I can easily identify any Raspberry Pis I’ve got connected amongst all the phones, tablets and PCs.
Method 1 – Using raspi-config
From the command line (or terminal if you are using the desktop) type :
sudo raspi-config
From the menu select “Hostname”.
Read the notes and select “OK”.
Enter your required hostname and select “OK”.
Select “Finish”.
When prompted to reboot select “Yes”.
Your Pi will reboot and will now have your new hostname.
Method 2 – Editing Files Manually
From the command line (or terminal if you are using the desktop) type :
sudo nano /etc/hostname
followed by ENTER. Type the hostname you require and using the menu save the file and exit.
Then type :
sudo nano /etc/hosts
followed by ENTER. Replace all instances of the old hostname (e.g. “raspberrypi”) with the new hostname that you entered above. As an example I changed my hostname to “pi2” so my file looks like this :
127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 127.0.1.1 pi2
Save the file. Then you can either reboot by typing :
sudo reboot
followed by ENTER or simply restart the hostname process by typing :
sudo /etc/init.d/hostname.sh start
followed by ENTER.
The hostname as been changed. You new hostname will now be visible in the command prompt when you open a new terminal window.
Please ensure you choose a hostname that only contains upper and lower case letters, numbers and the “-” character.
2 Comments
Just a note: a hostname can also have numbers (0-9) in it as well as letters (uppercase and lowercase) and the dash “-” character. So “Host-01”, “host-01” and “host01” are all valid for example.
Thanks for the update. I’ll modify my text.