0

I connected a raspberry pi 0 to a raspberry pi 4b+ via USB and i would like to know how can i share the internet connection. The pi4 is connected to the internet via the ethernet port. P.S.: I did all the configuration needed for the pi0 (loaded dwc2, gether and the rest), also both pi run lattest version of raspbian

2 Answers 2

0

This is how I achieved it:


on the pi4

to /etc/dhcpcd.conf [before the first line that starts with interface or to the end of the file, if no such lines exists]

denyinterfaces eth0 usb0

to the end of the file, add

interface br0

create the following files in /etc/systemd/network - note, the names of the files are unimportant, the important thing is the extension (.netdev/.network) and the content

bridge-br0.netdev

[NetDev]
Name=br0
Kind=bridge

br0-member-eth0.network

[Match]
Name=eth0

[Network]
Bridge=br0

br0-member-usb0.network

[Match]
Name=usb0

[Network]
Bridge=br0

enable systemd-networkd

systemctl enable systemd-networkd

Thats it for the pi4


on the pi 0

add the following the end of /etc/dhcpcd.conf

interface usb0

Though, I've done the following (as fallback in case DHCP fails)

profile static_usb0
static ip_address=192.168.1.122/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface usb0
fallback static_usb0

Obviously, you'd need to use your own local ip address, router and dns address as required

2
  • i tryed this 2 times , one time i couldnt connect my pi4 to the internet, and the other one i got the pi 0 connected to the internet, but the pi 4 could connect again
    – F G B
    May 31, 2021 at 15:57
  • Not sure what part you did wrong then - works great for me Jun 1, 2021 at 6:49
0

I tried the Solution from @Jaromanda X but unfortunately it didn't work for me. This instruction helped me very much: Cannot get internet from pizero connected to pi3 via USB (eth0 to usb0)

This is what I did:

enter image description here

on the pi 3/4

  1. The RaspberryPi needs a static IP-adress. You can either configure it in your Router (what I did) or you can set a static IP-adress in /etc/dhcpcd.conf like this:
# [/etc/dhcpcd.conf]

interface eth0
static_routers=192.168.178.1  # The IP-address of your router
static domain_name_servers=192.168.178.1
static ip_address=192.168.178.XX/24  # replace XX through any IP-address you want
  1. You need a network interface for your USB-connection which you can also add in /etc/dhcpcd.conf:
# [/etc/dhcpcd.conf]

# Subnet for usb0 (where the piZero is plugged)
interface usb0
static ip_address=10.0.11.1/24
  1. enable IP-forwarding by uncommenting/adding the following in /etc/sysctl.conf:
# [/etc/sysctl.conf]

net.ipv4.ip_forward=1
  1. Configure the firewall of the RaspberryPi by executing the following commands in the terminal:
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

Consider that these changes are only temporary. I put these commands into /etc/rc.local so that they are executed at every start of the pi. (I don't know if this is the best and recommended way to make the firewall settings persistent but it works)

on the pi zero

Setup the USB-inteface in /etc/dhcpcd.conf like this:

interface usb0
static ip_address=10.0.11.2
static routers=10.0.11.1
static domain_name_servers=8.8.8.8  # (Google DNS)

I also enabled dwc2 but I'm not sure if it's required.

Now you should be able to ping other devices in the internet or in your local network (e.g. 192.168.178.xx) from your RaspberryPi zero.


Consider that you are not able to access the RaspberryPi Zero from your local network because it is in the subnet (10.0.11.xx). To solve this I added a static route in my FritzBox (Home Network --> Network --> Network Settings --> IPv4-routes)

fritzbox configuration of static route


I used this to setup the clusterhat manually. It was very difficult to create a setup like this because there are barely tutorials on the internet according to the clusterhat respectively to connecting a RaspberryPi zero without WLAN to another RaspberryPi via USB.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 15, 2023 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.