0

I'm trying to setup two wireless AP on a Raspberry Pi. Lets call the two APs AP0 and AP1. I use hostapd to setup the APs and dnsmasq as the dhcp server.

AP0 is setup on the built-in WiFi on the RasPi at wlan0

AP1 is setup on an external USB adapter that supports AP mode at wlan1

This is my /etc/network/interfaces file:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
        address 192.168.43.1
        netmask 255.255.255.0
        hostapd /etc/hostapd/hostapd.conf

 auto wlan1
 allow-hotplug wlan1
 iface wlan1 inet static
        address 192.168.4.1
        netmask 255.255.255.0
        hostapd /etc/hostapd/hostapd1.conf

and this is my /etc/dnsmasq.conf file:

dhcp-range=wlan0,192.168.43.50,192.168.43.150,24h

dhcp-range=wlan1,192.168.4.50,192.168.4.150,24h

AP0 and AP1 are on channels 6 and 11 respectively.

I am able to connect multiple clients to AP1 and the clients can speak to each other. But the issue is with AP0 where the client connects for a second and then disconnects and this keeps on repeating. How to fix this issue?

5
  • I never used deprecated `/etc/network/interfaces' since years. Are you open to use a solution with systemd-networkd?
    – Ingo
    Commented Nov 5, 2020 at 18:12
  • Sure. I didn't know that /etc/network/interfaces is deprecated :)
    – mottom
    Commented Nov 5, 2020 at 18:47
  • It depends on the operating system you are using. I supposed that you use a Raspberry Pi OS based on buster. That is using dhcpcd with a hint in /etc/network/interfaces. What operating system do you use?
    – Ingo
    Commented Nov 5, 2020 at 19:00
  • Yes, I'm using the Raspberry Pi OS based on buster. Does that mean I don't require a seperate dhcp server like dnsmasq?
    – mottom
    Commented Nov 5, 2020 at 19:06
  • Yes, with systemd-networkd you do not need additional helpers like dnsmasq and hostapd. Just a moment please I'm just testing the double access point setup and will give you then an answer.
    – Ingo
    Commented Nov 5, 2020 at 19:24

1 Answer 1

2

As noted in a comment you are also agreed with using systemd-networkd. Here in short a configuration I have just tested, based on Setting up a Raspberry Pi as an access point - the easy way.

Switch over to systemd-networkd

Just follow to Use systemd-networkd for general networking. You can use section "♦ Quick Step". Then come back here.

Configure wpa_supplicant as access points

To configure wpa_supplicant as access point create these two 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 both EOF (delimiter EOF will not get part of the file):

rpi ~$ sudo -Es   # if not already done
rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
update_config=1
country=DE

network={
    ssid="AP0"
    mode=2            # access point
    frequency=2437    # channel 6
    key_mgmt=WPA-PSK
    proto=RSN WPA
    psk="password"
}
EOF

rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan1.conf <<EOF
ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
update_config=1
country=DE

network={
    ssid="AP1"
    mode=2            # access point
    frequency=2462    # channel 11
    key_mgmt=WPA-PSK
    proto=RSN WPA
    psk="password"
}
EOF

rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan1.conf
rpi ~# systemctl disable wpa_supplicant.service
rpi ~# systemctl enable [email protected]
rpi ~# systemctl enable [email protected]
rpi ~# rfkill unblock wlan

Configure network interfaces

Create the following two files to configure the interfaces:

rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.43.1/24
MulticastDNS=yes
DHCPServer=yes
EOF

rpi ~# cat > /etc/systemd/network/12-wlan1.network <<EOF
[Match]
Name=wlan1
[Network]
Address=192.168.4.1/24
MulticastDNS=yes
DHCPServer=yes
EOF

Reboot and it should do.

6
  • Thank you for the solution. I'm trying it out now. I noticed the network configuration files start with a different number. Any reason for that?
    – mottom
    Commented Nov 6, 2020 at 4:32
  • @mottom The network configuration files are executed in alphabetical order so you can control it. It is good practice to prefix them with a number as already done with old style SysV init scripts. In this case it doesn't matter which access point is first started.
    – Ingo
    Commented Nov 6, 2020 at 11:34
  • This is what I did. I disabled dnsmasq.service and hostapd.service, replaced the interfaces and dnsmasq.conf files with their originals (as they would be in a fresh install) and followed the steps as per the solution. I tried to connect clients to AP0 and AP1 but the client isn't assigned an IP address so it doesn't connect to either AP. Anything I'm missing or doing wrong?
    – mottom
    Commented Nov 6, 2020 at 14:54
  • @mottom Start with a fresh flashed raspios_lite_armhf-2020-08-24 to a spare SD Card on a Raspberry Pi 4B. Don't forget Quick steps on Use systemd-networkd for general networking.
    – Ingo
    Commented Nov 6, 2020 at 17:39
  • Thanks @Ingo, the solution works as expected. However I don't seem to have access to WAN anymore. I use a wireless USB modem/stick connected to the Pi.
    – mottom
    Commented Nov 10, 2020 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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