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.

  • I will extend the setup you have used, with a bridge with wlan0 and eth0. Just a moment please. – Ingo Jun 25 at 8:20
  • An dhcp server must run on your AP for wireless clients private network (assume wlan0) and on Ethernet (assume eth0) for wire clients private network. I cannot help you because I'm not familiarized with the default dhcp server but if you use dnsmasq , then I can help you. But the steps are the same : 1) assign an ip address to wlan0 (10.17.1.1/24) and eth0 (10.17.0.1/24) interfaces. 2) Bind your dhcp server on this precise addresses and configure the 'client network' scope in configuration file. 3) start the DHCP daemon(s ?). – Ephemeral Jun 25 at 20:21
  • For dnsmasq I use two instance (yes two dhcp and dns server listening on two different network) for that. I exclude necessary interfaces in dnsmasq.conf for dhcp and dns, bind the interfaces on specific assigned ip addr .... and It's work for me. – Ephemeral Jun 25 at 20:22
  • @lngo - that would be very much appreciated. – William Meyer Jun 26 at 15:43
1

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.

  • Thank you so much for your help Ingo, we just returned from a long European vacation and it worked perfectly on the airplane and cruise ship. The kids were thrilled to have Plex available! Now that I'm home, I tried the same steps on a Pi 4 but it doesn't work. It looks like the root of the problem is randomly identifying the on-board and WiFi dongle as wlan0 and wlan1. I tried setting them statically the way you can on Stretch but it didn't work. – William Meyer Jul 23 at 20:15
  • @WilliamMeyer What are the names of the interfaces on RPi 4B? Check with networkctl. – Ingo Jul 23 at 20:24
  • they are still wlan0 and wlan1 but on some boots the onboard is wlan0 and sometimes wlan1. – William Meyer Jul 24 at 17:13
  • @WilliamMeyer I have updated my answer at the end. – Ingo Jul 24 at 18:09
  • 1
    After looking at it again this morning I realized wl is Wireless Lan and xe894f61b0a92 is the MAC address of the adapter! I understand what is going on now so I'll take another run at it and see if I can get it to work. – William Meyer Jul 25 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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