Skip to content

Instantly share code, notes, and snippets.

@pbosetti
Last active June 6, 2025 12:23
Show Gist options
  • Save pbosetti/f5a539810f85ae17ab6eda0864e986b9 to your computer and use it in GitHub Desktop.
Save pbosetti/f5a539810f85ae17ab6eda0864e986b9 to your computer and use it in GitHub Desktop.
Raspi5 Ethernet via USB-C

What

The following lets you connect a Raspberry Pi 5 to a laptop via USB-C cable and have an Ethernet speedy connection via the same cable. One cable for both power and data flow, without hiccups of WiFi, and works perfectly with Visual Studio Code remote SSH.

Tested on 2025-05-29.

NOTE: Currently I cannot get it to work on Windows, for it stubbornly keeps mounting the Raspberry as a COM device.

Procedure

  1. Be sure to enable the SSH server on raspi-config. Also, you should disable the GUI on boot.

  2. Edit the file /boot/firmware/cmdline.txt and add the following just AFTER rootwait:

modules-load=dwc2,g_ether
  1. Edit the file /boot/firmware/config.txt and confirm it has an UNCOMMENTED line near the end that is otg_mode=1. Then add below the line [all] (it MUST to be after the [all] line for it to work properly) the following:
dtoverlay=dwc2
  1. Now we need to add our connection name by running the following command:
sudo nmcli con add type ethernet con-name ethernet-usb0
  1. Now edit the file we just created, named /etc/NetworkManager/system-connections/ethernet-usb0.nmconnection. You will be adding the lines for autoconnect and interface-name, and then modifying the line with method= to change auto to shared:
[connection]
id=ethernet-usb0
uuid=<random group of characters here>
type=ethernet
autoconnect=true
interface-name=usb0
  
[ethernet]
  
[ipv4]
method=shared
  
[ipv6]
addr-gen-mode=default
method=auto
  
[proxy]
  1. Create yet another new file (again with vi or nano) at /usr/local/sbin/usb-gadget.sh with the following contents:
#!/bin/bash

nmcli con up ethernet-usb0
  1. Make this new file executable:
sudo chmod a+rx /usr/local/sbin/usb-gadget.sh
  1. Create yet another file named /lib/systemd/system/usbgadget.service with the following text:
[Unit]
Description=My USB gadget
After=NetworkManager.service
Wants=NetworkManager.service
  
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/usb-gadget.sh
  
[Install]
WantedBy=sysinit.target
  1. Run the following command to enable this new service:
sudo systemctl enable usbgadget.service
  1. Reboot your pi5 so all your changes can be put to use. Run the following command to reboot it:
sudo shutdown -r now
  1. On your laptop, you should now have a new Ethernet interface of type RNDIS/Ethernet Gadget. Look at its IP. Suppose that the IP assigned to this interface is 10.24.0.138, the Raspi address should be 10.24.0.1, so you can just ssh <user>@10.24.0.1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment