OpenWrt WAN watchdog


Ideally, an internet connection would be perfectly stable, but since that is not always the case, a watchdog is the next best thing. In case you ever use your home machine(s) remotely, the use case should be clear: make sure the internet connection at home still works so that you can log in when travelling.

With OpenWrt, it’s fairly easy to implement a simple watchdog that pings a public IP address every minute and triggers /etc/init.d/networking restart in case the ping fails a couple of times in a row. For a DSL connection, this means it will try to re-dial. This setup recovered a broken connection for me more than once :-).

I stored the following shell script at /root/


while [[ $tries -lt 5 ]]
    if /bin/ping -c 1 >/dev/null
        exit 0

/etc/init.d/network restart

Don’t forget to make it executable using chmod +x /root/

Afterwards, add the following entry in System → Scheduled Tasks in LuCI:

* * * * * /root/