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
update_config=1
country=US

network={
    ssid="my-network-name"
    psk="my-network-password"
}

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.

Comments

>... 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!

Note: Newer Raspberry Pi OS versions (i.e. Bookworm full & lite) also support NetworkManager out of the box. I found the following worked better than using wpa_supplicant for my RPi4. You can configure WiFi connections from the terminal/ssh with commands like nmtui or nmcli.

To restrict a network configuration to a specific device during each boot, I prefer to enable "Predictable Networks Names" under "Advanced Settings" in sudo raspi-config first (then reboot).

To list network devices, use:
nmcli device

To create/edit a wifi network, use:
sudo nmtui

You can modify the WiFi network preconfigured with Raspberry Pi OS imager under the "preconfigured" name.

To create a hotspot, select Add -> Wi-Fi -> Create and use the following settings (use spacebar for checking options):

Profile name: Hotspot (or other name)
Device: wlan0 (or other name or leave blank)
SSID: AzureDiamond (or other name)
Mode: Access Point
Channel: Automatic
Security: WPA & WPA2 Personal
Password: hunter2 (i.e. your own password)
IPv4 Configuration: Shared
IPv6 Configuration: Ignore

[X] Automatically connect
[X] Available to all users

Note: Leave the other fields blank. Leave "Device" field blank to use any device, otherwise put your network adapter name from nmcli device into it. For this example, I used wlan0 as that's what the built-in Wi-Fi adapter is called when using predictable names on my RPi4. The above, except with unchecked "Automatically connect", are also the result of running the following command (from the Raspberry Pi official Hotspot tutorial):

sudo nmcli device wifi hotspot ssid AzureDiamond password hunter2 ifname wlan0

I prefer to use nmtui as I have to remember less. Just putting this other here in a comment in case someone else stumbles upon this post.