Skip to content

Sharing a Network Connection with USB RNDIS

How to expose an Ethernet-over-USB interface using RNDIS in an embedded Linux device.

This English edition retains the original diagrams and practical code or command examples.

Reference diagram 1

Commands and examples

+---------------------------+
|       用户空间应用层        |  <- 例如,通过 `ifconfig` 或 `ip` 命令配置网络
+---------------------------+
              |
+---------------------------+
|     网络协议栈层(Linux)    |  <- 网络协议栈,如 TCP/IP、UDP 等
+---------------------------+
              |
+---------------------------+
|      内核网络驱动层         |  <- RNDIS 驱动,负责 USB 网络设备的初始化与数据传输
+---------------------------+
              |
+---------------------------+
|       USB 核心驱动层        |  <- 处理 USB 设备的通信,支持 RNDIS 设备
+---------------------------+
              |
+---------------------------+
|     USB 设备硬件层         |  <- 设备本身,支持 USB 规范并实现 RNDIS 协议
+---------------------------+
grep RNDIS /boot/config-$(uname -r)
modprobe rndis_host
lsusb
ifconfig -a
sudo ifconfig usb0 192.168.0.1 netmask 255.255.255.0 up
sudo dhclient usb0
sudo ifconfig usb0 192.168.0.2 netmask 255.255.255.0 up
ping 192.168.0.2
ping 192.168.0.1
scp testfile.txt [email protected]:/home/user/
scp [email protected]:/home/user/testfile.txt /local/destination/
dmesg | grep usb

Practical notes

Validate pin multiplexing, clocks, power sequencing, kernel configuration, and device-tree bindings on the target board before drawing conclusions from a test result.