Is it possible to “overwrite” locally inserted default-gateway with the one got via ospf ?
I mean if I have 2 mikrotiks with ospf running and both boxes have different default-gateways. I want all the traffic go through only one of them until it goes down.
Sure!
Your default route should be set as “distribute-default=if-installed-as-type1” and the static gateways should have check-gateway=ping to disable it if it’s not reachable. Of course if the gateway is a ADSL router, you should use a recursive gateway to ensure the check gateway to work properly.
Each has it’s own default-gateway - both are different ones. Both have OSPF running.
All works fine until I turn on “redistributedefult route” on second router. After that is use ONLY it’s own static default-gw. Ospf injection does’t work
[admin@R2] > ip rou pr
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 A S 0.0.0.0/0 192.168.1.1 200
1 ADC 10.255.0.4/30 10.255.0.5 ether6-R1 0
2 ADo 192.168.0.0/24 10.255.0.6 110
3 ADC 192.168.1.0/24 192.168.1.23 ether5-OUT2 0
4 DC 192.168.88.0/24 192.168.88.1 ether8 255
[admin@R2] >
In my experience, working with ROS v6.17 (and a few earlier versions of 6), it’s sort of possible to get this to happen, but it will require manual (or scripted) intervention after network topology changes.
On R1 (the primary out), you would continue as you have it set up – the static default route has a cost of less than 110 and is set to check gateway (ping or arp, depending on how the gateway is setup), OSPF is set up to redistribute if installed (as either t1 or t2, doesn’t make any difference in a 2 default route setup).
On R2 (the secondary out), you set up the static route with a cost of more than 110 and check gateway, set up OSPF to redistribute if installed. But, in order to get it to actually install the OSPF route in the local router’s routing table, you must disable the static route first. If the static default route is disabled, OSPF will install its learned default route in the local routing table. After the OSPF route installs, you can then enable the static default route, which will sit there unused (and not redistribute into OSPF) until the R1 route fails.
However, you will have to manually disable the static default route on R2 after every time it becomes active – once R1 comes back up, you’ll still have both static routes active until the R2 route is disabled & re-enabled as above.
The only place I use it at, manual intervention is sufficient for my needs, so I haven’t done any scripting work towards trying to automate the recovery.
On R2, set the distance to 200 on your static default gateway.
(double check this - note the distance on other routes learned by OSPF, and make sure that your backup default GW statement is a higher number than that distance)
You don’t need scripts, etc.
The problem is the metric for your static default gateway.
By default, static routes are “better” than dynamic routes.
DLNoah’s solution is correct. One thing I would add is to make sure that your test pings from R1 cannot successfully go out R2, and cause R1 to think it is still connected to the Internet. Your connection will flap up and down while the connection on R1 is broken. (Filter them on R2, or make /32 route on R1 forcing ISP1)
Another thing you can do in your design (if you have other routers R3, R4, R5, etc) is to make R2 generate default information with a “worse” metric than R1 so that in case both routers are announcing default routes into your network, the network will prefer the ones from R1. Remember: OSPF chooses Type 1 external routes before Type 2 no matter what the metrics are.
[admin@R2] > ip rou pr
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 A S 0.0.0.0/0 192.168.1.1 200
1 ADC 10.255.0.0/30 10.255.0.1 ether7-R3 0
2 DC 10.255.0.4/30 10.255.0.5 ether6-R1 255
3 ADC 192.168.1.0/24 192.168.1.23 ether5-OUT2 0
4 DC 192.168.88.0/24 192.168.88.1 ether8 255
[admin@R2] >
Both boxes are on the table connected with 1 m cable only. So pings are going without any problems.
I know that. But the goal is to force R2 to mandatory use R1 as a default gw while R1 has default gw installed.
That part was an “extra” - how to get purely ospf routers to decide automatically…
Anyway, I just thought of something that might be the problem with this:
Scope.
(Route scope is something that hasn’t just clicked in my head yet, but I’m trying)
Static routes go into scope 10, and igp protocols like OSPF work in scope 20.
I wonder if you made the floating backup static route use scope 20, if that would fix the problem…
This is one thing about Mikrotik that frustrates me - some things that “just work” in other platforms either do not work, or require some strange configuration in Mikrotik.
Don’t get me wrong, I love the platform, but sometimes I just end up pulling my hair.
When I get to my office later this morning, I’m going to try some experimentation on this matter.