It is known that the Raspberry Pi can spawn an access point and connect as client to another wifi network simultaneously with its on board wifi chip. How to do that you can look at Access point as WiFi repeater, optional with bridge.
But using a second USB/WiFi dongle is simpler and depending on its hardware it may be possible to avoid the limitations of the single interface solution. With systemd-networkd and wpa_supplicant we have everything on the Raspberry Pi to setup what we want. There is no need to install additional software and fiddle with hostapd and dnsmasq. You have to switch to systemd-networkd and then simply set up wpa_supplicant one time for wlan0 as access point and one time for wlan1 as client. Then configure the interfaces and it's done.
Tested with
Raspberry Pi OS (32-bit) with desktop 2020-05-27 updated on 2020-06-27
Updates done with sudo apt update && sudo apt full-upgrade && sudo reboot
.
Here you will find the last tested revision for Raspbian Buster Lite.
Enable systemd-networkd
Just follow to Use systemd-networkd for general networking. You can use section "♦ Quick Step". Then come back here.
Configure wpa_supplicant for wlan0 as access point
To configure wpa_supplicant create these files with your settings for country=
, ssid=
, psk=
and maybe frequency=
You can just copy and paste this in one block to your command line beginning with cat
and including EOF (delimiter EOF will not get part of the file):
rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
country=DE
ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
update_config=1
p2p_disabled=1
network={
ssid="RPiNet"
mode=2
key_mgmt=WPA-PSK
psk="verySecretPassword"
frequency=2412
}
EOF
rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# systemctl disable wpa_supplicant.service
rpi ~# systemctl enable [email protected]
rpi ~# rfkill unblock wlan
Configure wpa_supplicant for wlan1 as client
rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan1.conf <<EOF
country=DE
ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
update_config=1
p2p_disabled=1
network={
ssid="TestNet"
psk="anotherSecretPassword"
}
EOF
rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan1.conf
rpi ~# systemctl disable wpa_supplicant.service
rpi ~# systemctl enable [email protected]
Configure interfaces
Create these two files:
rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.4.1/24
LLMNR=no
DNSSEC=no
MulticastDNS=yes
# IPMasquerade is doing NAT
IPMasquerade=yes
IPForward=yes
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 1.1.1.1
EOF
Because we don't have a bridge, we need two different subnets. Be aware that the static ip address for the access point wlan0 belongs to another subnet than that from wlan1. For the connection to the internet router we use network address translation (NAT).
rpi ~# cat > /etc/systemd/network/12-wlan1.network <<EOF
[Match]
Name=wlan1
[Network]
LLMNR=no
DNSSEC=no
MulticastDNS=yes
DHCP=yes
EOF
Reboot.
That's it.
references:
[1] Use systemd-networkd for general networking