internet access to a raspberry pi zero through usb

In my previous post, I set up the ability to ssh into a pi zero (not pi zero w) via usb.  Since I got that far,  I was pretty sure it was possible to give internet access to my pi zero through my laptop.  Turns out it is not that difficult.  First I set up a default route on the pi to send all packets not on the local subnet to my laptop:

sudo route add default gw

Now here is my routing table on the pi:

NAT router to give pi zero internet access
NAT router to give pi zero internet access

Next, I set up my laptop to essentially be a NAT router for the pi zero.  This is how to share my laptop’s internet connection with my pi:

modprobe iptable_nat
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o enp1s0 -j MASQUERADE
iptables -A FORWARD -i enps0s18f2u1 -j ACCEPT

Now my pi zero has internet access.  I tested by pinging my favorite dns server  However, when I try to ping my beloved employer’s domain, I get nowhere.  After I added a dns server to /etc/resolv.conf,  I am good to go:

pi zero internet access via usb
pi zero internet access via usb

Leave a Reply

Your email address will not be published. Required fields are marked *