I work on embedded device with linux on it. I want to use DHCP client first, but if there will be no answer from DHCP Server I want to set static-default IP. I suppose it shouldn't be complicated, but I haven't found strict answer.
I'm thinking about 2 solutions (Unfortunately I can test them in few days):
I set static IP with ifconfig, then I call udhcpc. If udhcpc will not obtain new IP, old one will stay.
I can also first call udhcpc, wait a while and check if IP is obtained. But this is not nice for me. I wouldn't like to add any wait routines into startup.
BR Bartek
I use udhcpc - something like:
udhcpc -n -f -i eth0
if ifconfig | grep -A1 eth0 | grep inet
then
dhclient should support fallback via lease declaration have a look at the
dhclient.conf
man page.Add something like this to your
dhclient.conf
or you can assign a second IP to the interface like
/etc/network/interfaces