11

I've got wlan0 and wlan1. Each interface should connect to a different SSID.

I would like to use wpa_supplicant for both.

I can put the two networks in /etc/wpa_supplicant.conf, but how do I tell which one each interface should use?

(RHEL 6.3)

3 Answers 3

11

You will need to create two new files in the following directory: /etc/wpa_supplicant/

The new files should be named with the interface name i.e wpa_supplicant-wlan1.conf

You should end up with two files like so:

for interface wlan0:

  • file /etc/wpa_supplicant/wpa_supplicant-wlan0.conf

for interface wlan1:

  • file /etc/wpa_supplicant/wpa_supplicant-wlan1.conf

content of wpa_supplicant-wlan0.conf file

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

country=US

network={
        ssid="ssid0"
        psk="pass0"
}

content of wpa_supplicant-wlan1.conf file

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

country=US

network={
        ssid="ssid1"
        psk="pass1"
}

reboot PI and you should have SSID attached to an interface.

4
  • This was originally downvoted but it worked for me.
    – alexpotato
    Commented Feb 26, 2020 at 22:06
  • may i know how does this work? i cant seem to find any documentation on wpa_supplicant.conf file naming
    – jaanhio
    Commented May 17, 2020 at 14:07
  • 2
    @jaanhio - Sadly the documentation for that is a bit lacking; you have to read through the code inside /usr/share/dhcpcd/hooks/10-wpa_supplicant to figure that out—and that's part of the dhcpcd project anyways! See @Hannes' separate answer for more details. Commented Jan 1, 2021 at 5:14
  • thank you and @Hannes for clarifying! btw im a big fan of yours :D
    – jaanhio
    Commented Jan 4, 2021 at 1:01
9

You create two separate wpa_supplicant.conf files, one for each interface. Then you specify which conf file goes with which interface when you invoke wpa_supplicant. You use the -N option to show that you want to start describing a new interface.

This example comes right out of the wpa_supplicant(8) man page:

wpa_supplicant \
    -c wpa1.conf -i wlan0 -D hostap -N \
    -c wpa2.conf -i ath0 -D madwifi
2
  • Thanks. This works in my NixOS
    – daparic
    Commented Sep 20, 2019 at 2:15
  • How would you use this if wpa_supplicant is being ls being run as a service e.g. via systemd?
    – alexpotato
    Commented Feb 25, 2020 at 12:25
3

@jaanhio Sorry can't comment, thus as an answer. Can somebody please move it to the comments? I think it is quite interessting to know why creating a file wpa_supplicant-wlan1 works.

junaid's answer is correct for debian. On debian (or at least Raspbian Buster) dhcpcd controls wpa_supplicant in /usr/share/dhcpcd/hooks/10-wpa_supplicant you find

if [ -z "$wpa_supplicant_conf" ]; then
        for x in \
                /etc/wpa_supplicant/wpa_supplicant-"$interface".conf \
                /etc/wpa_supplicant/wpa_supplicant.conf \
                /etc/wpa_supplicant-"$interface".conf \
                /etc/wpa_supplicant.conf \
        ; do
                if [ -s "$x" ]; then
                        wpa_supplicant_conf="$x"
                        break
                fi
        done
fi

So there is these behaviour with wpa_supplicant-wlan0.conf and wpa_supplicant-wlan1.conf files "documented"

Thus you also don't need a reboot when changing. Just exec sudo systemctl restart dhcpcd

1
  • Your comment submitted as an answer cannot be converted to comment due to its length. If you are unable to submit a comment you must earn that privilege. Asking for comment, submitted as an answer to be converted into a comment, is not allowed. I don't agree your answer is even a comment, but since you believe it's a comment, I went ahead and flagged it for a moderator to review
    – Ramhound
    Commented May 19, 2020 at 23:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .