Community discussions

MikroTik App
 
GiovanniG
Member
Member
Topic Author
Posts: 350
Joined: Sun Nov 15, 2015 4:12 pm

How to assing a dynamic route to a routing table

Tue Mar 05, 2024 6:14 pm

Hi, I've an important task, the LAN network /24 is splitted in two parts, the first 127 addresses using the devault gateway with main routing table, the second half of the subnet should use another gateway, this i ssimple to obtain, I mangle the 192.168.0.128/25 addresses to use another routing table which I created.
Now the problem is that this second gateway is givng me an internal IP which may change in future, and by DHCP client I can't define the routing table it has to be assigned, where I can mangle the traffic. To solve the problem I had to create a static default route to the gateway which actually I see on the DHCP client datas, works, but how can I created it automatic if the gateway address change?
Thanks

In the picture I show the differences between a dynamic route entry and a static one, it's the same also for 0.0.0.0/0 route. I can't uplead that scren because I'm afraid to activate it, I can loose the router remotely, I think you understood already
routeingtable.jpg
You do not have the required permissions to view the files attached to this post.
 
jaclaz
Long time Member
Long time Member
Posts: 667
Joined: Tue Oct 03, 2023 4:21 pm

Re: How to assing a dynamic route to a routing table

Tue Mar 05, 2024 7:59 pm

Dynamic rules are intended for Ros use.

Maybe you want to add a script to DHCP client to update the gateway on your static route ?
viewtopic.php?t=173560
 
GiovanniG
Member
Member
Topic Author
Posts: 350
Joined: Sun Nov 15, 2015 4:12 pm

Re: How to assing a dynamic route to a routing table

Tue Mar 05, 2024 8:26 pm

Thank you for kind answer, what is a Ros use? Mikrotik router OS? where are these dynamic rules and how can I use them? Sounds strange to me
I can use the script, but I consider it a dirty work, why Mikrotik simply don't let us to assing a default gateway from dynamic connection to a routing table? This is also a mystery.
The only script posted there is this
:if ($bound=1) do={/ip route set [find where dst-address=0.0.0.0/0 routing-mark=ISP1] gateway=$"gateway-address" }
reading it it seams a partial solutin only, much more interesing is the script in the Mikrotik guide, but I don't know how it behaves after the expiraiton (if it may be dangerous)
/ip dhcp-client
add add-default-route=no dhcp-options=hostname,clientid disabled=no interface=ether2 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"
 
jaclaz
Long time Member
Long time Member
Posts: 667
Joined: Tue Oct 03, 2023 4:21 pm

Re: How to assing a dynamic route to a routing table

Tue Mar 05, 2024 8:45 pm

You should read "Dynamic" as "automatically created/managed by the (Router) Operating System, NOT by user".

Yes, this is the script that may (if I got your question right) solve the issue:
:if ($bound=1) do={/ip route set [find where dst-address=0.0.0.0/0 routing-mark=ISP1] gateway=$"gateway-address" }
I don't see in any way how it is dirty or partial, it simply detects when a change in DHCP settings happens and updates the route with the current (new) gateway.
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1068
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: How to assing a dynamic route to a routing table

Tue Mar 05, 2024 10:19 pm

I can use the script, but I consider it a dirty work, why Mikrotik simply don't let us to assing a default gateway from dynamic connection to a routing table? This is also a mystery.

I completely agree! And I truly hope Mikrotik implements a simpler solution like /routing/rule src-interface=xxxx or similar. Currently, you can only use /routing/rule src-address=xxxx which needs to be updated using a DHCP script, giving it a "dirty" feel.

Who is online

Users browsing this forum: HokieCat, Jhonny, rjp0 and 27 guests