5

There are some tutorials to make an access point a WiFi repeater using only the on-board WiFi chip of a Raspberry Pi. But I want to use an additional USB/WiFi dongle as second interface for the up-link to an internet router, in the hope it would simplify the configuration and avoid the limitations of the single interface solution.

How can I setup an access point as WiFi repeater using an additional USB/WiFi dongle?

9

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=/var/run/wpa_supplicant GROUP=netdev
update_config=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 wpa_supplicant@wlan0.service
rpi ~# rfkill unblock 0

Configure wpa_supplicant for wlan1 as client

rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan1.conf <<EOF
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=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 wpa_supplicant@wlan1.service
rpi ~# rfkill unblock 2

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
# 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]
DHCP=yes
EOF

Reboot.
That's it.


references:
[1] Howto migrate from networking to systemd-networkd with dynamic failover

| improve this answer | |
  • Ingo - You're setup works perfectly and the installation steps were easy to follow, thank you. Is there any way to add the ability to use the eth0 on the LAN side? – William Meyer Jun 23 '19 at 21:49
  • @WilliamMeyer It is possible to use eth0 in addition. But what do you mean with using on the LAN side? How should it be used? Together with the access point with same ip address range? I know you can't comment just now at this answer and "answers" used as comments will be deleted. I suggest to make your own question and give a link to my answer as reference. Just click on the button "Ask Question" on the top right corner on this side. I will look at it. You can also comment your own question. – Ingo Jun 23 '19 at 22:41
  • @WilliamMeyer And please take the short Tour and visit the Help Center to get an idea how things work here. – Ingo Jun 23 '19 at 22:42
  • 1
    @jake Of course. As you can see I have immediately changed the second DNS server to 1.1.1.1 in the hope that it's a more stable one. In combination it should always working now. – Ingo Aug 13 '19 at 15:05
  • 1
    @jake You are right setting it to wlan0. I have made the same mistake again. The explanation you can see with sudo iptables-legacy --table nat --list --verbose in the source column. It is the subnet from the interface and must be that from wlan0 192.168.4.0/24. I have corrected it in the answer. – Ingo Jan 20 at 0:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.