Community discussions

MikroTik App
 
divB
newbie
Topic Author
Posts: 32
Joined: Mon Jul 06, 2015 8:18 pm

How can I change the default route for a packet (or put routes into multiple tables)?

Fri Oct 15, 2021 9:11 am

Hello,

How can I make routes to appear in multiple tables? Or, alternatively, how can I make sure that a newly created table contains all the routes from the main table?

What I actually want is to override the existing default route if and only if a package has source address from 233.252.0.0/24.


If I use "routing-mark" (either via "ip route rule" or "firewall mangle"), a new, empty table is created with my updated default route. I could manually copy all the routes from the main table but this is very messy and error prone. Even if I wanted, the Dynamic routes are automatically created.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How can I change the default route for a packet (or put routes into multiple tables)?

Fri Oct 15, 2021 11:59 am

I do not understand how you think,
instead of mark all and have the need of duplicate "main" table,
Simply mark only, checking source and destination, when the packet must follow another path...

Or better do not use firewall for do routing, instead use... Routing for do routing... use Route Rules with src-address

On the example below 233.252.0.0/24 must reach 192.168.0.0/16 from main route table and the rest from table "table-233-252"
The rules are applied on order, this mean that if dst is one IP inside 192.168.0.0/16, main table is used, else the table "table-233-252"
/ip route
add distance=1 gateway=7.8.9.10 routing-mark=table-233-252
/ip route rule
add action=lookup-only-in-table src-address=233.252.0.0/24 dst-address=192.168.0.0/16 table=main
add action=lookup-only-in-table src-address=233.252.0.0/24 table=table-233-252
 
divB
newbie
Topic Author
Posts: 32
Joined: Mon Jul 06, 2015 8:18 pm

Re: How can I change the default route for a packet (or put routes into multiple tables)?

Fri Oct 15, 2021 12:39 pm

Hi,

I think this was pretty much what I was saying ("either via "ip route rule"). My problem is a different one: I want to replace the default route only.

Currently my main routing table is big...and it has a default route, say via 193.0.0.169.

If the source address is from net 233.252.0.0/24, it should traverse the routing table exactly as normal but if it reaches the default route, it should instead use a different one (say, 7.8.9.10 via a different interface).

In your example, if the router receives a packet from 233.252.0.0/24, it looks up table-233-252 only. And this table does not contain anything but "add distance=1 gateway=7.8.9.10 routing-mark=table-233-252". So yes, the desired default route works. But it lacks all the routes of the main table. If a packet with such destination comes across, it would be routed over 7.8.9.10.
Your first rule avoids that but for this I would need to know all possible destinations from the main table. In other words, I would need to replicate it.

Does this make sense?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How can I change the default route for a packet (or put routes into multiple tables)?

Fri Oct 15, 2021 12:45 pm

Yes, the routes on main table are set manually or by BGP?
 
divB
newbie
Topic Author
Posts: 32
Joined: Mon Jul 06, 2015 8:18 pm

Re: How can I change the default route for a packet (or put routes into multiple tables)?

Fri Oct 15, 2021 12:56 pm

Yes, the routes on main table are set manually or by BGP?
Right now manually as well as automatically (the automatic ones are for the various interfaces. Turns out without these not even simple forwarding from one interface to the other works). There are a few tens of entries right now.

However, I want to deploy OSPF (maybe iBGP) since all the static routes get out of hand.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How can I change the default route for a packet (or put routes into multiple tables)?

Fri Oct 15, 2021 1:03 pm

On future keep one eye on VRF...

Actually with all "manual" only, can be doed by scripting, copyng all, except 0.0.0.0/0 from main to alternate table
 
divB
newbie
Topic Author
Posts: 32
Joined: Mon Jul 06, 2015 8:18 pm

Re: How can I change the default route for a packet (or put routes into multiple tables)?

Fri Oct 15, 2021 8:59 pm

On future keep one eye on VRF...
I have briefly looked into this but I have trouble understanding.
I also played around briefly but lost connection to the router. Gave up because I am not on-site (Safe Mode to the rescue!!)

Would you be willing to give a brief example using the numbers above? Interfaces:
  • 193.0.0.170/29. Normal WAN interface. Default route via 193.0.0.169.
  • 192.168.200.1/24. LAN interface
  • 233.252.0.0/24. Second WAN interface
  • 7.8.9.1/24. Interface linking 233.252.0.0/24. Should be the default route if source address 233.252.0.0/24
 
divB
newbie
Topic Author
Posts: 32
Joined: Mon Jul 06, 2015 8:18 pm

Re: How can I change the default route for a packet (or put routes into multiple tables)?

Sun Oct 17, 2021 9:56 am

Ok for the rest of the world, after banging my head on this for the last two days I finally got it working.

There can be multiple rules and multiple rules can jump to different tables. Key observation is (and unfortunately Mikrotiks documentation is totally lacking here) that if a rule is applied and no matching route is found in the table, it jumps back and tries the next matching rule.

With this in mind, I removed the default route from the main table, and created two tables containing only the two different default routes. The rules look like:
[admin@ugate] /ip route rule> print
Flags: X - disabled, I - inactive 
 0   src-address=233.252.0.0/24 dst-address=0.0.0.0/0 action=lookup table=main 

 1   src-address=233.252.0.0/24 dst-address=0.0.0.0/0 action=lookup table=default_net233 

 2   dst-address=0.0.0.0/0 action=lookup table=main 

 3   dst-address=0.0.0.0/0 action=lookup table=default_lan 
 
User avatar
Joni
Member Candidate
Member Candidate
Posts: 156
Joined: Fri Mar 20, 2015 2:46 pm
Contact:

Re: How can I change the default route for a packet (or put routes into multiple tables)?

Thu Jul 07, 2022 4:13 pm

Ok for the rest of the world, after banging my head on this for the last two days I finally got it working.

With this in mind, I removed the default route from the main table, and created two tables containing only the two different default routes.

And (also for the rest of the word) if you want to accomplish the same thing with DHCP routes then use the DHCP Clinet Lease scrpt example https://wiki.mikrotik.com/wiki/Manual:I ... pt_example
:local rmark "WAN1"
:local count [/ip route print count-only where comment="$mark"]
:if ($bound=1) do={
    :if ($count = 0) do={
        /ip route add gateway=$"gateway-address" comment="$mark" routing-mark=$rmark
    } else={
        :if ($count = 1) do={
            :local test [/ip route find where comment="$mark"]
            :if ([/ip route get $test gateway] != $"gateway-address") do={
                /ip route set $test gateway=$"gateway-address"
            }
        } else={
            :error "Multiple routes found"
        }
    }
} else={
    /ip route remove [find comment="$mark"]
}

Who is online

Users browsing this forum: Bing [Bot] and 103 guests