Connecting PC and RaspberryPi using LAN cable [duplicate]
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
On the Ubuntu Desktop
Note: This is for Ubuntu desktop. The interface for Mate may be different
-
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.
-
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).
-
On the "IPv4 Settings tab", select Method: "Shared to other computers"
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.)
-
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).
On the Raspberry Pi
Assign static IP to the Ethernet connection
-
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
-
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
-
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.
-
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
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)