raspberrypi ethernet gadget


Enable module

  1. Apply the steps in section 4.2
  2. Back up /boot/firmware/cmdline.txt
sudo cp /boot/firmware/cmdline.txt /boot/firmware/cmdline.txt.bak
  1. Using you preferred text editor add the following to the end of /boot/firmware/cmdline.txt
modules-load=dwc2,g_ether  g_ether.dev_addr=12:22:33:44:55:66 g_ether.host_addr=16:22:33:44:55:66

Replace the MAC addresses above as required. The contents of /boot/firmware/cmdline.txt must be one a single line 6. Save 7. Reboot

Verify It’s Working

  1. Boot your USB host.
  2. Connect the raspberrypi and allow it to boot
  3. Log in to your USB host.
  4. Run
lsusb

The output should contain a line similar to this one

Bus 001 Device 011: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget
  1. Run
ifconfig -a

The output should contain details for a usb0 interface. 8. At this stage it will not be possible to communicate over the link as networking has not yet been configured.

Basic Network Configuration

Note: RPiOS Bookworm or later. Bullseye and earlier do not use Network Manager unless explicitly configured to do so.

You will need to be root or use sudo to perform these steps.

  1. Create a new conection:
nmcli con add con-name my-connection type ethernet ifname usb0 ipv4.method manual ipv4.address x.x.x.x/y

Replace my-connection with your desired name, x.x.x.x with your desired IP address, and y with the desired netmask

For example:

nmcli con add con-name g_ether type ethernet ifname usb0 ipv4.method manual ipv4.address 10.0.0.1/24
  1. Activate connection
nmcli con up my-connection
  1. For more information on nmcli see
man nmcli

For a text menu based alternative try nmtui.

Troubleshooting

Windows24 Doesn’t Recognise The Zero Or Installs The Wrong Driver

Try using rndis here

Try using linux.inf or linux-cdc-acm.inf from here