Working with multiple WiFi interfaces on a Raspberry Pi

Sometimes I like to connect to multiple WiFi networks on my Pi for... reasons.

Other times I like being able to use a better wireless interface than the built-in WiFi module on the Pi 4 or CM4, but don't want to add dtoverlay=disable-wifi in my /boot/config.txt and reboot.

Since Pi OS uses wpa_supplicant, it's actually easy to do this.

First, see what interfaces you have available, e.g. with ip a:

$ ip a
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether e4:5f:01:4e:f0:22 brd ff:ff:ff:ff:ff:ff
4: wlan1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 84:5c:f3:f6:e9:29 brd ff:ff:ff:ff:ff:ff

If you want to specify a network configuration that only applies to wlan1, create a file named /etc/wpa_supplicant/wpa_supplicant-wlan1.conf, and put your network credentials inside:

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


Obviously, substitute your own values where relevant.

It should try connecting on wlan1 automatically (you should be able to follow with dmesg --follow), but sometimes, for some strange reason, it won't, and you'll have to reboot the Pi to pick up the changes.

The logic for the naming of wpa_supplicant.conf files is located inside /usr/share/dhcpcd/hooks/10-wpa_supplicant. And if you need to manually bring down an interface, run sudo ifconfig wlan0 down. You can also try reloading the wpa_supplicant config manually with sudo wpa_cli -i wlan0 reconfigure, but sometimes that doesn't seem to work for me.


>... reasons.
I like to have a separate, non-WAN-connected wifi network for things like cameras and my local database server and whatnot. Doesn't matter if there is a gaping hole in the device's security, so long as nobody can touch it... I guess.

dmesg --follow is a new one for me, I knew there must have been some way so seeing more wifi connection info from the command line. Thanks for sharing!
(At this point I should probably start a text file for all of the helpful commands I pick up in my Internetz travels.)

Heh, my blog is basically that text file. I've had to do this like 5 times and every time I forget exactly what the syntax is for the supplicant file naming. Decided I should just document it—now I can DDG or Google "geerling wifi raspberry pi" and after a couple days it'll be in the index ;)

Hi Jeff,

FYI, ifconfig is deprecated in favor of the ip (iproute2) command. The equivalent ip command is ip link set dev wlan0 down.

Love what you're doing, keep it up!

Kind regards, Ben

No such file /usr/share/dhcpcd/hooks/10-wpa_supplicant

Also I find that [code]wpa_cli -i wlan0 reconfig[/code] seems to work for me.

Thanks for continuing to pay for hosting so that we can find this information. I needed to add a second wireless Lan with a USB adapter and in seconds I was connected. I copied the original wpa_supplicant.conf to wpa_supplicant-wlan1.conf. Then I edited the latter changing the ssid and password, saved, rebooted and voila! Thanks again for maintaining this information.

Of course! The comments on these blog posts are one of the best sources for information. I hate it when someone has no way of providing feedback / updates on their past work, so even though spam is tough to deal with I like leaving the comments open!