Performing a bit of thread-necromancy here instead of starting a new one, in hopes that whatever hapless soul find this in the future is glad to have all the info in one place.
Problem: Once in a while, my WAN interface stops passing traffic. I know it's the WAN interface because I can no longer ping the 192.168.100.1 address which lives in my cable modem (and serves a nice little status page on port 80). I've emailed logs to my router's support folks because I'd like to get to the bottom of this, but I'm going out of town soon and needed a quick-and-dirty solution ASAP.
I can log into LuCI, find my way over to "interfaces", and hit the "restart" button, and it instantly fixes the problem. I needed an automatic scriptable version of that "restart" button.
Notable detail: In my case since the address I'm pinging is part of the cable modem a few inches away from the router, a single missed ping means trouble. I have no need for counting "tries" or anything like that.
Solution: I found this thread and didn't love the solution, so I found some noob-friendly shell scripting resources and had a go at it myself. Here's my script, with some debugging echoes commented out but left in place for explanation:
# This should ping the cable modem and if it's not reachable, bounce the wan interface
sleep 30 # Since this script gets called at bootup, give things some time to settle
ping -c 1 -w 1 192.168.100.1 > /dev/null
if [ $? -ne 0 ]; then
#echo "Ping didn't exit cleanly"
#echo "ifdown fired"
sleep 4 # I have no idea if this is needed.
#echo "ifup fired"
sleep 20 # again, give it a moment to come back up and settle
#echo "ping was OK"
sleep 10 # just to give me time to kill it in case it goes haywire, could shorten to 1.
I just dropped this in /root/ as pingtest.sh because I'm lazy and frankly I've never gotten my head around the unix directory structure anyway. Where does it belong?
Anyway, then I tacked a line onto the end of /etc/rc.local like so:
And finally, rebooted to watch it take effect. It works, it works! I can now watch the network page in my browser, momentarily unplug the WAN cable, and watch my script bounce the interface every 35 seconds until it's plugged back in. Presumably this should also catch the real problem when it happens, but I expect to be ignorant of such events now.
I hope this helps someone.