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 “weatherstation“.

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

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.

 

Source : https://www.howtogeek.com/167195/how-to-change-your-raspberry-pi-or-other-linux-devices-hostname/

En poursuivant votre navigation sur mon site, vous acceptez l’utilisation des Cookies et autres traceurs  pour réaliser des statistiques de visites et enregistrer sur votre machine vos activités pédagogiques. En savoir plus.