atux_null
Posts: 111
Joined: Thu Jun 21, 2012 1:58 pm

multiple wifis for portability

Thu Aug 16, 2018 7:50 am

i have a raspberry pi 0 w and i move it around for different jobs. i have configured it to be able to connect to different wifis and get an IP from DHCP. I would like to alter it a bit and have the following setup:
-connect with priority. if 2 or wifis are present, then connect by priority to a certain one
-in certain wifis give a static IP. In others get from DHCP.
here is my current working config for /etc/wpa_supplicant/wpa_supplicant.conf

Code: Select all

country=GB
update_config=1
ctrl_interface=/var/run/wpa_supplicant

#[email protected]
network={
    ssid="NETGEAR12"
    psk="whatever"
    id_str="work1"
}

#[email protected]
network={
    ssid="TP-LINK9"
    psk="whatevert34"
    id_str="work2"
}

#Home
network={
    ssid="Atux"
    psk="null!1home"
    id_str="home"
}

#other wifi
network={
    ssid="SSID_1"
    psk="123abc!"
    id_str="other_wifi"
}

#lab wifi
network={
    ssid="SSID_LAB"
    psk="123vcg34!"
    id_str="lab"
}
and the handling of IPs in /etc/network/interfaces

Code: Select all

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d


auto lo
iface lo inet loopback

iface eth0 inet manual

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

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface work1 inet dhcp
iface work2 inet dhcp
iface home inet dhcp
iface other_wifi inet dhcp
iface lab inet dhcp
i would like:
-work1 get a static IP 192.168.1.89/24 with gateway 192.168.1.1 and DNS 192.168.1.1. If possible in case of conflict get from DHCP
-work2 get a static IP 192.168.0.89/24 with gateway 192.168.0.1 and DNS 192.168.0.1. If possible in case of conflict get from DHCP
-home get a static IP 192.168.2.89/24 with gateway 192.168.2.1 and DNS 192.168.2.1. If possible in case of conflict get from DHCP
-other_wifi get a dynamic IP
-lab get a dynamic IP

is the aforementioned feasible? if yes, how can i achieve it please?

Return to “Networking and servers”