Howto disable/delete a route by parameters, not by number?

I have mikrotik router (RB2011) connected to three external networks by PPPoE (via different providers).
All of them has default route, and there are a number of static routes, addressed to the gateway of a particular provider
I wrote a script to deactivate some of static routes and activate another one, if PPPoE interface goes down.
But I don’t know the number of route, that is nesessary to disable/enable/delete routes - the number of routes may be chanched by order of PPPoE interface start or if it was temporary disconnected.
So, how can I disable/enable/delete route by it parameters - network, gate, etc?

This should do it for you:

/ip route remove [find gateway="192.168.1.1"]

you can “find” anything that you can “set”, for routes those would be

bhp-as-path
bhp-communities
bgp-med
bhp-prepend
comment
distance
gateway
route-tag
scope
type
numbers
bhp-atomic-aggregate
bhp-local-pref
bhp-origin
check-gateway
disabled
dat-address
pref-src
routing-mark
target-scope
vrf-interface

Thank you, it works!
But another question is: how can I prevent the inactivation of a static route when the gateway is unavailable?
This is useful when a route is used to check the path to the external host through certain external connection.

I don’t think you can. Once the router is unable to talk to the gateway, it will disable the route until it is available again.

I found the same.

Apparently, it is necessary to use to check the availability of the way network address of a particular service provider, which is not available through their external interface.
I will be think :slight_smile:

Hi Dears
I have a problem and I was thankful if someone helps me.
I have several numbers of 951 routers as my clients and I want to remove some useless routes in them without any disconnection or remove other routes. The point is that some of these useless route’s gateways were PPTP and L2TP which they are removed and they changed to “unknown” and the route is static and not active. Some of them
I have used (/IP route remove [/ip route find gateway=“unknown”]) but it didn’t help me.
is there any script which removes routes by their flag (S- Static the blue lines) and not manual or one by one or using the line numbers. As I said I have several routers and use ssh for all of them.

Best Regards,

/ip route print for check
0 S 192.168.x.0/24 *F16EA3 20
1 S 192.168.x.0/24 *F177AF 20

/ip route remove [find static gateway~“F1*”];

/ip route remove [find where gateway~"^\\*[0-9a-fA-F]{1,8}\$"]

Can’t do it

/ip route remove [find where immediate-gw=“ether10-HeyB”]
no such item (4)