By default, any Raspberry Pi that uses Raspbian, the official OS, has “raspberrypi” as its hostname. So, whether you’re trying to use your Raspberry Pi as a web server or set up a headless Raspberry Pi that you access remotely, your board will always be listed as “raspberrypi” on your network. That’s not very helpful when you have multiple Raspberry Pi devices and can’t tell one from the other.
Fortunately, it’s very easy to rename your Raspberry Pi in Raspbian.There are three main ways to change the Raspberry Pi’s hostname and, which one you choose, really depends on your preference for command line or desktop environment. Note that your Raspberry Pi hostname can have numbers, letters, capital letters and hyphens (as long as the first character isn’t a hyphen) but it can’t have special characters.
Change Raspberry Pi Hostname at Command Prompt
1. Launch raspi-config by typing:
The Raspberry Pi Configuration tool launches.
2. Select Network Options.
3. Select Hostname and hit Enter or select Ok if you receive a warning telling you not to use special characters in Raspberry Pi’s hostname.
4. Enter a new hostname and hit Enter.
5. Click Finish to exit raspi-config. You can get to the Finish button by hitting Tab.
6. Select Yes when asked if you’d like to reboot. If you select No then you’ll need to reboot manually for your change to take effect.
When your Raspberry Pi reboots, it should have the new hostname.
Change Raspberry Pi Hostname in Desktop Mode
There’s no need to go to a terminal window to rename your device. If you’re on the desktop, changing your Raspberry Pi’s hostname is just as easy.
1. Launch Raspberry Pi Configuration from the Preference menu.
2. Enter a new name in the hostname field and click Ok.
3. Click Yes when prompted to reboot.
Change Raspberry Pi Hostname by Editing Config Files
If you’re the kind of person who prefers to get their hands dirty going into text files and changing settings there, you can edit the relevant hosts files directly. The easiest way to get there is from the command line.
1. Open the /etc/hosts file for editing.
sudo nano /etc/hosts
2. Change the old Raspberry Pi hostname to your new one and save. In nano, you save by hitting CTRL+X and then Y for yes.
3. Open /etc/hostname for editing.
sudo nano /etc/hostname
4. Change the hostname there and save.
5. Reboot your Raspberry Pi for the changes to take effect. At the command prompt, you can type the following to reboot.