2

I followed the answer to this question:

Access point as WiFi router/repeater with additional WiFi-dongle

To have my 3 B+ act as a WiFi hotspot where wlan1 connects to the internet (WAN) and the pi acts as a router with devices connecting to wlan0 on the LAN side.

That works great but I also want to connect a LAN device to eth0

I think I just need to bridge eth0 and wlan0 but haven’t been able to make it work.

1 Answers1

2

To bridge eth0 with wlan0 I will start with the setup you have already done with Access point as WiFi router/repeater with additional WiFi-dongle.

You will get this setup:

          (dhcp
        from RPi)        bridge
           ╱    wifi    ┌───────┐
mobile-phone <~.~.~.~.> │(wlan0)│              wifi            wan
                        │    br0│RPi(wlan1) <.~.~.~.~> router <───> INTERNET
      laptop <────────> | (eth0)│╲       ╲
           ╲    wired   └───────┘╱      (dhcp
         (dhcp          192.168.4.1   from router)
       from RPi)

From the already done setup first rename 08-wlan0.network:

rpi ~$ sudo -Es
rpi ~# mv /etc/systemd/network/08-wlan0.network /etc/systemd/network/16-br0_up.network

and change line Name=wlan0 into Name=br0 in /etc/systemd/network/16-br0_up.network.

Then add these two files:

rpi ~# cat > /etc/systemd/network/02-br0.netdev <<EOF
[NetDev]
Name=br0
Kind=bridge
EOF

rpi ~# cat > /etc/systemd/network/04-br0_add-eth0.network <<EOF
[Match]
Name=eth0
[Network]
Bridge=br0
EOF

Now we have to tell wpa_supplicant for wlan0 to use a bridge. We do it by modifying its service with:

rpi ~# systemctl edit wpa_supplicant@wlan0.service

In the empty editor insert these statements, save them and quit the editor:

[Service]
ExecStartPre=/sbin/iw dev %i set type __ap
ExecStartPre=/bin/ip link set %i master br0

ExecStart=
ExecStart=/sbin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-%I.conf -Dnl80211,wext -i%I -bbr0

ExecStopPost=-/bin/ip link set %i nomaster
ExecStopPost=-/sbin/iw dev %i set type managed

Reboot.
That's it.

Update in respect of a comment:

The interfaces are still wlan0 and wlan1 but on some boots the onboard is wlan0 and sometimes wlan1.

This is a classical use case for Predictable Network Interface Names. You should enable it and use the new interface names instead of wlan0 and wlan1. The new names, for example enp9s0 (wired) or wlxe894f61b0a92 (wireless), will never change. To enable predictable network interface names you can use sudo raspi-config and select 2 Network Options -> N3 Network interface names. If this doesn't help you can also append net.ifnames=1 to the line in /boot/cmdline.txt.

Ingo
  • 42,961
  • 20
  • 87
  • 207