MCorePI Mine: Workers Unite!

By tjohnson , 21 May, 2025
mcmclose

Dual Pi Zero USB Gadget Interfaces with Static IP & /30 Routing

When using multiple Raspberry Pi Zero devices via USB gadget Ethernet (g_ether), each device shows up on the host as its own isolated Ethernet interface. These are point-to-point links and each must be configured with its own subnet or precise route.


βœ… Overview: My Setup

  • Subnet mask: 255.255.255.252 (/30) for precise point-to-point routing
  • Two Pi Zeros connected via USB:
Interface Host IP Pi IP Subnet
enxbe2fea22f916 192.168.7.1 192.168.7.2 192.168.7.0/30
enxb21f48a9110b 192.168.7.3 192.168.7.4 192.168.7.2/30

πŸ§ͺ Step 1: Test Configuration Manually

Assign IPs:

sudo ip addr add 192.168.7.1/30 dev enxbe2fea22f916
sudo ip addr add 192.168.7.3/30 dev enxb21f48a9110b

Add routes to reach each Pi:

sudo ip route add 192.168.7.2 dev enxbe2fea22f916
sudo ip route add 192.168.7.4 dev enxb21f48a9110b

Restart interfaces (if needed):

sudo ip link set enxbe2fea22f916 down
sudo ip link set enxbe2fea22f916 up

sudo ip link set enxb21f48a9110b down
sudo ip link set enxb21f48a9110b up

Once configured, ping and ssh should work for both devices.


🧷 Step 2: Make It Permanent

If you're using ifupdown (common in legacy Debian installs):

Create 2 config files:

# /etc/network/interfaces.d/enxbe2fea22f916
auto enxbe2fea22f916
iface enxbe2fea22f916 inet static
  address 192.168.7.1
  netmask 255.255.255.252
  up ip route add 192.168.7.2 dev enxbe2fea22f916
# /etc/network/interfaces.d/enxb21f48a9110b
auto enxb21f48a9110b
iface enxb21f48a9110b inet static
  address 192.168.7.3
  netmask 255.255.255.252
  up ip route add 192.168.7.4 dev enxb21f48a9110b

Reload and bring interfaces up:

sudo ifdown enxbe2fea22f916 || true
sudo ifup enxbe2fea22f916

sudo ifdown enxb21f48a9110b || true
sudo ifup enxb21f48a9110b

πŸ“˜ Understanding /30 (CIDR 255.255.255.252)

A /30 subnet provides exactly 4 IP addresses:

  • 1 network address
  • 2 usable host IPs
  • 1 broadcast address

This is perfect for a direct USB connection between two devices:

192.168.7.0/30
β†’ Usable: 192.168.7.1 (host), 192.168.7.2 (Pi)

192.168.7.2/30
β†’ Usable: 192.168.7.3 (host), 192.168.7.4 (Pi)

Trying to route an entire /24 through one USB gadget interface won’t work β€” each one is a point-to-point pipe and must be treated as such.


πŸ› οΈ Optional: udev & Custom Naming

For easier automation, create a udev rule to rename interfaces:

# /etc/udev/rules.d/99-usbgadget.rules
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="be:2f:ea:22:f9:16", NAME="piusb0"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="b2:1f:48:a9:11:0b", NAME="piusb1"

Then update your interface files to match piusb0 and piusb1.


βœ… Summary

  • Each USB gadget device must use its own /30 subnet
  • One route per interface
  • Manual configuration works, but persistent config via /etc/network/interfaces.d/ is cleaner
  • Use udev to simplify naming and avoid renaming issues after reboots

Triple β€œ5” Farms Tech Division β€” precision USB networking, one Pi at a time.