geneworld
Posts: 67
Joined: Sun Jan 19, 2014 11:46 pm

PiZero usb internet gadget from another pi

Sun May 29, 2016 8:25 pm

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!
1 B R1
4B R2 IR
1B+ USB Boot/RetroPie2.6/KODI
1Pi2 USB Boot/Media Server/Torrent Box
1Pi Zero Web-based universal remote control
2Pi Zero Misc.
1Pi3 USB Boot/RetroPie3.6/KODI/pianobar

User avatar
DougieLawson
Posts: 35789
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: PiZero usb internet gadget from another pi

Sun May 29, 2016 8:53 pm

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).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

geneworld
Posts: 67
Joined: Sun Jan 19, 2014 11:46 pm

Re: PiZero usb internet gadget from another pi

Mon May 30, 2016 6:47 am

Great I'll give it a try! Thanks!
1 B R1
4B R2 IR
1B+ USB Boot/RetroPie2.6/KODI
1Pi2 USB Boot/Media Server/Torrent Box
1Pi Zero Web-based universal remote control
2Pi Zero Misc.
1Pi3 USB Boot/RetroPie3.6/KODI/pianobar

Eastonboy99
Posts: 6
Joined: Sat Jan 16, 2016 11:04 pm

Re: PiZero usb internet gadget from another pi

Wed Jun 08, 2016 1:31 pm

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?

Return to “Advanced users”