The default hostname for the Raspberry Pi is, creatively enough, “
raspberrypi“. What if you want a different hostname or you want to avoid hostname conflicts on your local network? Read on as we show you how to quickly change the hostname of a Linux-based device.
Why Do I Want to Do This?
There are two primary reasons why you would want to take a few minutes to edit the local hostname of a Linux device on your network. The most common reason would simply be customization–it’s fun to personalize things. Rather than leave your Raspberry Pi music station as plain old “
raspberrypi“, for example, you could rename it to “
The other reason you would want to customize the local host is to avoid name conflicts. If you, for example, have purchased and set up three Raspberry Pi units, all three of them (assuming a default Raspbian installation) will attempt to claim the local hostname “
The first one will succeed and the next two will fail to resolve their hostnames, leaving them blank in your router’s device list (as seen in the screenshot above) and unreachable via hostname-based protocols like Samba file sharing.
Fortunately it’s super simple, assuming you know where to perform a few quick edits, to change the hostname of your Raspberry Pi (and most other Linux-based devices you have full access to). For demonstration purposes we’ll be performing the change on a stock Raspbian installation, but the same file edits will work on Debian, Ubuntu, and most other Linux platforms.
Changing the Host on your Pi
We have so many Raspberry Pi units around the office that a bunch of them are now in conflict. Today we’re going to fix that by assigning unique names to each Pi unit based on their current function. A perfect candidate for this renaming is our awesome Raspberry Pi weather station; it will be much easier to identify it on the network once we change the hostname to “
The first step is to either open up the terminal on the device or to SSH into the device and open up a remote terminal. Our device is headless and currently running, so we’ll take the remote terminal route and connect to it via SSH.
At the terminal, type the following command to open the hosts file:
sudo nano /etc/hosts
Your hosts file will look like so:
Leave all of the entries alone except for the very last entry labeled
127.0.1.1 with the hostname “
raspberrypi“. This is the only line you want to edit. Replace “raspberrypi” with whatever hostname you desire. We replaced it on our device with “
weatherstation“. Press CTRL+X to close the editor; agree to overwrite the existing file and save it.
Back at the terminal, type the following command to open the hostname file:
sudo nano /etc/hostname
This file only contains your current hostname:
Replace the default “
raspberrypi” with the same hostname you put in the previous step (e.g. “
weatherstation“). Again, press CTRL+X to close the editor, agree to overwrite the existing file and save it.
Finally, we need to commit the changes to the system and reboot the system for the changes to take effect. At the terminal, enter the following command to commit the changes:
Follow that command with:
Once the system comes back online, you can check the device list in your router to see if the new hostname has properly resolved:
Success! Now instead of wandering the network without a name, our little Raspberry Pi weather station has a hostname all its own.
- › Google Is Finally Making Chrome Use Less RAM
- › Bring Home Crisp Audio With Kanto YU2 Desk Speakers for $80 Off
- › How to Block Websites on Android
- › Today Only: This Tiny 65W 2-Port USB-C Charger Is Just $32
- › You Can Now Protect Your Apple Account With Hardware Keys
- › Disney+ With Ads Is Here, and It Doesn’t Work on Roku