I have a few CentOS 6/7 systems (non-production, experimental purposes) that have been configured to use DHCP for their IP address. Last week there was a big network disruption and I found that those systems had lost their IP address and the DHCP client had terminated. I guess after too many/too long retries.
What is the proper way to make it try to recover forever? Is there a dhcp client setting that can do this? Or should I add a cron entry that does something like 'ifup eth0' every hour? Or is there a much better way to do this?
I know CentOS 6 and CentOS 7 do these things differently and I'm looking for answers for both these cases.
Update:
For now I have created this script (which I put in /etc/cron.hourly/ ) that seems to work in the specific situation of CentOS 6. This is probably not the best solution but it "Works on my machine".
#!/bin/bash
IF=eth0
ifconfig ${IF} | fgrep 'inet addr' > /dev/null
if [ $? -ne 0 ];
then
echo "Network is dead, trying restart"
ifup ${IF}
fi
Still looking for the proper way to do this so I do not think this is the right answer to my question.
Both CentOS 6 and 7 should accept the PERSISTENT_DHCLIENT option within /etc/sysconfig/network-scripts/ifcfg* files .e.g.
This instructs the ifup-eth script to run the dhclient without the (default) -1 option
With that option dhclient will try once. From the man page
Without that option dhclient should retry occasionally (every 5 minutes by default) again from dhclient.conf man page