Sunday, May 1, 2016

Using only Ethernet cable to connect Windows computer to Raspberry Pi

The Raspberry Pi is designed to be used a standalone computer only needed a monitor, keyboard and mouse to function.

There are many guides on how to SSH or VNC into the Raspberry Pi with the network set up usually using a router.

Well, what if you don't have a router because you're at an event or you don't want to put your Pi on the network.  It's fun at a Raspberry Jam to see all the Raspberry Pi's with the same name and the same user name and password on a network.

For this situation there is a really simple solution.  You give the computer's Ethernet port a fixed IP and you do the same on the Pi.
The great thing with this is the computer and the Pi can still connect to the available network over wifi and if available connect to the internet. 


I use this configuration a lot for simple python development where a full GUI isn't needed and since my ability to remember things is limited access to the internet from my laptop is essential for tips and trouble shooting.


For this to work the IP addresses you give the Ethernet ports cannot be on the same subnet as the router (if there is one)|
To check this on Windows do an ipconfig

You'll get something like below which shows the Wireless has an IP address of 192.168.0.11 with a subnet mask of 255.255.255.0 and a gateway of 19.168.0.1

The subnet mask says what range is usable.
In this case 192.168.0.1 - 192.168.0.255 are all in the subnet so are part of this routers control. 
You can limit the IP controlled by the router, but for this it's safer to assume ALL IP addresses from 1-255 are out of bounds. There are more than enough other IP addresses to use safely

Windows IP Configuration

Ethernet adapter Ethernet:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 3:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 5:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wi-Fi:
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::501b:b10b:e1c4:62ff%5
   IPv4 Address. . . . . . . . . . . : 192.168.0.11
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1

Tunnel adapter isatap.{70D5B1BF-BEE1-475B-9752-73772D3EA37A}:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:
   Connection-specific DNS Suffix  . :
   IPv6 Address. . . . . . . . . . . : 2001:0:5ef5:79fb:2c33:3c3f:3f57:fff4
   Link-local IPv6 Address . . . . . : fe80::2c33:3c3f:3f57:fff4%2
   Default Gateway . . . . . . . . . : ::


With this kind of set up I usually go for the range 10.0.0.X
Setting the IP for the computer to 10.0.0.100 and then the Pi's use IP addresses from there up.


\Setting IP address on Windows Computer

Go to the Setting and select [Network and Internet]


Then select Ethernet and [Change adapter settings]







Right Click on the Ethernet adapter and select [Properties]



If you're not logged in as Administrator rights then you'll be asked to enter your Administrator password.

Once done select Internet Protocol Version 4 (TCP/IPv4) and click [Properties]


By default it's probably set to Obtain IP address automatically with the same for DNS

Click [Use the following IP address:] and enter the IP address you wish to use on the computer.
As I mentioned I set  mine to 10.0.0.100

When you click OK it might say a subnet isn't set and set a default of 255.0.0.0.  Just accept the subnet.  It is used to keep IP addresses in organised groups so it doesn't matter what it is for our purposes as long as our 2 IP addresses are included which they will be.



The just click OK and close all the windows that have been opened.  All is set now for the computer.

For the Pi side  you ill either need a monitor, keyboard and mouse or to have a router to connect the Ethernet that way or have wifi setup as this method uses the GUI desktop tool. 


I'm using RealVNC as have been playing with Minecraft over VNC
Connect using RealVNC to your wifi or DNS provided IP address for your Ethernet port.

Top right in the task bar right click on the network/wifi indicator and select [Wifi network (dhcpcdui) Settings]



This will open the Network Setting tool

It opens with the Configure: Interface option but with nothing selected. In the blank drop down select eth0

Automatically configure empty options should be ticked with all fields empty.
Not type the IP address you want to use in the IP Address: box.  For this one I used 10.0.0.102

Then [Apply] and [Close]

At this point I usually restart the Raspberry Pi and connect the Ethernet port directly to the laptop.
Of course my VNC session will disconnect. So I will have to connect again.

Now if I run ipconfig on the laptop I get the following where the Ethernet IP is 10.0.0.100 (result)

Ethernet adapter Ethernet:
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::b0ac:5dbe:415b:e7e3%11
   IPv4 Address. . . . . . . . . . . : 10.0.0.100
   Subnet Mask . . . . . . . . . . . : 255.0.0.0
   Default Gateway . . . . . . . . . :

Wireless LAN adapter Wi-Fi:
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::501b:b10b:e1c4:62ff%5
   IPv4 Address. . . . . . . . . . . : 192.168.0.11
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1


Reconnect RealVNC with 10.0.0.102 as the Raspberry Pi IP address and everything should work.
Now no need for a router, or a wifi. But if you have wifi then the computer and Pi can still connect to the Internet using wifi while maintaining their direct connection over the Ethernet so wget and other updates can still be done.

The great thing with this is also that since each Pis Ethernet connection will be on a different network if you have 10 laptops with 10 Pis you can do this setup on one Pi and then dd the microSDs on to the others and they will all work with no conflict.