1

Say wifi1 is on 192.168.1.1 and wifi2 is on 10.11.11.1, I think I need a separate static IP for each network e.g. 192.168.1.233 won’t work on wifi2. Is there a way the raspberry pi can automatically switches between IP’s based on which WiFi it's connected to?

1
  • 2
    The normal way of switching IP based on network is DHCP.
    – Milliways
    Feb 6 '19 at 23:40
1

dhcpcd can configure interfaces dependent on the host network. This uses the Address Resolution Protocol (ARP) to probe hosts based on MAC or IP address before attempting DHCP resolution.

See Host Specific Configuration in How to set up networking/WiFi

1
  • 1
    It's also possible to use the SSID to set IP, etc
    – Dirk
    Feb 7 '19 at 0:50
0

go to dhcpcd.conf and edit IP address as per each wifi requirement and enable ARPing.

Try this way:

interface eth0
arping 192.168.2.1
arping 192.168.4.50
profile 192.168.2.1
static ip_address =192.168.2.44/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1

profile 192.168.4.50
static ip_address=192.168.0.44/24
static routers=192.168.4.50
static domain_name_servers=192.168.4.50

Refer https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=140252

1
  • 3
    It would be helpful if you would give more details on how exactly this should / could be done.
    – Dirk
    Feb 7 '19 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.