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.
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:
sudo /etc/init.d/hostname.sh
Follow that command with:
sudo reboot
Source: https://www.howtogeek.com/167195/how-to-change-your-raspberry-pi-or-other-linux-devices-hostname/