Connecting PC and RaspberryPi using LAN cable

13,214

Solution 1

You have to configure both sides with the static IP addresses you intent to use.

The ifconfig output for the PC tells me that the interface is not up and no IP is configured - we have to remedy that.

To cover our bases you should make sure your cabling is fine, you can do that with ethtool on both sides

sudo apt-get install ethtool

then on the Pi:

ethtool enxb827eb3d64cc

and on the PC:

ethtool enp3s0

Look for

Link detected: yes

and make sure that speed and duplex are the same on both sides, with a Pi it should look like

Speed: 100Mb/s
Duplex: Full

Now you can change your IPs temporarily (not reboot safe) with

ifconfig enp3s0 10.0.0.2 netmask 255.255.255.0 up

on the PC and the following on the Pi

ifconfig enxb827eb3d64cc 10.0.0.1 netmask 255.255.255.0 up

No gateway needed since they are both in the same network.

A permanent solution would be to set the IPs either in the GUI or in the config file called /etc/network/interfaces.

This depends heavily on the GUI you use but something similar to

Preferences -> Connections->Edit connections->IPv4 settings

should be it on both the PC and the Pi

Here is a good example of how to set a static IP. Just keep in mind that you may have to disable the GUIs network settings (i.e. gnome's Network Manager tends to overwrite and override this unless disabled)

(or whatever range you have decided to use, just make sure they are in the same range)

Solution 2

On the Ubuntu Desktop

Note: This is for Ubuntu desktop. The interface for Mate may be different

  1. On the computer, which is connected to the Internet, click the network icon in the panel and go to "Edit Connections..." at the bottom of the menu.

    Edit Connection...

  2. Double click your Wired Connection (Leave your wireless connection untouched, the one connected to Internet and the one you want to share, as I understand).

    Network Connections Dialog

  3. On the "IPv4 Settings tab", select Method: "Shared to other computers"

    Editing Wired Connection

  4. Reconnect by clicking on the Wired Network, so it gets a new IP address. (The two computers must be connected by an ethernet cable for this step, so connect them now if you haven't already.)

  5. Click on "Connection Information" in the network menu and write down the IP address and network mask (in my case it was assigned 10.42.0.1/255.255.255.0 but I do not know if that will always be the case).

    Connection Information

On the Raspberry Pi

Assign static IP to the Ethernet connection

  1. In Pi the WiFi device is called wlan but the ethernet device name is hard to guess. To find the device names use the command:

    $ ip link show

The output will show your Ethernet device in Pi enxb827eb3d64cc

  1. Next we need to find the current IP addresses assigned to enxb827eb3d64cc:

    $ ip -4 addr show dev enxb827eb3d64cc | grep inet

I get something like this, yours may be different:

inet 10.42.0.211/24 brd 10.42.0.255 scope global enxb827eb3d64cc
  1. You can keep the assigned IP address or choose a different one in the same subnet. Add the following lines at the end of /etc/dhcpcd.conf by:

    $ sudo nano /etc/dhcpcd.conf

With the following content to make the assigned IP address static:

# Custom static IP address for enxb827eb3d64cc
interface enxb827eb3d64cc
static ip_address=10.42.0.211/24
static routers=10.42.0.255
static domain_name_servers=10.42.0.255

Change 10.42.0.211 above to 10.42.0.x where x is a number between 2 and 254 if you want to assign a different IP address.

  1. Reboot Pi to make the new IP address take effect:

    $ sudo reboot now

Now you should be able to ssh from the desktop to the Pi with the following command:

$ ssh [email protected]

Hope this helps

Share:
13,214

Related videos on Youtube

lets_try
Author by

lets_try

Updated on September 18, 2022

Comments

  • lets_try
    lets_try over 1 year

    I am trying to connect my desktop running Ubuntu 16.04 to a Raspberry Pi3 running Ubuntu MATE. The end goal is to ssh using Ethernet connection by assigning static IP addresses to PC (say 10.0.0.1) and to Pi (say 10.0.0.2).

    Then I can do ssh [email protected] from the PC, right?. I have connected PC and Pi using ethernet/lan cable. Then I disabled Enable Wi-Fi option on Raspberry Pi and I can see that it is connected to Wired Connection 1. Running ifconfig command on the Raspberry Pi gives:

    pi@pi-desktop:~$ ifconfig 
    enxb827eb3d64cc Link encap:Ethernet  HWaddr b8:27:eb:3d:64:cc  
                  inet addr:192.168.100.1  Bcast:192.168.100.255  Mask:255.255.255.0
                  inet6 addr: fe80::afe3:308f:92f3:e890/64 Scope:Link
                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                  RX packets:662 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:111 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000
                  RX bytes:151040 (151.0 KB)  TX bytes:19190 (19.1 KB)
        
        lo        Link encap:Local Loopback  
                  inet addr:127.0.0.1  Mask:255.0.0.0
                  inet6 addr: ::1/128 Scope:Host
                  UP LOOPBACK RUNNING  MTU:65536  Metric:1
                  RX packets:21628 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:21628 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1
                  RX bytes:1300280 (1.3 MB)  TX bytes:1300280 (1.3 MB)
    

    Then I was planning to set PCs IP address to 192.168.100.2 but it is not connected to Wired Connection 1 even with Enable Wi-Fi disabled. Running ifconfig on PC gives:

    pc@pc-desk:~$ ifconfig
    enp3s0    Link encap:Ethernet  HWaddr 74:d4:35:d1:2c:f4  
              inet6 addr: fe80::181f:fbbb:63d2:c4e4/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:106 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1386 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:17736 (17.7 KB)  TX bytes:263114 (263.1 KB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:9695 errors:0 dropped:0 overruns:0 frame:0
              TX packets:9695 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:845799 (845.7 KB)  TX bytes:845799 (845.7 KB)
    

    I am stuck here. Any pointers would be highly appreciated.

    Edit: Output of ethtool

    On PC:

    pc@pc-desk:~$ ethtool enp3s0
    
        Settings for enp3s0:
            Supported ports: [ TP MII ]
            Supported link modes:   10baseT/Half 10baseT/Full 
                                    100baseT/Half 100baseT/Full 
                                    1000baseT/Half 1000baseT/Full 
            Supported pause frame use: No
            Supports auto-negotiation: Yes
            Advertised link modes:  10baseT/Half 10baseT/Full 
                                    100baseT/Half 100baseT/Full 
                                    1000baseT/Half 1000baseT/Full 
            Advertised pause frame use: Symmetric Receive-only
            Advertised auto-negotiation: Yes
            Link partner advertised link modes:  10baseT/Half 10baseT/Full 
                                                 100baseT/Half 100baseT/Full 
            Link partner advertised pause frame use: Symmetric Receive-only
            Link partner advertised auto-negotiation: Yes
            Speed: 100Mb/s
            Duplex: Full
            Port: MII
            PHYAD: 0
            Transceiver: internal
            Auto-negotiation: on
        Cannot get wake-on-lan settings: Operation not permitted
            Current message level: 0x00000033 (51)
                           drv probe ifdown ifup
            Link detected: yes
    

    On Raspberry Pi :

    pi@pi-desktop:~$ ethtool enxb827eb3d64cc
    Settings for enxb827eb3d64cc:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised pause frame use: Symmetric Receive-only
        Advertised auto-negotiation: Yes
        Link partner advertised link modes:  10baseT/Half 10baseT/Full
                                             100baseT/Half 100baseT/Full
        Link partner advertised pause frame use: Symmetric Receive-only
        Link partner advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
    Cannot get wake-on-lan settings: Operation not permitted
        Current message level: 0x00000007 (7)
                       drv probe link
        Link detected: yes
    

    Output of uname -a command:

    On Raspberry Pi:

    pi@pi-desktop:~$ uname -a
    Linux pi-desktop 4.4.38-v7+ #938 SMP Thu Dec 15 15:22:21 GMT 2016 armv7l armv7l armv7l GNU/Linux
    

    On PC:

    pc@pc-desk:~$ uname -a
    Linux pc-desk 4.13.0-26-generic #29~16.04.2-Ubuntu SMP Tue Jan 9 22:00:44 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    
    • Robert Riedl
      Robert Riedl over 6 years
      ...and you have to configure both sides to the static IP addresses you intent to use. You can do that temporarily (not reboot safe) with ifconfig enp3s0 10.0.0.2 netmask 255.255.255.0 up(or whatever range you have decided to use, just make sure they are in the same range)
    • lets_try
      lets_try over 6 years
      Yes , you are right. I forgot to change the IP to static address before posting the ifconfig output of raspberry pi. I usually set static IPs using GUI under network connections->Edit connections->IPv4 settings. I can see 10.0.0.2 and 255.255.255.0 as ip and subnet mask, what should the gateway be set to in this case ? . In normal cases I would set it to router IP address
    • lets_try
      lets_try over 6 years
      I have added the output . I could not make much sense of it though.
    • lets_try
      lets_try over 6 years
      It worked!. I think like you mentioned the error occurred since the static IPs were not set. I was under the assumption that if ifconfig doesnot list IP address then it is not connected to the network. Thank you for your response. Can you post the above comments as answer. I can accept it then . Cheers :)
    • Robert Riedl
      Robert Riedl over 6 years
      lets_try and @user68186, I've added my answer and as soon as it is accepted we can clean up the comments
  • lets_try
    lets_try over 6 years
    Thank you for your response. I accepted Robert Riedl's since it was the first correct answer to my problem and just to be fair :)