3

My hardware setup is currently:

Router -> RPi (eth0) -> RPi (wlan0) -> subnet for my devices

My desired setup is:

Router -> RPi (eth0) -> RPi (wlan0 + eth1) -> subnet for my devices

My setup:

The RPi access point creates a new subnet with hostapd and dnsmasq. It distributes new IP addresses over wlan0, while getting its internet access over eth0. eth0 is the interface of the dedicated ethernet port on my RPi.

I connected a USB-Ethernet dongle to my RPi to provide a wired connection to some devices. It is detected as eth1. All devices connected to it (via a switch) need to live within the same new subnet and be able to find the devices connected over wlan0.

I used RaspAP for my initial setup, but manual steps might be necessary now I think.

Creating a second hostapd config for eth1 would just open a second subnet, as far I understand, so that's not what I want. I read something about installing a bridge for wlan0 and eth1 (or "bonding" them together), and then choose the newly created interface as the AP interface via RaspAP but I didn't get it to work correctly.

What is the correct/best way to establish a subnet which can be accessed simultaneously via wifi (wlan0) and the USB dongle (eth1) of the RPi?

Edit: My dhcpcd.conf looks like this:

interface wlan0
static ip_address=10.3.141.1/24
static routers=10.3.141.1
static domain_name_servers=1.1.1.1 1.0.0.1
interface eth1
static ip_address=10.3.141.1/24
static routers=10.3.141.1
static domain_name_servers=1.1.1.1 1.0.0.1
interface eth0
static ip_address=10.168.57.151/24
static routers=10.168.57.1
static domain_name_servers=10.168.57.1 8.8.8.8

Adding # to either the 4 eth1 or wlan0 rules makes the other work, but having both entries uncommented, only the lower one works. Maybe it has something to do with conflicting static IP addresses or the router IP address, but doesn't they need to be the same, if I want them to be in the same subnet?

UPDATE with info from comment:
I am using a Raspberry Pi 2 Model B Rev 1.1 with Raspbian GNU/Linux 9 (stretch) and the TP-Link TL WN823N RTL8192EU WiFi Dongle.

Ingo
  • 40,606
  • 15
  • 76
  • 189
  • 1
    Did you config `iptables`. It might work if you add some rule like: `sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT` || `sudo iptables -A FORWARD -i wlan0 -o eth1 -j ACCEPT` – M. Rostami Feb 01 '20 at 21:26
  • 1
    Yes I tried that, unfortunately it didn't help. I only get eth1 **or** wlan0 to work, depending on which interface I have listed in `dhcpcd.conf`. If I list both interfaces in this config file, only the one works, which is written lower in the file – Felix Bernhard Feb 01 '20 at 21:35
  • 1
    Alright, it would help others if you add all the procedures done. – M. Rostami Feb 01 '20 at 21:40
  • 1
    Okay, I edited my question. Apart from what I mentioned, I did nothing manually, just the default RaspAP setup. – Felix Bernhard Feb 01 '20 at 21:41
  • 1
    As the edited section, you should set `eth0` in DHCP client mode because it would get ip address from `wlan0` DHCP server. It could work if you add suitable rule to `iptables`. – M. Rostami Feb 01 '20 at 21:43
  • `eth0` is the interface where the router is connected to (where the internet is coming from). Do you mean `eth1`? How can I set `eth1` in "DHCP client mode"? – Felix Bernhard Feb 01 '20 at 22:09
  • Yes, I meant `eth1`. Simply by comment all lines of `eth1` by a `#`. – M. Rostami Feb 01 '20 at 23:18
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/103979/discussion-between-felix-bernhard-and-m-rostami). – Felix Bernhard Feb 01 '20 at 23:44

2 Answers2

4

If you are open to use another modern all-in-one networking environment without needing additional helpers like hostapd, dnsmasq or bridge utils you can use systemd-networkd. It makes life easier. It is part of the default Raspbian image and you only have to enable and configure it. Here is a tested and working setup for what you want to do: Configuring Raspberry pi as Router, Wifi and Ethernet Bridge. The only difference is that it uses eth0 for the bridge and eth1 as uplink but it should not be a big issue to just swap the interfaces in the setup or just swap the ethernet cables on your RasPi ;-)

Seamus
  • 18,728
  • 2
  • 27
  • 57
Ingo
  • 40,606
  • 15
  • 76
  • 189
  • Well, this setup seems to work. I set it all up but until now I am unable to get the WiFi AP to work with the new wpa_supplicant config. The connection via the Ethernet cable works just fine and I am able to see the ssid of the newly created wifi, but I can't connect any devices to it. It always says "connection failed" and wpa_supplicant logs `AP-STA-DISCONNECTED` with `OnDisassoc(wlan0) reason=8`. The WiFI AP worked just fine while utilizing hostapd with the old setup (RaspAP). Do you maybe know what's wrong here? – Felix Bernhard Feb 03 '20 at 02:13
  • I disabled the wpa_supplicant part, reinstalled hostapd and setup the access point as before. Everything works now! – Felix Bernhard Feb 03 '20 at 03:00
  • @FelixBernhard I don't know why the AP with wpa_supplicant refused connection. I'm very interested to reproduce it but I can't. I have another single failing setup [Android won't connect to RasPi access point](https://raspberrypi.stackexchange.com/a/107492/79866). What RasPi version do you use? RPi 4B? What Raspbian version do you use? Buster? With what devices do you try to connect to the AP? Android? What may be a difference between yours and my setup? – Ingo Feb 03 '20 at 09:09
  • I am using a `Raspberry Pi 2 Model B Rev 1.1` with `Raspbian GNU/Linux 9 (stretch)` and the `TP-Link TL WN823N RTL8192EU` WiFi Dongle. I tried to connect to the AP with both an iPhone 6S (iOS 13) and a Windows Laptop (Windows 10) with both saying `connection failed`. – Felix Bernhard Feb 03 '20 at 13:17
0

What you want is a bridge device. This would be "br0" instead of "wlan0" and "eth1".

Then I believe you list the bridged devices on a "bridge_ports" line in /etc/network/interfaces or equivalent.

In any case, you install bridge-utils, and the "brctl" command gets run automatically when you run ifup and ifdown.

You might read /usr/share/doc/ifupdown/examples/bridge

David G.
  • 225
  • 1
  • 2
  • 6