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:
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.