zubenubi
Posts: 8
Joined: Mon Mar 07, 2016 8:17 pm

Multiple Wifi Networks with Static IP

Mon Mar 07, 2016 8:33 pm

Hi,

I have an rpi 2 Model B and a rpi 3.

The new onboard Wifi is great for my application, but I am having trouble getting it to behave in the way that my rpi2 machine behaves. Specifically, I want to use this machine on multiple different networks and I want to have the rpi use a static ip address on each wifi network when it connects. This I achieved on the rpi 2 with the following version of raspbian:

Linux raspberrypi 3.18.5-v7+ #225 SMP PREEMPT Fri Jan 30 18:53:55 GMT 2015 armv7l GNU/Linux

Here is the /etc/network/interfaces file:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

iface IMDmFi inet static
address 192.168.10.89
netmask 255.255.255.0
gateway 192.168.10.2

iface NautiCloud inet static
address 192.168.111.22
netmask 255.255.255.0
gateway 192.168.111.1

Here is the /etc/wpa_supplicant/wpa_supplicant.conf file:

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

network={
ssid="IMDmFi"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
group=CCMP
psk=*******************************
id_str="IMDmFi"
}
network={
ssid="NautiCloud"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
group=CCMP
psk=*******************************
id_str="NautiCloud"
}


With these 2 files I can bring my rpi2 from one network to another and when I power on the rpi2 in the vicinity of either network it connects to the respective network at the specified ip address.

I have tried these same settings on the rpi3 with (Linux raspberrypi 4.1.18-v7+ #846 SMP Thu Feb 25 14:22:53 GMT 2016 armv7l GNU/Linux).

When I do the rpi3 does not connect at its assigned static ip.

Is there an updated guide for rpi3 that is like the one I found earlier at:

http://neilbaldwin.net/blog/raspberry-p ... p-address/

TIA

User avatar
Milliways
Posts: 534
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: Multiple Wifi Networks with Static IP

Tue Mar 08, 2016 2:14 am

Rasbian was changed in May 2015 to use different networking.

The same setup should work if you disable dhcpcd.

I think dhcpcd offers many benefits. You could set static IP using the new dhcpcd method. I can't say how it would work with different settings for different networks.

[How do I set up networking/WiFi/Static IP](http://raspberrypi.stackexchange.com/a/37921/8697)

I still don't understand the fixation Raspberry Pi users seem to have with static addresses. There are better ways of doing things.

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Multiple Wifi Networks with Static IP

Tue Mar 08, 2016 2:36 am

Milliways wrote:I still don't understand the fixation Raspberry Pi users seem to have with static addresses. There are better ways of doing things.
Their names can be set in a hosts file and you don't have to use zeroconf. There seem to be a lot of routers that hand out ip addresses that change even if you've set them to something you want them to not change from. You might want more than one ip address and you can't figure out how to do that with dhcp. And finally the big one, you can't figure out dhcp in Jessie at all.

LinuxCircle
Posts: 26
Joined: Sat May 04, 2013 2:03 am
Contact: Website

Re: Multiple Wifi Networks with Static IP

Fri Sep 16, 2016 1:02 am

We have figured it out over here. You only need to modify 2 files: wpa_supplicant.conf and dhcpcd exit hook file
http://www.linuxcircle.com/2016/09/15/r ... -networks/
www.linuxcircle.com

androcton
Posts: 1
Joined: Sun Mar 04, 2018 1:17 pm

Re: Multiple Wifi Networks with Static IP

Sun Mar 04, 2018 1:26 pm

What if I have the SSID the same for both home network and hotspot. Can I still achieve the same??

Return to “Raspberry Pi OS”