Skip to content

USB Ethernet Gadget Setup

This guide explains how to set up a USB Ethernet Gadget (g_ether) to connect a Raspberry Pi via USB and enable SSH access from a PC.

1. Raspberry Pi Setup

1.1 Enable OTG Function

Edit /boot/firmware/config.txt to enable OTG function.

sudo nano /boot/firmware/config.txt
Add the following line:
dtoverlay=dwc2
Save and exit (Ctrl + XYEnter).

1.2 Load Kernel Modules

Edit /boot/firmware/cmdline.txt to load dwc2 and g_ether.

sudo nano /boot/firmware/cmdline.txt
Add the following after rootwait:
modules-load=dwc2,g_ether
Note: Ensure it remains on a single line. Save and exit (Ctrl + XYEnter).

1.3 Network Configuration

Set a static IP for the usb0 interface on the Raspberry Pi (optional).

sudo nano /etc/dhcpcd.conf
Add the following:
interface usb0
static ip_address=192.168.7.2/24

1.4 Reboot

Reboot the Raspberry Pi to apply the changes.

sudo reboot

2. PC Setup

2.1 Verify Network Interface After USB Connection

Connect the Raspberry Pi to the PC via USB and check the interfaces.

ip a
Ensure usb0 appears in the list.

2.2 Set IP on PC (Linux)

sudo ip addr add 192.168.7.1/24 dev usb0
sudo ip link set usb0 up

For Windows: Open ncpa.cpl, locate the usb0 adapter, and manually assign 192.168.7.1/24.


3. SSH Connection

Connect to the Raspberry Pi via SSH from the PC.

ssh pi@192.168.7.2
Or, if Bonjour (Avahi) is enabled:
ssh pi@raspberrypi.local

✅ Summary

  • Enabled g_ether to establish a virtual network over USB.
  • Configured usb0 on the PC with a static IP to enable SSH access.
  • No serial connection needed! Just a USB cable for SSH! 🎉