Raspberry pi OTG cluster networking raspberry pi3 and raspberry pi zero

Let's assume you have two raspi zero and one raspi3, we want to connect pi zeros to reach internal networking with raspi3 as host and internet over raspi3.

Add this to /boot/cmdline.txt after rootwait
pizero1
modules-load=dwc2,g_ether g_ether.host_addr=00:22:82:ff:ff:01 g_ether.dev_addr=00:22:82:ff:ff:11 quiet
pizero2
modules-load=dwc2,g_ether g_ether.host_addr=00:22:82:ff:ff:02 g_ether.dev_addr=00:22:82:ff:ff:12 quiet

Add this to /boot/config.txt
pizero1 and pizero2
dtoverlay=dwc2
gpu_mem=16

Add this to /etc/dhcpcd.conf 
pizero1
interface usb0
static ip_address=192.168.7.2/24
static routers=192.168.7.1
static domain_name_servers=8.8.8.8

pizero2
interface usb0
static ip_address=192.168.7.2/24
static routers=192.168.7.1
static domain_name_servers=8.8.8.8


edit /etc/sysctl.conf make ip forward 1 and check if it's ok
sudo sysctl -p /etc/sysctl.conf
net.ipv4.ip_forward = 1

make sure ip forward is 1 and add this iptables entries based on your network conn eth0 or wlan0 if you are using wifi
sudo sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward' 
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -t nat -A POSTROUTING -o
wlan0 -j MASQUERADE

for raspi3
add this to /etc/dhcpcd.conf 
interface eth1
static ip_address=192.168.7.1/24
static domain_name_servers=8.8.8.8 

interface eth2
static ip_address=192.168.8.1/24
static domain_name_servers=8.8.8.8  

add this to /etc/udev/rules.d/90-pi-network.rules
SUBSYSTEM=="net", ATTR{address}=="00:22:82:ff:ff:01", NAME="eth1"
SUBSYSTEM=="net", ATTR{address}=="00:22:82:ff:ff:02", NAME="eth2"


now you can connect pizeros from raspi3 with and they can reach internet
ssh 192.168.7.2
ssh 192.168.8.2


now you can try pinging google from pizeros
ping google





Comments

Popular posts from this blog

Pyppeteer fix for BrowserError: Browser closed unexpectedly

overlay filesystem and containers

How to add pagination to django comments for your model