Skip to content

Instantly share code, notes, and snippets.

@niun
Last active August 2, 2024 00:20
Show Gist options
  • Save niun/a97f32a14a35d41a2a5ff4d36dab7028 to your computer and use it in GitHub Desktop.
Save niun/a97f32a14a35d41a2a5ff4d36dab7028 to your computer and use it in GitHub Desktop.

Raspberry Pi (Zero) as Network Adapter USB Gadget

HowTo Summary for the Host PC <- Ethernet over USB Cable -> Raspi connection with a Windows focus

Requires a Raspberry Pi with a DWC USB controller. Should work with Raspberry Pi Zero (v1, v1.3, W, WH, 2 W), A, A+, 3A+, 4B. Raspi 5 with firmware update sudo rpi-update is said to work also.

These guides have more details but are not updated for Raspberry Pi OS Bookworm which changed some network configuration related stuff (migrated to NetworkManager?):

Create Image

Put Raspberry Pi OS Bookworm image on SD Card using Raspberry Pi Imager. Use advanced settings in Imager to enable ssh on the Raspi.

/boot in the following is the boot partition of the new created SD Card. It has a fat file system and should be writable from Windows.

Enable USB Gadget

Note

Is this step needed?

In /boot/config.txt add the following last line:

dtoverlay=dwc2as

In /boot/cmdline.txt Add the option modules-load=dwc2,g_ether after rootwait.

Configure Raspi Network

Configure Raspi network with fixed IPv4 in firstrun.sh on boot partition of new SD Card (disables Network Manager). Put the following before the line rm -f /boot/firstrun.sh (Source: thagrol on forums.raspberrypi.com):

cat >/etc/network/interfaces.d/eth0 <<'EOF'
auto eth00
allow-hotplug eth00
iface eth00 inet static
        address 169.254.1.1
        netmask 255.255.0.0

auto eth0.1
allow-hotplug etc0.1
iface usb0.1 inet dhcp

EOF

cat >/etc/network/interfaces.d/g_ether <<'EOF'
auto usb0
allow-hotplug usb0
iface usb0 inet static
        address 169.254.1.1
        netmask 255.255.0.0

auto usb0.1
allow-hotplug usb0.1
iface usb0.1 inet dhcp

EOF

First Startup

A micro USB to USB-A cable should be enough to connect a Raspberry Pi Zero to a host PC and supply it with power at the same time. For When Raspi gets detected as Serial Port device in Windows

  • Device Manager > Update Driver > Select manually
  • If no Network adapter driver selectable

Now it should be possible to SSH into the Raspi when it is simply conneced to the host computer:

ssh -l <username> 169.254.1.1

Share (Windows) Host PC's Internet Access with the Raspi

Start Menu > type "View Network Connections" > Properties of internet connection > Sharing > check "Allow other network users to connect through this computer's Internet connection". If a drop down is present, select the Raspi's RNDIS/USB Gadget connection there. For me there is no dropdown and connection sharing is not working yet.

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