First of I followed this guide to turn my raspberry pi zero into a ethernet gadget. Then I added this to /etc/network/interfaces:
Code: Select all
allow-hotplug usb0
iface usb0 inet static
address 10.0.1.2
netmask 255.255.255.0
gateway 10.0.0.1
Code: Select all
allow-hotplug usb0
iface usb0 inet static
address 10.0.1.1
netmask 255.255.255.0
gateway 10.0.0.1
I could ssh into my raspberry pi zero with ssh [email protected] but my next goal was to share network access, so I could run stuff like ping google.com on my raspberry pi zero. I found this guide which explains how to forward network access from wlan0 to eth0 and I tried doing the same with usb0.
I added pre-up iptables-restore < /etc/network/iptables.conf to /etc/network/interfaces. This is the content of my iptables.conf file:
Code: Select all
# Generated by iptables-save v1.4.21 on Tue Feb 16 16:41:38 2016
*mangle
:PREROUTING ACCEPT [472:58950]
:INPUT ACCEPT [324:32281]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [30694:35635555]
:POSTROUTING ACCEPT [30694:35635555]
COMMIT
# Completed on Tue Feb 16 16:41:38 2016
# Generated by iptables-save v1.4.21 on Tue Feb 16 16:41:38 2016
*filter
:INPUT ACCEPT [57:4180]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [2194:2536976]
-A FORWARD -i usb0 -j ACCEPT
-A FORWARD -i wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
COMMIT
# Completed on Tue Feb 16 16:41:38 2016
# Generated by iptables-save v1.4.21 on Tue Feb 16 16:41:38 2016
*nat
:PREROUTING ACCEPT [6:821]
:INPUT ACCEPT [1:242]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o wlan0 -j SNAT --to-source 10.0.0.115
COMMIT
# Completed on Tue Feb 16 16:41:38 2016
Code: Select all
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Unfortunently network is still unreachable on my raspberry pi zero after rebooting both my raspberry pi 2 and raspberry pi zero. This is the output of route on my raspberry pi 2:
Code: Select all
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.0.0.1 0.0.0.0 UG 0 0 0 wlan0
10.0.0.0 * 255.255.255.0 U 0 0 0 wlan0
10.0.1.0 * 255.255.255.0 U 0 0 0 usb0