One of the first things you do with a Raspberry Pi is connect it to a wifi or ethernet network but what if you don’t have an extra keyboard or screen available, but you have a laptop?
There are times when a HDMI monitor is not available to use with your Raspberry Pi. In those circumstances it can be very useful to remote connect using a nearby network and a laptop (see the Guide to…Remote Connections). However, sometimes there isn’t a network available either!
So how can we make use of a laptop screen and keyboard when there is no network?
As discussed in Meltwater Raspberry Pi Hardware’s Guide to Remote Connections, there is the option of using a TTL-serial cable, however this provides rather slow access. The serial connection won’t support X11 (which allows us to run graphical programs), and you won’t be able use VNC or shared folders if you have them setup.
The answer is a simple network cable!
It is advisable to set this up before you need it so you can be sure that it is configured and working correctly. As long as you have an SD-Card reader available, you can switch between the configurations using a laptop (or directly on the Raspberry Pi if you have a screen/keyboard at the time).
Remember if you need the wired network for your computer (i.e. to get internet) then you shall have to make a choice about which one you wish to use (or get an extra network port by adding a USB network dongle). If you use wireless connections, then you can still have both!
Any standard network cable should be suitable (needs to have a male RJ45 connector on each end), most cables available will be fine for our needs.
Note: You can use a normal network cable since the Raspberry Pi LAN chip is smart enough to reconfigure itself for direct network connections (in the past older computers would have needed a special “cross-over” cable).
Before you boot up your RPi you’ll need to edit the /boot/cmdline.txt file. This can be done either on the RPi itself using nano or your preferred editor or by mounting the SD card on another computer with a card reader and editing the file there:
Here’s how you do that:
sudo nano /boot/cmdline.txt
5. Edit cmdline.txt and add the IP address at the end (be sure you don’t add any extra lines).
For network settings where the IP address is obtained automatically, use an address in the range 169.254.X.X (169.254.0.0 – 169.254.255.255):
type “ip=169.254.0.2” at the end of the cmdline.txt file.
If you’ve edited the cmdline.txt file on another computer you’ll need to put it back into the RPi and boot it up.
Otherwise, you’ll then need to reboot your RPi by typing:
Make sure your static IP stuck, you’ll see the IP address announced during the bootup procedure.
You should get a result similar to this:
The IP address is 169.254.0.2
Or you can double check to discover your RPi’s static IP:
sudo hostname -I
On your laptop
Connect an ethernet cable between your laptop and the RPi and open the Terminal and ssh into your Raspberry Pi:
You’ll be asked to create a network certificate and then prompted for a password to your RPi, by default it is “raspberrypi” if you haven’t changed it.