Headless Boot Of Raspberry Pi Using A Static IP Address

(Looking for headless boot using DHCP?)

If you don’t have a DHCP server running on your home network, or you want to allocate a specific ip address for your Pi – maybe because you want to access it via a second network port on a local machine, or via a standard hub – you can still headless boot by setting the ip address on the SD card beforehand.

You will need:

  1. A computer running Linux (mine is Fedora 20).
  2. A Raspberry Pi and compatible power adapter.
  3. An ethernet cable.
  4. An SD card for the Pi OS

Step 1 – Create a bootable SD card

As I’ve said before, I had trouble finding an SD card that would boot. In the end, this one worked:

raspbian

To create the card, you need to download Raspbian from the Raspberry Pi website. Then follow the official instructions here to copy the image to the SD card. They are listed under Linux, Mac and Windows at the foot of the page.

Step 2 – Edit The Network Details

Make sure the SD card is mounted on your computer and cd to the Raspbian filesystem (your path will be unique to your machine, but on Fedora will follow this pattern):

cd /run/media/faye/3d81d9e2-7d1b-4015-8c2c-29ec0875f762/

Open the network interfaces file for editing (you can use nano instead, or whatever editor you like):

sudo vi etc/network/interfaces

In this file, change the line:

iface eth0 inet dhcp

to

iface eth0 inet static

and directly underneath it add the network address for the Pi, the netmask and the gateway. The Pi should be set to an address that you know is not taken. The netmask for home networks is typically 255.255.255.0, and the gateway is the ip address of your router (typically 192.168.1.254):

address 192.168.1.211
netmask 255.255.255.0
gateway 192.168.1.254

Save and quit the interfaces file. Type:

sync

and when it finishes unmount the SD card. You can do this in the graphical interface, or you can type

df -h

to get the paths to the two partitions on the card, and unmount them on the command line:

umount /dev/mmcblk0p1
umount /dev/mmcblk0p2

Step 3 – Boot up the Pi and Check the LEDs

Put the SD card into your Pi and connect it to a network port.

When you power the Pi, you should see all the lights flashing away. There are five LEDs on the board:

  • OK (ACT on revision 2 boards)
  • PWR
  • FDX
  • LNK
  • 10M (100 on revision 2 boards)

The first LED to come on will be PWR, which you can guess is the indicator for power received. This should always be on.

The bottom three lights are all related to the network connection – full duplex, link light and connection speed. The maximum connection speed of the Pi is 100mbps – don’t be fooled by the 10M label (this was corrected to 100 on the revision 2 board).

The top LED will only light up when the SD card is being accessed. It was renamed to ACT (activity) on the revision 2 board. When I first started using the Pi I thought that if OK wasn’t lit up then something had gone wrong (and this is possibly the reason for the name change), but this is not the case.

If your Pi boots up correctly from the SD card, and connects to the network, you should see the bottom four lights on as in this photo:

pi_leds

If your Pi looks like this, you’re ready for the next step!

Troubleshooting

If you only get the power LED and nothing else, it is probably an issue with the SD card. I tried three cards before I found one that worked.

However, sometimes you really will need to connect up a keyboard and monitor to see what’s happening – there is only so much you can try before you need some output from the device to tell you what is going on.

Step 4 – Access Your Pi

In a terminal window, type (replace with the ip address that you chose in Step 2):

ssh pi@192.168.1.211

This is telling ssh you want to log in as user ‘pi’ to the static ip address that you set earlier.

Type ‘yes’ at the prompt and then enter the default password: raspberry.

You’re in!

Step 5 – Expand Your Filesystem

Once you’re logged into the Pi, the first thing you should do is run

raspi-config

This will bring up a config utility like this:

raspi-config

If you don’t do this, you’ll run out of space pretty quick (i.e. as soon as you run an OS update).

Select option 1, and make any other changes you might want. They are all optional and you can always come back to this later – I left everything as it was for now.

Finally, exit and reboot.

The last thing you should do before playing with the Pi is a system update:

sudo apt-get update

followed by

sudo apt-get upgrade

If you want to remove the downloaded packages (they can take up a lot of space), you can do this with

sudo apt-get clean

And then you should be good to go.

 

All Pi guides are created using a revision 1 board.