Hi folks,
can someone help me ?
I am trying write a script, that will take two “default routes” (dhcp client on two interfaces/WANs) given from DHCP servers and rewrite them, like a standard static route. I want this for adding ROUTE-MARKS on these “new” created routes.
I have already write something like this :
:local dynroute
/ip route
:foreach i in=[find dynamic=yes dst-address=0.0.0.0] do={
:set dynroute [get $i ]
/ip route remove $i
/ip route add gateway=$dynroute}
But this is totally crap and not functional what so ever. Can someone help me ?
Please…
rushlife -
First - you can’t delete dynamic routes…the system just won’t let you.
I take from your post you’re just trying to mark connections/packets with route marks so what you probably want to do is just get the dynamic routes / gateways and copy them to a route table, i.e. wan1, wan2. Then you can use the firewall mangle section to 1) mark connections/packets coming in an interface (wan1, wan2) with prerouting, then 2) use mark route based on the prerouting mark so that any connection coming in wan1 will go back out wan1, same for wan2, and 3) use the route rule table to tell ROS what routing table to use based on the routing mark… So really the only script you would need is the one to find the current dynamic routes and copy them to the appropriate routing table…
I am guessing the next part would be ‘new’ connections, deciding which interface they would go out based on some criteria you already have in mind…
Similar for NAT table, just masquerade ‘out interface’ which will be determined by the routing mark/routing table…
Still - one of your interfaces will have to be the ‘default’ for all packets not marked (which are generally RB generated packets). You can ‘steer’ them with the output chain in Mangle.
I didn’t write a script as I wanted to be sure that the above was your plan…
If the above is your plan then look for a script for ‘load balancing’ and further dynamic or PPPoE or DSL assigned addresses - there should be about 20 or so already written scripts right up your alley for what you’re trying to do.
Thom
“First - you can’t delete dynamic routes…the system just won’t let you.”
Obviously you know much less than I, surprisingly.
Dynamic GW routes from dhcp server can be easily deleted, no problem at all.
I helped myself and I wrote this :
:foreach c in=[/ip route find distance=88 dynamic=yes] do=
{/ip route add copy-from=$c comment=wan1r ; /ip route remove numbers=$c }
Distance (with which one I finding this route) can be defined on dhcp client setting or ppp client.
Final words, do not believe anyone who says that something is cannot be done.