Raspberry Pi 3: connect to multiple WiFis & set multiple Static IPs

Laura Bravo Priegue
The Startup
Published in
3 min readApr 19, 2020

This is basically a short tutorial on something that took me a bit to figure out myself due to the (lack of up-to-date) material that I found online on the topic. That is: how to connect your Raspberry Pi to different WiFi networks and give them different and static IP addresses. Hope you find it useful!

  • Connect the Pi to multiple WiFi Networks

We start by connecting the Raspberry to multiple networks. I believe there are different ways of go about this, and all of them are quite straightforward! My preferred option is the changing the wpa_supplicant.conf file from the command line using nano.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add this to the bottom of the file to add a WiFi network:

network={
ssid="your_ssid"
psk="your_password"
#optional id_str="id_string"
}

Add the above lines for as many networks you wish. In my case, my Raspberry can connect to 3 different WiFis.

Note: If you are using a Raspberry Pi3+, remember that if you haven’t done it already you must also specify the country you are in. You can either use the raspi-config application, or edit the wpa_supplicant.conf file by adding a line such as country=ISO_code_of_your_country.

  • Give different static IPs to the Pi

Now comes the tricky bit. It seems that the way of doing this changed a while ago. In Raspbian Wheezy one would have to set it up in /etc/network/interfaces. However, in Jessie one has to edit the dhcpcd.conf file instead. Use the following command:

sudo nano /etc/dhcpcd.conf

You will need to know the IP addresses of each of your routers. You can access this by running the following command while being connected to the network.

ip r | grep default

The IP will be used for editing the dhcpcd.conf file. One can edit this file following the official static IP templates released in the official Raspberry site. In my case I added the following lines:

interface <Network> 
arping <IP_Router1>
arping <IP_Router2>
profile <IP_Router1>
static ip_address=<IP_Pi1>/24
static routers=<IP_Router1>
static domain_name_servers=<Name_Server1>
profile <IP_Router2>
ip_address=<IP_Pi2>/24
static routers=<IP_Router2>
domain_name_servers=<Name_Server2>
  • Network → In our case this has to be set to wlan0. If using a wired connection set to eth0.
  • IP_router → The IP address of the router.
  • IP_Pi → The static IP address you want to assign to your Pi.
  • Name_Server → Name server address.

This is an example of how I edited my own file. The changes are made after the#Example static IP configurationline.

Exit the file with ctrl+X and reboot the Pi by running sudo rebootand you are ready to go!! 🍓🍓🍓

Sources:

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

Laura Bravo Priegue
Laura Bravo Priegue

Written by Laura Bravo Priegue

ML Engineer @ SpoonGuru | From Madrid | Always learning ✌🏻

Responses (3)