Saturday, February 6

Upgrade you old laptop with a Raspberry Pi - take two




What if you want to connect your Raspberry Pi tailless but use a Windows OS on your laptop?
Well don't despair, there are ways to do that and a few tricks that will allow you to do so under several circumstances.

So let's recap what do we want to achieve. We want to connect a Raspberry Pi to a Windows computer, typically a laptop so that we can use the Keyboard, the Mouse and the Monitor of the laptop and replace its "engine" with a Raspberry Pi.
Old laptop or not this solution also makes for a great way to make your Pi a lot more portable. In this tailless configuration the only cable you might have is the power supply to your laptop!

Be weary that I have used  a Windows 7 for the laptop and Raspbian Jessie for the RPi. Things may be slightly different using other versions.

This article should also serve as an Errata Corrige for my previous one with regards to the Pi's support for Link-Local address. I will amend the previous post ASAP.

Requirements


Laptop

HW:
At least two USB ports
Ehernet adapter
WiFi card (optional)

SW:
A functioning Windows OS
VNC or RDP client

RPi

HW:
WiFi card
Ethernet card

SW:
VNC or RDP server (which regrettably needs to be installed upfront)

To glue them together we also need a USB Y cable and a 20-30cm Ethernet cable (Cat 5e or +) straight or crossover.

Networking


The first hurdle that we need to solve is how to try to make the laptop talk to the Pi at IP level. For that to happen the two must be connected at layer 1 and 2 of the OSI stack. The Ethernet cable plugged in your laptop's NIC and in the Pi's one does just that. It provides physical connectivity and data link. What we don't get as easily is two IPs in the same subnet.
This can be achieved in many ways, let's see a few.

Bonjour Windows


First things first though let's talk about how to allow Windows to resolve the

raspberrypi.local

That we are going to use to connect to the Pi independently from its IP address. Dealing with IP addresses is in fact quite a pain, that's why DNS came about after all. In my previous article I mentioned the good that comes with mDNS so that you can reach raspberrypi.local independently to which IPv4 or IPv6 you are using on the Pi.

Windows does not come natively with mDNS but there is a piece of software that we can install from Apple to install this protocol under Windows. Apple's interpretation of mDNS is called Bonjour and can be found here

Installing it is extremely easy and you will be able to use it straight away. Thanks Apple!
Once installed if you check the services running on your laptop you should see something like this:



Back to IP now. The first thing you should do it to disable any protocol and service that is not quite necessary from the Local Area Connection Property page of your laptop Ethernet's card. This is what I did:



Using APIPA


Automatic Private IP Addressing is Microsoft's interpretation of Link-Local address and it is a way of auto assigning IP addresses to hosts within a network segment without the need for a DHCP (service that is typically the job of your home router or NAS). A Class B of IP addresses has been reserved just for this purpose.

169.254.0.0/16 or 169.254.0.1 through to 169.254.255.254 with 169.254.0.0 being the subnet and 169.254.255.255 being the broadcast address. The network mask is 255.255.0.0.

Which in itself is quite a lot of technical gibberish but bare with me.

Now in the absence of a DHCP a Windows system (or any other OS supporting Link-Local address) will be configured as 169.254.x.y and this is the case for the Pi too with Raspbian Wheezy or Jessie.

I know I have said in my previous article that it didn't but ... it turns out it was grapevine knowledge which I would have been better off verifying first. I'll amend the other article ASAP.

The following screenshots illustrate the status of the adapters and of some other aspects at the network level of both the laptop and the RPi.





Note that once the two hosts communicate with each other the IP of the RPi will be evident in the ARP cache of the laptop



Booting your Pi after plugging the network cable and power is enough for your laptop to resolve raspberrypi.local in an IP 169.254.x.y with no extra hurdles. At this point you could already connect to your Pi via VNC by configuring the service on the Pi as I explained in my previous post




About IPv6


All works well also with IPv6


The Pi's sets itself up with an IPv6 and from the laptop pinging raspberrypi.local will successfully resolve and reach the Pi's IPv6 address:


As well as the IPv4.

These are screenshots of the laptop's network info:




Static IP addresses


If your laptop has an IP configured for its Ethernet adapter that you are not willing to alter then you can use the cmdline.txt to configure the Pi with an IP in the same subnet as you laptop. Easy!

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait ip= x.y.z.w

You need to edit the cmdline.txt file in /boot and add the part highlight in bod above. Make sure that all the text is on one line only.

