Page 1 of 1

PiZero usb internet gadget from another pi

Posted: Sun May 29, 2016 8:25 pm
by geneworld
Hey guys I've come across a question that i haven't been able to find a solution for. I have one of my Pi Zero's set up as a usb gadget connected to my Pi 3 through ssh. I've seen posts on how to enable internet through the host computer via both windows and mac but i haven't yet been able to figure out/ find how to set it up through linux on another raspberrypi. Has anyone been able to get this to work?

Thanks!

Re: PiZero usb internet gadget from another pi

Posted: Sun May 29, 2016 8:53 pm
by DougieLawson
If both interfaces support it you need the bridge-utils
sudo -i
apt-get install bridge-utils
brctl addbr br0
brctl addif br0 eth0 usb0
exit
that doesn't work with some WiFi drivers, it may not work with the USB OTG network driver.

If not then you'll need to set up some iptables rules

Code: Select all

#!/bin/bash

iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables --table nat --append POSTROUTING --out-interface usb0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT

sysctl -w net.ipv4.ip_forward=1
and run dnsmasq

Code: Select all

interface=eth0
no-dhcp-interface=wlan0
dhcp-range=interface:eth0,192.168.2.90,192.168.2.95,infinite
Note: that assumes your regular eth0 network is 192.168.x.x/24 not 192.168.2.x/24

There may be better ways to do the dnsmasq stuff, but that's working for the couple of Raspberries I'm running (using wlan0 not usb0 in my case).

Re: PiZero usb internet gadget from another pi

Posted: Mon May 30, 2016 6:47 am
by geneworld
Great I'll give it a try! Thanks!

Re: PiZero usb internet gadget from another pi

Posted: Wed Jun 08, 2016 1:31 pm
by Eastonboy99
I have tried both the Bridge and the iptables version of trying to give the Pi zero internet. Neither have worked for me. Are there any other ways where I could bridge the Ethernet and the USB adapters so that I can access the Zero on any computer on my network?