Net watchdog for OpenWrt

Lately, my cable connection gets disconnected too often. To automate reconnection, I installed a simple watchdog script that pings outside address and if there is no response it restarts router network. It’s not most efficient, since only WAN needs to be restarted, but it does the job.

Here is a simple watchdog script.

while [ $n -lt 10 ]
  if /bin/ping -c 1 >/dev/null
    exit 0
/etc/init.d/network restart

First, ssh to router and create this script

ssh root@
nano /root/
chmod +x /root/

Save it to /root/, and give executable permissions
chmod +x /root/
Add it to cron in order to execute it every minute:

* * * * * /root/

You can either add this line using luci web interface at
or just edit /etc/crontabs/root file.

Make sure cron is enabled!