I cannot get internet access from a pizero connected via USB to a pi3 connected via ethernet.
usb0 +---+
|
|
|
+------+ +---+| +------+
|ROUTER+----+PI3+v---+PIZERO|
+------+ +---+ +------+
+-^
|
+
eth0
I tried to compile info from these articles to get where I am:
- http://blog.gbaman.info/?p=791#comment-136183
- http://raspberryjamberlin.de/zero360-part-2-connecting-via-otg-a-cluster-of-raspberry-pi-zeros-to-a-pi-3/
- Sharing the Pi's WiFi connection through the Ethernet port
pi3 and piZero are running Raspbian Jessie Lite 2017-01-11. The Pi Zero was setup for headless OTG with the method described here: https://gist.github.com/gbaman/975e2db164b3ca2b51ae11e45e8fd40a#file-howtootgfast-md
I now have:
1 - pi3 configured with static ips (able to reach internet)
pi3 :: /etc/dhcpcd.conf
[...]
nohook lookup-hostname
# Static IP for ethernet access
interface eth0
static ip_address=192.168.178.77/24
static routers=192.168.178.1
static domain_name_servers=192.168.178.1
# Subnet for usb0 (where the piZero is plugged)
interface usb0
static ip_address=10.0.11.1/24
2 - pi3 able to do ipv4 fwd
pi3 :: /etc/sysctl.conf
[...]
net.ipv4.ip_forward=1
[...]
3 - pi3 firewall set up to allow eth0 / usb0 communication
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i usb0 -o eth0 -j ACCEPT
The output of the rules has been saved into a file automatically loaded by rc.local
. This is the result of iptable-save
after each reboot:
# Generated by iptables-save v1.4.21 on Mon Feb 13 12:01:27 2017
*nat
:PREROUTING ACCEPT [30:2521]
:INPUT ACCEPT [24:2233]
:OUTPUT ACCEPT [30:2616]
:POSTROUTING ACCEPT [19:1581]
-A POSTROUTING -o eth0 -j SNAT --to-source 192.168.178.77
-A POSTROUTING -o eth0 -j SNAT --to-source 192.168.178.77
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Mon Feb 13 12:01:27 2017
# Generated by iptables-save v1.4.21 on Mon Feb 13 12:01:27 2017
*filter
:INPUT ACCEPT [339:38929]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [293:33013]
-A FORWARD -i usb0 -o eth0 -j ACCEPT
-A FORWARD -i eth0 -o usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i usb0 -o eth0 -j ACCEPT
COMMIT
# Completed on Mon Feb 13 12:01:27 2017
4 - piZero configured with static ips (reachable from pi3 with ssh [email protected]
and ssh [email protected]
)
piZero :: /etc/dhcpcd.conf
[...]
interface usb0
static ip_address=10.0.11.2
static routers=10.0.11.1
static domain_name_servers=10.0.11.1
Pinging 8.8.8.8 is successful on the PiZero:
$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=5.43 ms
[...]
--- 8.8.8.8 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5006ms
rtt min/avg/max/mdev = 4.659/4.850/5.435/0.279 ms
But still no access to internet from the PiZero (impossible to ping stackexchange.com or to run apt-get update). Any ideas?