Greetings to everyone who reads this.
With the following script a request is made to obtain ip by dhcp to “ether1-WAN1” to which a routing mark is added, it works correctly but in addition to doing that, I need to link that rule with the required interface so such that when 2 wan have the same gateway, the routing mark works by directing the traffic to such an interface … That can be done manually by entering the gateway: gateway% ether1-WAN1 for example, but not integrating it into the script:
/ip dhcp-client
add add-default-route=no dhcp-options=hostname,clientid disabled=no interface=ether1-WAN1 script=“{\r
\n :local rmark "WAN1"\r
\n :local count [/ip route print count-only where comment="WAN1"]\r
\n :if ($bound=1) do={\r
\n :if ($count = 0) do={\r
\n /ip route add gateway=$"gateway-address” comment="WAN1" routing-mark=$rmark\r
\n } else={\r
\n :if ($count = 1) do={\r
\n :local test [/ip route find where comment="WAN1"]\r
\n :if ([/ip route get $test gateway] != $"gateway-address") do={\r
\n /ip route set $test gateway=$"gateway-address"\r
\n }\r
\n } else={\r
\n :error "Multiple routes found"\r
\n }\r
\n }\r
\n } else={\r
\n /ip route remove [find comment="WAN1"]\r
\n }\r
\n}\r
\n"