The format is ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf> so you can add other parameters if you need to. The netmask might be one that you want to set right.

More simply you could configure the eth0 of the Pi once it is booted if you have access to the GUI before making it tailless on your laptop. A good time to do this is when you install you VNC server


The following screenshots illustrate the status and configuration of the adapters and of some other aspects at the network level of both the laptop and the RPi.






DHCP via ICS


An easy enough solution to connect to your Pi is to leverage on the Internet Connection Sharing functionality of modern Operating Systems like Windows. ICS will let you share a connection on your laptop via another one. Your laptop may have a WiFi card connecting you to the Internet and an Ethernet adapter. ICS will allow you to share the WiFi via the Ethernet NIC, anything connected via an Ethernet cable to the laptop will receive an IP address and will be able to use the WiFi as a gateway to the Internet.

Now we could be interested in just that but I said that we wanted to use old laptops just as KVMs not also as Internet gateways, there is nothing wrong with that but accessing the Pi from elsewhere than the laptop with this configuration may be troublesome if not plain impossible.
What we are very much interested in is the fact the ICS transforms the Windows OS in a DHCP on the shared network adapter so that we can have our IP!

To configure ICS in Windows the sharing must be activated on the interface that we are going to be using as gateway. In my example below I am using my WiFi as gateway and activating the share on the local network adapter



Once that's done the local network adapter will receive an IP address in the range 192.168.137.0/24 which topically will be 192.168.137.1


Note that as the laptop provides an IP to the Pi, the Pi's address can easily be found by looking at the ARP cache of the laptop



The Pi receives an IP like 192.168.137.x as did mine


All this good though comes at a price. The DNS resolution and the default route of the Pi are configured as if we wanted to use the laptop as our gateway. In order to use the Pi's WiFi card instead we need to alter the file
/etc/resolv.conf


And comment out the line which bares the IP of the laptop.
Next we need to remove the default route once that has once again the IP of the laptop by running:

sudo route del -net 0.0.0.0 gw 192.168.137.1

Lastly we need to setup the IP as static on the Pi as explained in the previous section and this time use the IP we were given with ICS which was 192.168.137.136. Make sure to untick "Automatically configure empty options".


Tip


You can change the subnet 192.168.137.0/24 to whichever you prefer by editing the registry

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\SharedAcces


I only have an Ethernet card on my old laptop


In this case we need to trick the OS into believing that it has a connection to share. The best way to do this is to create for example a dialup connection as in here:



or add an additional WiFi card or other network interface via PCMCIA or a bluetoooth adapter but that would be quite inefficient and rather laborious. Unless there are some very specific needs I would just create the fake dial-up.

What else is there to say?

All of the above IP options will require in the majority of cases a one off connection to a monitor, keyboard and mouse so factor this in if you are off somewhere with a brand new SD card for your tailless Raspberry Pi.

Which of these setup is best it largely depends on your needs but the Link-Local address / APIPA seems by far the preferable especially when using Bonjour.
The ICS is certainly the most confusing and complicated but it can have its uses. If your "portable" lab becomes a bit overcrowded and you need a DHCP for some of the devices, then ICS could be your friend. Here is an example:


If your "portable" setup becomes a bit more complex and you have devices that need an IP delivered with a DHCP, ICS is your friend.  In the picture above I have a tailless Pi connected to a switch to which are connected the laptop and a security camera. The camera can only do static IP or DHCP hence the need for ICS when on the move.


Also ICS inherently allows you to know the IP of its clients as by assigning them an IP that also generates an entry in the ICS's ARP cache. By inspecting it we can immediately tell which IP have been assigned making connecting to them a lot more easy even in the absence of mDNS / Bonjour.

A good part of what has been said in this article and in the previous one applies to the Raspberry Pi A/A+ and to the Zero but not in all cases. These configurations are meant to use a real Ethernet card and won't always work for the likes of the Ethernet Gadget as in this article from Adafruit. I will explore this at some point and see what of the above is applicable in this case and what should be adjusted.

The cables to make the Pi tailless are only two, could I use a Wireless connection instead of the short Ethernet? I don't see why not but it would make things a bit more complicated and confusing. The Ethernet cable guarantees a really good connection to the laptop and it is not prone to the various problems the WiFi inherently has. Tiding up the Ethernet with the power cable should not be a big problem and I would stick with that. This is until the USB gadget configuration is easier to setup and use, that may be a real game changer.



No comments: