2

Raspbian Buster Lite, Raspi 3b+

I want to bond ethernet (eth0) and a USB wifi dongle (wlan1) for network/internet access. This part I've managed with success, dynamic failover works perfectly.

The problem is when I create an AP assigned to the Raspi's built-in wifi (wlan0). With the USB wifi dongle (wlan1) plugged in, I always lose AP access- wlan0 is shown as "down".

systemd-networkd with Dynamic Failover: network interfaces eth0 (Ethernet), wlan1 (USB Wifi Dongle)

#Create Systemd Network

-Es

cat >/etc/resolvconf.conf <<EOF
# Set to NO to disable resolvconf from running any subscribers. Defaults to YES.
resolvconf=NO
EOF

systemctl mask networking.service

mv /etc/network/interfaces /etc/network/interfaces~

systemctl mask dhcpcd.service

systemctl enable systemd-networkd.service

systemctl enable systemd-resolved.service

ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

cat >/etc/systemd/network/04-eth.network <<EOF
[Match]
Name=eth0
[Network]
# to use static IP (with your settings) toggle commenting the next 8 lines.
#Address=192.168.50.60/24
#DNS=84.200.69.80 1.1.1.1
#[Route]
#Gateway=192.168.50.1
#Metric=10
DHCP=yes
[DHCP]
RouteMetric=10
EOF

-Es

cat >/etc/systemd/network/08-wifi.network <<EOF
[Match]
Name=wlan1
[Network]
# to use static IP (with your settings) toggle commenting the next 8 lines.
#Address=192.168.50.61/24
#DNS=84.200.69.80 1.1.1.1
#[Route]
#Gateway=192.168.50.1
#Metric=20
DHCP=yes
[DHCP]
RouteMetric=20
EOF

cat >/etc/wpa_supplicant/wpa_supplicant-wlan1.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
    ssid="My_Wifi"
    psk="My_Password"
    key_mgmt=WPA-PSK
}
EOF

chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan1.conf

systemctl disable wpa_supplicant.service

systemctl enable wpa_supplicant@wlan1.service

Bond Network Interfaces eth0 and wlan1

############# Bond eth0 and wlan1 ###############

-Es

mv /etc/systemd/network/04-eth.network /etc/systemd/network/04-eth.network~

mv /etc/systemd/network/08-wifi.network /etc/systemd/network/08-wifi.network~

cat >/etc/systemd/network/02-bond0.netdev <<EOF
[NetDev]
# status: cat /proc/net/bonding/bond0
Name=bond0
Kind=bond
[Bond]
Mode=active-backup
# primary slave is defined in *eth.network
MIIMonitorSec=500ms
UpDelaySec=1000ms
DownDelaySec=1000ms
MinLinks=1
EOF

cat >/etc/systemd/network/12-bond0-add-eth.network <<EOF
[Match]
Name=eth0
[Network]
Bond=bond0
PrimarySlave=yes
EOF

cat >/etc/systemd/network/16-bond0-add-wifi.network <<EOF
[Match]
Name=wlan1
[Network]
Bond=bond0
EOF

cat >/etc/systemd/network/20-bond0-up.network <<EOF
[Match]
Name=bond0
[Network]
# to use static IP (with your settings) toggle commenting the next 4 lines.
DHCP=yes
IPForward=yes
#Address=192.168.50.60/24
#Gateway=192.168.50.1
#DNS=84.200.69.80 1.1.1.1
EOF

Creating Access Point, wlan0 (Raspi built-in wifi)

############# Create AP Access Point wlan0 ###############

cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="My_AP"
    mode=2
    frequency=2437
    #key_mgmt=NONE   # uncomment this for an open hotspot
    # delete next 3 lines if key_mgmt=NONE
    ## Enabling key_mgmt prevents login and returns incorrect password
    #key_mgmt=WPA-PSK
    proto=RSN WPA
    psk="My_AP_Pass"
}
EOF

chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf

systemctl enable wpa_supplicant@wlan0.service

cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.4.1/24
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 1.1.1.1
EOF

systemctl edit wpa_supplicant@wlan0.service

[Service]
ExecStartPre=/sbin/iptables -t nat -A POSTROUTING -o bond0 -j MASQUERADE
ExecStopPost=-/sbin/iptables -t nat -D POSTROUTING -o bond0 -j MASQUERADE

Reference

Setting up a Raspberry Pi as an access point - the easy way

How to migrate from networking to systemd-networkd with dynamic failover

Additional Information

I have tried using three different Wifi USB dongles:

  • RTL8811AU Chipset
  • RTL8188EUS Chipset
  • RTL8188EU Chipset
  • All of the above work and it does not seem to be a particular Wifi dongle that knocks out the Raspi's built-in Wifi.

    This behavior is consistent with Raspbian Stretch Lite and Raspbian Buster Lite, Raspi 3b+ and Raspi 4.

    I have tested this setup on Armbian Stretch and Armbian Buster (OPi hardware) and behavior is identical to Raspbian setup.

    Using predictable network interface naming. I have not tried to assign by MAC Address and would prefer not to in the event I would like to clone the drive and use another Raspi and/or Wifi dongle.

    • Thanks for your detailed feedback. I'm just checking it. At a first glance I also run into problems starting my second wifi dongle on RPi 4B, no matter if bonding or not. Haven't tested it before. Will come back. – Ingo Aug 28 at 9:42
    • Thank you! I updated my post to include Wifi dongle chipsets and specific setups I've used for testing. – Evos Aug 28 at 14:19
    • Sorry, but I had some problems with my test environment. There was a shortcut on the USB to TTL adapter for the debug console that confused the RasPi and the monitoring laptop. Fortunately the TTL shortcut doesn't fried my RasPi but what I commented before has another reason. Look at my answer. – Ingo Aug 28 at 20:01
    0

    Seems you have a conflict running the USB/WiFi dongle together with the built-in WiFi device. Starting with a fresh flashed Raspbian Buster Lite image first I verified on my Raspberry Pi 4B that it is working properly without bonding using this setup Access point as WiFi router/repeater with additional WiFi-dongle.

    It works.

    Then I flashed the image again and exactly used the setup you have given in your question. And what should I say?

    It also works.

    Here are some output for comparison:

    rpi ~$ ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever
    2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
        link/ether 9a:9f:4d:64:fa:0d brd ff:ff:ff:ff:ff:ff
    3: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
        link/ether 9a:9f:4d:64:fa:0d brd ff:ff:ff:ff:ff:ff
        inet 192.168.50.205/24 brd 192.168.50.255 scope global dynamic bond0
           valid_lft 2108sec preferred_lft 2108sec
        inet6 fe80::989f:4dff:fe64:fa0d/64 scope link
           valid_lft forever preferred_lft forever
    4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether dc:a6:32:01:db:ed brd ff:ff:ff:ff:ff:ff
        inet 192.168.4.1/24 brd 192.168.4.255 scope global wlan0
           valid_lft forever preferred_lft forever
        inet6 fe80::dea6:32ff:fe01:dbed/64 scope link
           valid_lft forever preferred_lft forever
    5: wlan1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
    link/ether 9a:9f:4d:64:fa:0d brd ff:ff:ff:ff:ff:ff
    
    rpi ~$ iw dev
    phy#1
        Interface wlan1
            ifindex 5
            wdev 0x100000001
            addr 9a:9f:4d:64:fa:0d
            ssid TestNet
            type managed
            channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz
            txpower 30.00 dBm
    phy#0
        Unnamed/non-netdev interface
            wdev 0x2
            addr aa:66:d1:aa:f6:19
            type P2P-device
            txpower 31.00 dBm
        Interface wlan0
            ifindex 4
            wdev 0x1
            addr dc:a6:32:01:db:ed
            ssid RPiNet
            type AP
            channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz
            txpower 31.00 dBm
    
    rpi ~$ cat /proc/net/bonding/bond0
    Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
    
    Bonding Mode: fault-tolerance (active-backup)
    Primary Slave: eth0 (primary_reselect always)
    Currently Active Slave: eth0
    MII Status: up
    MII Polling Interval (ms): 500
    Up Delay (ms): 1000
    Down Delay (ms): 1000
    
    Slave Interface: eth0
    MII Status: up
    Speed: 1000 Mbps
    Duplex: full
    Link Failure Count: 0
    Permanent HW addr: dc:a6:32:01:db:ec
    Slave queue ID: 0
    
    Slave Interface: wlan1
    MII Status: up
    Speed: Unknown
    Duplex: Unknown
    Link Failure Count: 0
    Permanent HW addr: 00:0e:00:20:08:13
    Slave queue ID: 0
    

    If I unplug the wired cable then my smartphone connected to the access point continued to browse the internet, means dynamic failover also works.

    • Something is not right with my bond config. Can you post your bond0 configuration? – Evos Aug 29 at 14:48
    • @Evos I don't know what I should post about the the bond0 configuration. Look at your question and you will find the setup. As already said I followed it line by line except configuring wpa_supplicant with country=DE and using ssid and psk from my location. Maybe there is a problem with your wireless connection? Does wlan0 and wlan1 work without bonding as shown in the link at my answer? – Ingo Aug 29 at 15:44
    • It does not appear to be a problem with USB/Wifi, I test the connection through each section of the process. There are differences between our output: Bond mode for me returns round-robin and does not show wlan1 as a slave interface. I have to think that there must be a difference in our configurations and if not, why the output isn't similar. – Evos Aug 29 at 19:58
    • Bond mode is set in /etc/systemd/network/02-bond0.netdev with Mode=active-backup. Setting this was buggy with systemd 232 comming with Raspbian Stretch. With it you have to load the bonding module with parameter direct. How to do it look at raspberrypi.stackexchange.com/revisions/78788/15 and search for /etc/modprobe.d/bonding.conf. But this should not be an issue because we both are using Raspbian Buster with systemd 241 that has fixed the bugs as you can see with my setup. – Ingo Aug 29 at 20:51

    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.