Checking of failed link

I have router with two WAN links and one lan. There is two nat rules and two default gateways. I have two scripts that in case of link failure disables primary nat and route and enables backup pair.
I am pinging host on internet, and in case of failure scripts is executed. There is also filter rule so pinghost1 can be pinged only from primary link.
Problem is that when primary link is down, and primary route is disabled, router can not ping coresponding host, end check that is the link recovered so recover script is executed.
My new idea is to mark rooting for icmp and pinghost1, and not disable route1 but to add routing-mark so that only that host can be pinged through that route and route1 is active that way although it has same dst-address as route2.

This is how it looks after provider1 failure, and executing of scripts (route1 is not disabled but routing-mark is added)

filter rules:
;;; No ping pinghost1 via provider1
chain=output action=drop protocol=icmp dst-address=pinghost1-IP out-interface=ether2

Mangle:
;;; Mark routing for ping to pinghost1
chain=output action=mark-routing new-routing-mark=ka_berk passthrough=yes protocol=icmp dst-address=pinghost1-IP

Routing:

0 A S ;;; Routing_provider1
0.0.0.0/0 gateway1-IP 1 routing-mark=ka_berk
1 A S ;;; Routing_provider2
0.0.0.0/0 gateway2-IP 1

Ping from router to pinghost1 is still rejected, because it trys to go out through gateway2
If I change chain in filter from output to forward and in mangle from output to prerouting I have desired behavior on client in LAN ( It can ping pinghost1 through gatway1)

Help please :slight_smile:

You could try using a host route (/32) to the host you are pinging to check the availability of ISP 1.
No packet filtering or marking is required.

so for example:
123.123.123.1/32 gateway1-ip
0.0.0.0/0 gateway1-ip
X 0.0.0.0/0 gateway2-ip

Then use Tools → Netwatch to ping the pinghost. use “on down” to disable default route to gateway1-ip, and enable default route to gateway2-ip.
use “on up” to do the other way. :slight_smile: