Setting the Network Name of a Raspberry Pi
You want to change the network name of your Raspberry Pi so that it’s not just called “raspberrypi.”
Changing the name of your Pi is pretty straightforward. There are just two files that need to be changed.
First, edit the file /etc/hostname. You can do this by opening a Terminal window and typing the command:
$ sudo nano /etc/hostname |
Replace “raspberrypi” with a name of your choice. This should remain one word, without any punctuation or unusual characters. This includes the _ character.
Second, open the file /etc/hosts in an editor using the command:
$ sudo nano /etc/hosts |
The file will look something 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 raspberrypi |
Change the text at the end that uses the old name (“raspberrypi”) to the new name.
Restart the Pi, and you should find that the name has changed when you view it on the network from another computer.
Discussion
Changing the name of your Pi can be very useful, especially if you have more than one Pi connected to your network.
See Also
See also Recipe 2.3 to change the IP address of your Raspberry Pi.