A Raspberry Pi will by default connect to the network if the ethernet connector is plugged in to a router. It is also possible to configure networking on a Raspberry Pi to direct connect to a computer so no router is necessary.
Is it possible to detect which type of setup is present at boot, and make the proper configuration dynamically? I would like to do this to be able to have both a configuration mode (eth0 direct connect with local web server hosting config app) and a normal mode (eth0 internet connection).
I have thought about attempting to get a network DHCP lease on eth0, and if it fails, then running a local DHCP server with isc-dhcp-server to let the directly connected computer get an IP address from the Raspberry Pi.
Two problems with my solution:
- It is going to add a lot of delay before the admin page is available.
- If the Pi is connected to a network at boot, and the network's DHCP server is temporarily down, the Pi will boot into the wrong mode.
Is there any simpler, faster and more foolproof way of detecting this?