Direct connect between PC and Raspberry PI with ethernet cable

Hi,
time ago i needed to connect my laptop to my raspberry pi through ssh without use internet and router. In this way i'm able to use my laptop monitor and keyboard without a connection.
The solution is to use ethernet cable to direct connect laptop with raspberry.

This is very easy to implement. We need to set static IPs on pc and raspberry:

1) set ip static on your raspberry:

sudo nano /etc/network/interfaces

and use this template:

auto lo

iface lo inet loopback
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp


 where 192.168.1.100 is an example of ip you can assign


2) set ip static on your pc:

sudo nano /etc/network/interfaces

and use the same template:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback


##

iface eth0 inet static
        address 192.168.1.99
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1  


where 192.168.1.99 is an example of ip for your pc

now you need to check if ethernet connection is running (remember to connect pc to raspberry with ethernet cable):

sudo ifconfig

if you see ethernet interface (es. "eth0") running you are ready to connect to your raspberry pi from your pc, else do this:

 ifup eth0

where eth0 is the name of your ethernet interface. In this way you are enabling ethernet interface.

check if connection works well:

ssh pi@192.168.1.100

ok, now you are ready to use your raspberry with your pc without internet and router

Commenti