6

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)

8

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
| improve this answer | |
  • Thanks. This works in my NixOS – eigenfield Sep 20 '19 at 2:15
  • How would you use this if wpa_supplicant is being ls being run as a service e.g. via systemd? – alexpotato Feb 25 at 12:25
1

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.

| improve this answer | |
  • This was originally downvoted but it worked for me. – alexpotato Feb 26 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 at 14:07
-1

@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

| improve this answer | |
  • 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 at 23:06

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.