How can I run a script when an interface isn't routable?

I'm using PBR to route requests to certain domains from subnet to a particular interface (wan2). I want requests to other domains to go to my default gateway (on wan1) - so I don't want to delete that default gateway route. But if for some reason wan2 is down or fails, I want the request to block (wait), not failover to the default gateway, and I want to run a script so I can bring that interface back up. Ideally I don't want to bother bringing it back up until there's actual traffic that needs the interface. Is there a way to do this?

crontab every minute

script that runs (to be edited with the right output interface):
ping -c 3 -I wan
detect if it exited with errors and fix the gateway

Watchcat is pretty useful

Thanks. However, I actually want to leave the interface down until it's needed. So I only want to reconnect when a packet comes along that should be routed - not immediately when it fails.

1 Like

does the received packet arrive on the interface which could be not active ?

please provide more information on how you are going to bring up an interface that may not be up but is receiving packets....

Is the interface currently always active?

1 Like

You can log matching traffic with firewall and create a service that follows the log and brings up a specific WAN on a log event.