Skip to content

Instantly share code, notes, and snippets.

@tomazursic
Last active November 13, 2017 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomazursic/d9315e90003e39f400009f0957142de8 to your computer and use it in GitHub Desktop.
Save tomazursic/d9315e90003e39f400009f0957142de8 to your computer and use it in GitHub Desktop.

Raspbeerry Pi USB gadget

  1. Fresh sd card with Raspbian

  2. Enable ssh

Add empty file "ssh" to /boot partition on SD card

Add to config.txt

dtoverlay=dwc2

Add to cmd.txt

modules-load=dwc2,g_ether

Edit your /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)

Plug in the USB cable from your computer to the "USB" connector port on the Pi Zero, not the PWR connector.

ssh pi@raspberrypi.local

Sharing Internet

  1. RNDIS USB connection to your Raspberry Pi by selecting Manually from the Configure IPv4 menu. Use 192.168.2.1 for the IP Address, and 255.255.255.0 for the Subnet Mask. Click Apply to save your changes.

  2. Sharing tab in System Preferences.

Share your connetion from: WiFi Turn on RNDIS Turn on Internet Sharing

Edit your /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo usb0
iface lo inet loopback

iface eth0 inet manual

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

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug usb0
iface usb0 inet manual

Static IP

allow-hotplug usb0
iface usb0 inet static
        address 192.168.7.2
        netmask 255.255.255.0
        network 192.168.7.0
        broadcast 192.168.7.255
        gateway 192.168.7.1

sudo ifdown usb0
sudo ifup usb0
ifconfig usb0

MacOSX setup:

System Preferences -> Network box

Configure IP4 Manually

For the IP address pick 192.168.7.1 (note that this is not the same as the Pi Zero's address!)
For the subnet mask, use 255.255.255.0  (same as Pi)
For the router/gateway use 192.168.7.1 (same as Pi)

References:

https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/ethernet-tweaks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment