Chapter 23:

RNDIS GADGET

Creating a Raspberry Pi Zero RNDIS Gadget

This guide will walk you through setting up a Raspberry Pi Zero as an RNDIS (Remote Network Driver Interface Specification) Ethernet Gadget. This turns your Pi Zero into a device that, when plugged into a USB port on another computer, acts as an Ethernet connection.

Requirements

  • Raspberry Pi Zero

  • Micro SD card with Raspbian OS installed

  • Access to the Pi Zero for initial setup (keyboard, monitor, etc.)

  • A host computer (e.g., Windows 10)

Step 1: Modify Boot Configuration

  1. Configure config.txt and cmdline.txt:

    • Mount your Pi's SD card on your computer.

    • Open config.txt and add the following line at the end:

      dtoverlay=dwc2

    • In cmdline.txt, insert

      modules-load=dwc2,g_ether

      after rootwait. Ensure there is only one space between each item and no new lines are added.

Step 2: Set Up Network on Pi Zero

  1. Configure Network Interfaces:

    • Insert the SD card back into your Pi Zero, boot it up, and open the terminal.

    • Edit the dhcpcd.conf file:

      sudo nano /etc/dhcpcd.conf

    • Add these lines to set a static IP for the usb0 interface:

      interface usb0 static ip_address=192.168.2.2/24 static routers=192.168.2.1 static domain_name_servers=8.8.8.8

Step 3: Connect to Windows 10 Host

  1. Plug Pi Zero into Windows 10 PC:

    • Use a USB cable to connect the Pi Zero to your Windows 10 computer.

    • Windows should recognize it as a new network interface.

  2. Configure Windows 10 Network Sharing:

    • Go to 'Network and Sharing Center' > 'Change adapter settings'.

    • Right-click your primary internet connection and select 'Properties'.

    • Go to the 'Sharing' tab.

    • Check 'Allow other network users to connect through this computer’s Internet connection'.

    • In the 'Home networking connection' drop-down, select the new network connection that corresponds to your Pi Zero.

  3. Set RNDIS Ethernet IPv4 Settings:

    • Right-click on the RNDIS connection (Pi Zero), go to 'Properties', and select 'Internet Protocol Version 4 (TCP/IPv4)'.

    • Click 'Properties', then 'Use the following IP address'.

    • Set the IP address to 192.168.7.1 and subnet mask to 255.255.255.0.

Finalizing

  • Your Raspberry Pi Zero should now be accessible from your Windows PC via SSH or VNC at the static IP 192.168.2.2.

  • The Pi Zero will also have access to the internet through your PC’s shared connection.

Notes

  • Ensure the Pi Zero is properly powered and connected before attempting to access it.

  • This setup is ideal for creating a portable, low-power computer with network access via the host PC.

  • Always safely eject the SD card from your computer after modifying files to prevent corruption.

Note: Setting up an RNDIS gadget can be a technical process, and it's crucial to follow the steps carefully. If you encounter any network issues, double-check your configuration settings.