Sep 092012

Using two Pis at once

I recently started using two Raspberry Pi’s on the same network. On top of that, I had a nicely developed and updated image of Raspbian, so I made an exact copy of the SD card for Pi #2. (see: how to backup an SD card image here | how to write an SD card here).

But there were issues, and it took me some time to figure out why Pi #2 was crashing. Pi #1 (RS) is the one I’ve used since May. Pi #2 (Farnell) arrived a week later but has not been used a lot.

I’d been running Pi #1 overclocked to 900 MHz, which seems to cause Pi #2 to freeze up. :(
Having made an exact copy of the SD card, I was trying to run Pi #2 to the same overclock, without having tested it – hence the crashing. Pi #2 seems stable at 800 MHz.

How to change the hostname

The other side effect of having an exact copy of the SD card image is that both Pis were identified on the system as raspberrypi. So I decided to change the name. I seemed to remember from long ago, when setting up a web server there was a command called hostname, so I tried it.

and it spat out “raspberrypi”.

So then I tried man hostname so I could read the manual pages. Basically, you can type
sudo hostname RasPi1
and it will change you hostname to RasPi1, but only until you reboot. Not much use really.

The way to change it permanently is to edit the hostname file under /etc

sudo nano /etc/hostname

editing the hostname in nano

then change raspberrypi to whatever you want to call your Pi. (I’ve chosen RasPi1).
then <CTRL>+O (save)

<ENTER> (confirm the filename “hostname”)

<CTRL>+X (exit)

=========== UPDATE ===========
UPDATE 21 September 2012

This worked fine in the Raspbian Wheezy release up until September 2012. From then on it is necessary to edit one more file as well.

sudo nano /etc/hosts

change the “raspberrypi” entry there to your new hostname as well. It must be exactly as in your hostname file.
e.g. Raspi is NOT the same as RasPi


If you don’t do this, you will get system errors, for example when using sudo “sudo unable to resolve hostname”.
=========== UPDATE ===========

Then reboot. sudo reboot And when your Pi boots, you’ll see your new hostname on the prompt


and it should appear in your router control panel (eventually) too, making it easier to identify which machine you are using.

Hope you found this useful. ;)

  9 Responses to “How to change the name of your Raspberry Pi – new hostname”

  1. There’s a third file that could be a problem on some installations. In /etc/dhcp/dhclient.conf, uncomment the line send host-name, and if it has the literal host name on the line, change it to gethostname(), so that it will look up the current host name. This will cause dhcp to advertise your new host name to the rest of the network. It could also cause the old host name to be advertised, even though you think you’ve changed it.

  2. Very helpful and easy thanks, noted the comments of the previous.

  3. By default in Raspian, the config file /etc/dhcp/dhclient.conf has

    send host-name = gethostname();

    set as default, however does not hurt to verify your settings when changing the hostname and hosts file.

  4. If you set up password-less logins to your original Pi you will find that it will also work on your new one. You may not want this – sudo edit the ~/.ssh/authorized_keys on the new Pi to remove the lines containing the user@hostname entries where you want to remove this facility.

  5. I am using wheezy 2013-7-26. After making changes to hostnames and hosts I can not login anymore. send host-name = gethostname(); is already set in dhclient.config.

    Does someone know what went wrong? (even if I use the raspi-config menu for changing the hostname I cant Login anymore.

  6. “and it should appear in your router control panel (eventually) too, ”

    Why “eventually” – is there a delay?
    If a delay, how can you make it happen quicker?

    • There could be a delay while waiting for the DHCP lease (with the old hostname) to expire, before your Pi requests a new DHCP lease (with the new hostname).
      Your router may have an option to force-drop current leases? Or you might be able to use dhclient on your Pi to request a new DHCP lease from the router?

  7. You can just use ‘sudo raspi-config’ and change hostname.

    • Yes you can do that now, but when Alex originally wrote this article that feature didn’t exist in raspi-config yet ;-)

Leave a Reply