How to change hostname on raspberry pi

If you are like me and have a lot of Pi’s so I’m going to show you how to change hostname on raspberry pi.
First you will need A computer with a SD card reading, A SD card with Jessie installed. (link here)

    1. First, log onto your Pi and open a terminal window.
    2. Edit the “hostname” file. If you do not go ahead and create it.
      sudo nano /etc/hostname
    3. This file contains only one line – the name of your Pi.  Change the name to whatever you like, but only use the letters ‘a’ to ‘z’ (upper or lower), digits ‘0’ to ‘9’, and the dash ‘-‘
    4. Save the file using Ctrl+x, then Y followed by Enter.
    5. There is a second file that also contains the hostname, but it is only there as a workaround for some software.  Therefore you should also edit that file. Find the line starting with 127.0.0.1, and change the name following it to your new hostname.  Save the file using Ctrl+x, then Y followed by Enter:
sudo nano /etc/hosts

Logging the correct way

  1. Connect the Ethernet cable to your computer and to the Raspberry Pi. Connect the power supply to the Raspberry Pi which will turn it on. Wait for 2-5 minutes, or until the Pi has fully booted
  2. Log into your router and check the IP address of you pi
  3. ssh into your pi ssh pi@IPAddress
  4. Input the default password for raspberry pi  pw: raspberry
  5. Edit the files as above
  6. Now we are going to power down the Raspberry Pi or reboot the Pi from the command line by typing “sudo reboot now”.
  7. After reboot your Pi will be listening on the new address. So, now when you go to login, open a ssh pi@hostname

Logging in the incorrect way

  1. Connect the Ethernet cable to your computer and to the Raspberry Pi. Connect the power supply to the Raspberry Pi which will turn it on. Wait for 2-5 minutes, or until the Pi has fully booted
  2. Remove power
  3. After reboot your Pi will be listening on the new address. So, now when you go to login, open a ssh pi@hostname

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.