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

Laura Bravo Priegue
Apr 19 · 3 min read

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!

Image for post
Image for post
  • 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:

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

Image for post
Image for post

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>
static routers=<IP_Router2>
  • Network → In our case this has to be set to wlan0. If using a wired connection set to eth0.

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

Image for post
Image for post

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


The Startup

Medium's largest active publication, followed by +719K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store