3

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?

6

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. For reference I use Raspbian Buster Lite 2019-06-20 updated with sudo apt update && sudo apt full-upgrade && sudo reboot done at 2019-06-27.


Enable systemd-networkd

For detailed information look at (1). Here only in short. Execute these commands:

# disable classic networking
rpi ~$ sudo -Es
rpi ~# systemctl mask networking.service dhcpcd.service
rpi ~# mv /etc/network/interfaces /etc/network/interfaces~
rpi ~# sed -i '1i resolvconf=NO' /etc/resolvconf.conf

# enable systemd-networkd
rpi ~# systemctl enable systemd-networkd.service systemd-resolved.service
rpi ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

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

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 enable wpa_supplicant@wlan1.service

For the connection to the internet router we use network address translation (NAT). To setup it we extend the service for wlan1 with:

rpi ~# systemctl edit wpa_supplicant@wlan1.service

In the empty editor insert these statements, save them and quit the editor:

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

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

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

  • 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 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 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 at 22:42
  • The DNS servers seem to be down. – jake Aug 7 at 13:38
  • 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 at 15:05

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.