How to connect to a Raspberry Pi Zero to an Ubuntu laptop by USB?
Solution 1
You need to go into the network-manager menu, Edit Connections… and edit the new Ethernet connection (for me it was “Wired connection 2”). Switch to the IPv4 tab, and change the Method to “Link-Local only”. Click Save and then Close.
The usb0 network interface will then get assigned a 169.254.x.y address, and “ssh [email protected]” will work just like it should.
Solution 2
I have experienced that the connection is not established correctly due to usb0 being renamed. What worked for me is to ensure that the connection is setup with the usb0 name.
In /etc/network/interfaces i appended the following to the file (you can change your address as it fits you):
auto usb0
iface usb0 inet static
address 10.9.8.1
netmask 255.255.255.0
up iptables -A FORWARD -i usb0 -j ACCEPT
up iptables -A FORWARD -o usb0 -j ACCEPT
up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
To ensure that the usb0 is recognized the following file must be created
/etc/udev/rules.d/70-persistent-net.rules
in the file the following is appended
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="cdc_ether", NAME="usb0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="cdc_eem", NAME="usb0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="cdc_subset", NAME="usb0"
Now the network should be set up correctly on the computer and you should be able to connect to the RPI
Related videos on Youtube
philmegamega
Updated on September 18, 2022Comments
-
philmegamega over 1 year
I tried following the instructions shown here so that hopefully I would be able to use my Raspberry Pi Zero without buying a usb keyboard, mouse and monitor.
After doing that I was unable to ssh in to the Raspberry Pi Zero. The output I got was:
ssh: Could not resolve hostname raspberrypi.local: Name or service not known
I tried dmesg and saw the following:
[ 2060.683489] usb 2-1: new high-speed USB device number 6 using xhci_hcd [ 2065.979176] usb 2-1: new high-speed USB device number 7 using xhci_hcd [ 2066.108051] usb 2-1: New USB device found, idVendor=0525, idProduct=a4a2 [ 2066.108056] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 2066.108058] usb 2-1: Product: RNDIS/Ethernet Gadget [ 2066.108060] usb 2-1: Manufacturer: Linux 4.4.21+ with 20980000.usb [ 2066.233624] cdc_subset: probe of 2-1:1.0 failed with error -22 [ 2066.234408] cdc_subset 2-1:1.1 usb0: register 'cdc_subset' at usb-0000:00:14.0-1, Linux Device, 6a:2b:ee:30:07:6e [ 2066.235273] usbcore: registered new interface driver cdc_subset [ 2066.236484] cdc_ether: probe of 2-1:1.0 failed with error -16 [ 2066.236507] usbcore: registered new interface driver cdc_ether [ 2066.238455] cdc_subset 2-1:1.1 enp0s20u1i1: renamed from usb0 [ 2066.264145] IPv6: ADDRCONF(NETDEV_UP): enp0s20u1i1: link is not ready [ 2066.264275] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2066.264281] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2066.264627] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2066.265568] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2066.265575] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2066.274193] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2111.934891] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2111.934898] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2111.936117] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2111.948226] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2111.948247] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped [ 2111.948251] cdc_subset 2-1:1.1 enp0s20u1i1: kevent 12 may have been dropped
Can anyone shed any light on what these logs mean? Extensive googling has yeilded no results for me.
I’m using Ubuntu 16.04.1 LTS 64-bit on a Lenovo Z50 (runs Ubuntu but a bit dodgily which is probably the source of most problems I have on this laptop). I have also tried using a Windows laptop. This worked after I installed the Bonjour software from Apple.
The output from the ifconfig says there is no IP address for the device so I’m not sure how I would connect to it.
enp0s20u3 Link encap:Ethernet HWaddr ce:77:fe:7a:9f:66 inet6 addr: fe80::7af9:c911:f518:cede/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:30 errors:0 dropped:0 overruns:0 frame:0 TX packets:84 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:5660 (5.6 KB) TX bytes:13989 (13.9 KB)
Thanks!
Update:
Beware of red herrings in everything below this line
OK so I downloaded the linux kernal source (latest stable version which is v4.8.11) and did some grepping.
I found that the "Kevent blah may have been dropped" is thrown in a function called 'usbnet_defer_kevent'.
/* some work can't be done in tasklets, so we use keventd * * NOTE: annoying asymmetry: if it's active, schedule_work() fails, * but tasklet_schedule() doesn't. hope the failure is rare. */ void usbnet_defer_kevent (struct usbnet *dev, int work) { set_bit (work, &dev->flags); if (!schedule_work (&dev->kevent)) { if (net_ratelimit()) netdev_err(dev->net, "kevent %d may have been dropped\n", work); } else { netdev_dbg(dev->net, "kevent %d scheduled\n", work); } } EXPORT_SYMBOL_GPL(usbnet_defer_kevent);
I found
usbnet_defer_kevent(dev, EVENT_SET_RX_MODE);
being thrown in a few places and it turns out that we have it definied in usbnet.h like so# define EVENT_SET_RX_MODE 12
. Not sure whatEVENT_SET_RX_MODE
is yet though (well. not what it is supposed to enumerate) so if anyone can help with that please do.cdc_subset: probe of blah failed with error blah is called in 'really_probe' in drivers/base/dd.c. Looks like linux tests drivers to see if they are suitable by 'probing' the device with the driver. That's my guess anyway. Need to find out what '-22' and '-16' are.
suspicion: I don't have a suitable driver installed
I'll keep hammering away at it anyway.
ps. sorry for the incoherant smattering of information here. I'm kind of using this as a notepad for my own digging.
-
FelixJN over 7 yearsThe RasperryPi seems to have an IPv6 address assigned. Try to use
ssh
with IPv6 viassh -6 fe80::7af9:c911:f518:cede
and see if that gets you further. And double check you Pi's hostname, as it could not be resolved (might however also be an IPv4 vs. IPv6 problem). Can you ping the Pi via DNS name? -
philmegamega over 7 yearsThanks @Fiximan. I tried 'ssh -6 fe80::b1f2:e0c2:fa74:b356' and got 'ssh: connect to host ... Invalid argument'. So after a quick google I tried 'ssh -6 fe80::b1f2:e0c2:fa74:b356%enp0s20u3' and got 'ssh: connect to host fe80::b1f2:e0c2:fa74:b356%enp0s20u3 port 22: Connection refused'. This is the same problem I get if I try after doing 'sudo ifconfig enp0s20u3 some ip address'. I can't ping the pi using the DNS name no. I get 'unknown host' if I try that. Pretty sure that the DNS name should be raspberrypi.local as I got it to work in Windows using that DNS name yesterday.
-
thephez over 7 yearsYou may want to try posting this on the Raspberry Pi SO also (raspberrypi.stackexchange.com).
-
philmegamega over 7 years@thephez Good suggestion. Except that I think the fact that I got the connection to work on a Windows laptop indicates that I need to look at my laptop rather than the pi. I'll try posting there if I get no luck here.
-
FelixJN over 7 years@philmegamega Well, I forgot about the device specification - sorry. May be try skipping the
.local
in you DNS ping, and AFAIK the device specified would be the LOCAL device from where the connection starts, i.e. your client's device - so maybe check your Ubuntu'sifconfig
for the proper device name. (but I am not too familiar with IPv6). Besides that: Crossposting usually is not encouraged .... -
philmegamega over 7 years@Fiximan I tried skipping the .local. Still no luck unfortunately
-
FelixJN over 7 years@philmegamega Can you ping the raspberrypi via it's IPv6-address?
ping6 fe80::b1f2:e0c2:fa74:b356%DEVICE
(withDEVICE
being your Ubuntu's network device, usuallyeth0
orwlan0
, seeifconfig
on that machine). You might also think about defining an IPv4 address as simplest solution. (Apart from that: for quotingcode
use backticks >> ` <<--- these.) -
philmegamega over 7 years@Fiximan I can ping the device using
ping6 fe80::bd63:7aa6:84ff:2817%enp0s20u2i1 PING fe80::bd63:7aa6:84ff:2817%enp0s20u2i1(fe80::bd63:7aa6:84ff:2817) 56 data bytes 64 bytes from fe80::bd63:7aa6:84ff:2817: icmp_seq=1 ttl=64 time=0.044 ms ping: sendmsg: Cannot assign requested address 64 bytes from fe80::bd63:7aa6:84ff:2817: icmp_seq=3 ttl=64 time=0.035 ms 64 bytes from fe80::bd63:7aa6:84ff:2817: icmp_seq=4 ttl=64 time=0.042 ms
. I can also ping the device after assigning an IPv4 address. But I still getConnection refused
when I try to SSH in to it. -
FelixJN over 7 yearsDoes this refused connection appear in you Pi's
/var/log/auth.log
? If so it might be a problem with your ssh server configuration (/etc/ssh/sshd_config
). Can you successfully connect viassh
using Windows (e.g. with putty)? -
philmegamega over 7 years@Fiximan Nope. Nothing appears in /var/log/auth.log when I try to ssh. It does work in Windows, yes. I remember that I was getting the same problem in Windows until I installed Bonjour. In Linux I think I need to have avahi-daemon running for the same purpose (whatever that is). It is running but I'm having a look in to it anyway.
-
-
philmegamega about 6 yearsThanks for that Rasmus. In the end I just bought an Rpi 3 and just connected through Wifi! I'll have a go with this on the old pi at some point though.