1

my current configuration is as follows:

I recieve Internet from the house I live in. It comes via Ethernet and has a DHCP running. The Problem is, that it is MAC-Adress limited to one device. Therefore I got my RPi 3B v1.2 configured as Wifi Router, wich is working fine. So the configuration is:

House-Internet --eth0--> Pi --wlan0--> Laptop

IP Ranges are:

eth0 172.x.x.x

wlan0 192.168.1.x

Here is a link to my interfaces-configuration: https://bit.ly/2DZ6DgX

DHCP for wlan0 is made by dnsmasq with standard settings.

.

What I want to do: I want to configure a second ethernet-adapter to use the same network as wlan0. The eth1 dongle is a generic usb ethernet adapter. So the internet (coming from eth0 and the same network/iprange as wlan0).

I tried creating a bridge between eth1 and wlan0 with brctl. As soon as I plugin a device on eth1, I won't get internet connection on both wlan0 and eth1.

Hope you can help me.

EDIT /etc/interfaces/:


# Localhost
auto lo
iface lo inet loopback

# Ethernet
auto eth0
allow-hotplug eth0
iface eth0 inet manual

auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.1.2
netmask 255.255.255.0

auto br0
iface br0 inet dhcp
bridge_ports eth1 wlan0
bridge_fd 0
bridge_stp off

# WLAN-Interface
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0

# NAT und Masquerading aktivieren
up /sbin/iptables -A FORWARD -o eth0 -i wlan0 -m conntrack --ctstate NEW -j ACCEPT
up /sbin/iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
up /sbin/iptables -t nat -F POSTROUTING
up /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# IP-Forwarding aktivieren
up sysctl -w net.ipv4.ip_forward=1
up sysctl -w net.ipv6.conf.all.forwarding=1

# hostapd und dnsmasq neu starten
up service hostapd restart
up service dnsmasq restart

Ingo
  • 40,606
  • 15
  • 76
  • 189
Marek P
  • 11
  • 1
  • 3
  • Please paste the interfaces-configuration into the question. I have an idea how to route a bridge but only with modern *systemd-networkd*. I don't use classic networking since years anymore. – Ingo May 12 '19 at 22:42
  • Does using *systemd-networkd* is an option for you? – Ingo May 13 '19 at 07:49
  • Hi Ingo, thanks for your answer. I am open to any solutions (including using systems-networkd ; But I personally have no experience with it) I updated the Interfaces in the Post – Marek P May 13 '19 at 09:15
  • OK, what Raspberry Pi you are using? Is it a RPi 3B+? I assume you will add an USB/wired ethernet dongle as second interface **eth1**? – Ingo May 13 '19 at 09:26
  • Its a RPi 3B v1.2. The eth1 dongle is a generic usb ethernet adapter. – Marek P May 13 '19 at 13:58

1 Answers1

4

I will show a solution in two steps using systemd-networkd. First I create an access point (wlan0) and bridge it with the wired connection (eth0). Then I configure routing between the bridge (br0) and the up-link (eth1).

Tested with
Raspbian Buster Lite 2019-09-26 on a Raspberry Pi 4B updated at 2020-02-02.
Updates done with sudo apt update && sudo apt full-upgrade && sudo reboot.
Here you can find the last tested revision for previous Raspbian versions.

Example for this setup:
to be compatible with other examples from me I'm using different ip addresses. But it should not be a problem to replace them with yours.

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

♦ Setting up an access point (wlan0) and bridge it with wired ethernet (eth0)

Follow the instructions given in section "General setup" of Setting up a Raspberry Pi as an access point - the easy way.

Then create the following four files to configure interfaces.

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

rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
EOF

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

rpi ~# cat > /etc/systemd/network/16-br0_up.network <<EOF
[Match]
Name=br0
[Network]
Address=192.168.4.1/24
MulticastDNS=yes
IPMasquerade=yes
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 1.1.1.1
EOF

Now we have to tell wpa_supplicant 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 and check if the bridge works. The mobile phone and the laptop should have an ip address from subnet 192.168.4.0/24 and you should be able to ping the mobile phone from the laptop and vice versa.


♦ Configure routing between up-link eth1 and the bridge br0

Plug in the USB/ethernet dongle if not already done. You should have then an interface eth1. Now create this file to configure eth1:

rpi ~$ sudo -Es
rpi ~# cat > /etc/systemd/network/04-eth1.network <<EOF
[Match]
Name=eth1
[Network]
DHCP=yes
MulticastDNS=yes
EOF

Restart networking:

rpi ~# systemctl daemon-reload
rpi ~# systemctl restart systemd-networkd.service
rpi ~# exit
rpi ~$

That's it.

Ingo
  • 40,606
  • 15
  • 76
  • 189