Published by expire0
Posted on March 21, 2017
Connect a Raspberry PI Zero to a Fedora/Centos/Windows 8-10 Linux System via USB. We were looking to use the PI Zero as a USB Ethernet/RNDIS Gadget. This will allow us to connect to the PI Via ssh over USB.
For this method, alongside your Raspberry Pi Zero, MicroUSB cable and MicroSD card, only an additional computer is required, which can be running Windows (with Bonjour, iTunes or Quicktime installed), Mac OS or Linux (with Avahi Daemon installed, for example Ubuntu has it built in).
1. Flash Raspbian Jessie full or Raspbian Jessie Lite onto the SD card.
2. Once Raspbian is flashed, open up the boot partition (in Windows Explorer, Finder etc) and add to the bottom of the config.txt file dtoverlay=dwc2 on a new line, then save the file.
3. If using a recent release of Jessie (Dec 2016 onwards), then create a new file simply called ssh in the SD card as well. By default SSH is now disabled so this is required to enable it. Remember – Make sure your file doesn’t have an extension (like .txt etc)!
4. Finally, open up the cmdline.txt. Be careful with this file, it is very picky with its formatting! Each parameter is seperated by a single space (it does not use newlines). Insert modules-load=dwc2,g_ether after rootwait. To compare, an edited version of the cmdline.txt file at the time of writing, can be found here.
4a. You will need to enable ssh on raspbian as it is disabled by default. Enable SSH on Raspbian
5. That’s it, eject the SD card from your computer, put it in your Raspberry Pi Zero and connect it via USB to your computer. It will take up to 90s to boot up (shorter on subsequent boots). It should then appear as a USB Ethernet device. You can SSH into it using raspberrypi.local as the address.
We needed to install avahi-daemon.service, avahi-compat-libdns_sd (Libraries for Apple Bonjour mDNSResponder compatibility)
yum or dnf install avahi-daemon avahi-tools avahi-ui-tools avahi-compat-libdns_sd nss-mdns
b. Centos comes with firewalld enabled by default. You will need to allow port 5353 UDP. If you have trouble with Fedora be sure to check the firewall settings.
c. Connect the PI and check for the Ethernet device name of the pi .
A. Run lsusb and look for the USB Ethernet device. This will confirm that you system can see the device.
Example : Bus 003 Device 046: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget
B. You will also need to edit the network connection ipv4.method. Set this to link-local
Example : nmcli c ** to view the connections
nmcli c mod ‘Wired connection 2’ ipv4.method link-local ** modify the connection
(Note this can be done via the GUI using the settings > network option.)
C. You should be able to ping raspberrypi.local and get a response. Now you can connect to the PI via ssh.
D. You can validate the ip via arp -a or nmap -sP 169.254.0.0/16 (nmap will take about 10-15 min to run). You should receive a 169.254.x.x ip.
A. If you have Apple itunes installed. You should be good with just inserting the PI into the USB port.Then open putty to connect to raspberrypi.local. You can confirm if the device is recognized by going to the device manager.
B. If you encounter issues and you do not have itunes installed. Try installing the Bonjour application directly via https://support.apple.com/kb/DL999?locale=en_US
C. You should then be able to connect to the PI via putty.
If you are sure you followed all of the PI setup steps and Windows is unable to locate the host. There may be another unknown issue blocking the .local url . You can access the PI via IP by following the below steps.