:local interfaceName "ether4"
:local routeComment "to_wan4"
# Get the gateway from the DHCP client
:local GWay [/ip dhcp-client get [find interface=$interfaceName] gateway]
# Check if the route with the specified comment exists
:local routeExists [/ip route find where comment=$routeComment]
# If the route exists, update the gateway. If not, add a new route.
:if ($routeExists != "") do={
/ip route set [$routeExists] gateway=($GWay."%ether4")
} else={
/ip route add dst-address=[Link]/0 gateway=($GWay."%ether4") check-
gateway=ping comment=$routeComment
}
# Add/Update the route with check-gateway=ping, distance=4, and routing-table=ISP4
:local routeISP4Exists [/ip route find where comment=$routeComment and routing-
table=ISP4]
:if ($routeISP4Exists != "") do={
/ip route set [$routeISP4Exists] gateway=($GWay."%ether4") check-gateway=ping
distance=4
} else={
/ip route add dst-address=[Link]/0 gateway=($GWay."%ether4") check-
gateway=ping distance=4 routing-table=ISP4 comment=$routeComment
}