I have a headless raspberry pi zero. It is configured to be connected to home network and my mobile hotspot (Android phone). When I am home, I would like it to get a static IP, where I know I can connect to it (works fine).
But when it connects to my mobile hotspot, it can't get that static IP. In that case, I want it to fall back to dynamic IP. How can I configure dhcpcd.conf to achieve that?
Most information I can find is the other way around (when DHCP server fails). Some claimed that this is impossible (which I doubt). I don't want to change dhcpcd.conf each time I move from one network to another.
Why is this such a problem? Why can't I configure mobile hotspot to accept same static IP? Android is simply primitive in this regard. It only allows a certain IP range (192.168.43.0/24). But I need to connect to the pi on the mobile network. I can find the dynamic IP either on the 16x2 display or with nmap. The weird issue is that notification on my phone tells me that there are 2 clients connected but nmap, doesn't find the rpi. I suppose on physical/data link layer RPi is connected but can't get the static IP. Only way to get around is to make sure RPi can get a dynamic IP, if static IP doesn't work out.
Edit - Summary of the discussions below: It is not possible to detect failed static IP. Client act like the IP belongs to it, while router won't deliver the packages to that IP. Client things that it is connected, while it is not. Actually, DHCP server delivers IP addresses. But my router's DHCP server is aware of clients requesting static IP and allows it (seen under DHCP clients at router's web panel), while other clients request a dynamic IP. However, my router doesn't allow a fixed IP on specified clients (e.g. my mac address).
I am looking for a configuration like it is done at Apple Mac OS, where users can define dynamic or static IP for each WiFi access point separately.