OK, I returned to AsusWRT-Merlin firmware again having some idea in mind. At the end I managed to solve the issue by using nice workaround. Basically I noticed that the issue can be solved by restarting WAN interface:
service restart_wan
Or by splitting it into two commands:
service stop_wan
service start_wan
So I prepared a script which is run after the router is powered on and then by crontab every 5 minutes:
/jffs/scripts/wan-check
Code:
#!/bin/sh
# Uncomment the IP you would like to ping
# ISP default GW
IP_TO_CHECK=$(nvram get wan_gateway)
# ISP first DNS
#IP_TO_CHECK=$(nvram get wan_dns|awk '{ print $1 }')
# Your own IP to check
#IP_TO_CHECK=WWW.XXX.YYY.ZZZ
if ! ping -c 1 -W 5 $IP_TO_CHECK ; then
logger "****** wan-check ******: IP $IP_TO_CHECK not pingable, restarting WAN connection"
logger "****** wan-check ******: Stopping WAN connection"
service stop_wan
sleep 7
logger "****** wan-check ******: Starting WAN connection"
service start_wan
#else
# logger "****** wan-check ******: IP $IP_TO_CHECK OK"
fi
You can define different IPs to check, depending on your ISP. It can be your ISP default GW, ISP DNS or any IP address you have in mind. Simply check what is pingable and then uncomment appropriate section and ensure there is only one IP_TO_CHECK variable active.
Then you need to add crontab entry to run the script in predefined intervals. I think the best place is to put it into services-start or init-start script.
Below cron will run the script every 5 mins (*/5). In order not to have wait 5 mins to get the WAN up & running again I put the wan-check script invocation also in the beginning of the services-start file, just before crontab entry is created (to avoid a situation where the script is invoked by both services-start script and cron):
/jffs/scripts/services-start
Code:
#!/bin/sh
sleep 20
/jffs/scripts/wan-check
sleep 2
cru a WANCheck "*/5 * * * * /jffs/scripts/wan-check"
After you create the scripts please assign +rx flags:
chmod a+rx /jffs/scripts/*
chmod go-w /jffs/scripts/*
And that's it. I did few rounds of tests and I have internet connection all the time, regardless of power-cycle numbers. You can observe wan-check script invocations in your syslog (uncomment the 'else' statement and line after it if you want to see if it is run by cron also while the connection is OK).
I hope RMerlin will figure out what is the reason for such behaviour, so we don't have to use this workaround.