Save this script to file and make it executable. Then run it in a cronjob.
Open your favorite editor and copy this script :
# cron script for checking lan connectivity
# Ping count is set aggressively to 1, increase depending what you want.
#I'm assuming ping is installed.
#Find the gateway IP address
GATEWAY_IP=`ip route | grep default | cut -d " " -f 3`
# ping test
$PING -n -c "$PING_COUNT" "$GATEWAY_IP" &>/dev/null
if [ "$?" -ge 1 ]
# This will log a message in system log (see manpage).
logger "Network access DOWN"
service network restart
logger "Network access OK"
Save the file and name it checklan for example.
Make it executable by type in cmdline :
chmod +x checklan
As root or using sudo, move the file to /usr/local/bin :
mv checklan /usr/local/bin
Using sudo or root, open a new file in /etc/cron.d
Copy the the following line :
*/10 * * * * root /usr/local/bin/checklan
Save the change by typing :x
Restart cron as root or using sudo :
service crond restart
Then the script should run every 10 mins.
NOTE: Please read on the Internet about cron to understand syntax.
You can increase rate up to every min.
Check /var/log/messages or /var/log/syslog to see if it is working:
tail -f /var/log/messages
If it works you will see something like this:
Apr 1 20:04:01 <hostname> logger: checklan OK