Hi,
I need to configure a static route using a gateway obtained from DHCP.
Cisco has this functionality, e.g.:
ip route 8.8.8.8 255.255.255.255 dhcp
With this feature, static routes are installed in a routing table with the destination next-hop IP address set to the IP address supplied by gateway from DHCP. If the DHCP gateway (option 3) changes during the client renewal, the routes change the next-hop to a new IP address supplied in the renewal.
Can this be done on Mikrotik without using scripts?
I believe you can add those by scripting in the “script” property of the dhcp-client: DHCP - RouterOS - MikroTik Documentation
You can make use of the global variables inside the script to grab the gateway address.
Thanks.
I expected I would have to use scripts if there was no other alternative.
If you want to keep the script simple, you can update a single static route with the script and then use recursion to use the dst-address of that route as the gateway for anything else. At least it’s less messy that way.
on advanced tab in dhcp client paste this code
:if ($bound=1) do={
/ip route add distance=1 gateway=$"gateway-address" dst-address="8.8.8.8" comment="RoutesDHCP"
} else={
/ip route remove [/ip route find comment="RoutesDHCP"]
}