10

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)

Spiff
  • 101,729
  • 17
  • 175
  • 229
user1219721
  • 353
  • 1
  • 3
  • 9

3 Answers3

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.

alexpotato
  • 153
  • 6
junaid
  • 121
  • 1
  • 2
  • This was originally downvoted but it worked for me. – alexpotato Feb 26 '20 at 22:06
  • may i know how does this work? i cant seem to find any documentation on wpa_supplicant.conf file naming – jaanhio May 17 '20 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. – geerlingguy Jan 01 '21 at 05:14
  • thank you and @Hannes for clarifying! btw im a big fan of yours :D – jaanhio Jan 04 '21 at 01: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
Spiff
  • 101,729
  • 17
  • 175
  • 229
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

Hannes
  • 269
  • 2
  • 7
  • 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 May 19 '20 at 23:06