3

I have 2 static addreses (a.b.c.72/24 and a.b.c.128/24) on gateway1 and gateway2 interfaces. ISP have one gateway a.b.c.1 . I can use a.b.c.72 only on gateway1, a.b.c.128 only on gateway2.

How to get a.b.c.128 working? I want route some local machines via second interface. I know some ways to route via different gateways in mikrotik. In linux i can specify dev parameter to route.

I added routing tables and rules, but it still routed via gateway2.

 /ip dhcp-client print
Flags: X - disabled, I - invalid 
 #   INTERFACE           USE ADD-DEFAULT-ROUTE STATUS        ADDRESS           
 0   gateway1            yes no                bound         X.Y.164.72/24  
 1   gateway2            yes no                bound         X.Y.164.128/24 



/ip route
add distance=51 gateway=X.Y.164.1 pref-src=X.Y.164.128 routing-mark=gate2
add distance=1 dst-address=X.Y.164.0/24 gateway=gateway2 pref-src=X.Y.164.128 routing-mark=gate2
add distance=52 gateway=X.Y.164.1 pref-src=X.Y.164.72 routing-mark=gate1
add distance=1 dst-address=X.Y.164.0/24 gateway=gateway1 pref-src=X.Y.164.72 routing-mark=gate1
add distance=52 gateway=X.Y.164.1
add distance=10 dst-address=10.0.0.0/8 gateway=center

On selected line i need to have iproute equivalent to ip route add default via 109.60.164.1 dev gateway2 table gate2 but it routes via gateway1 interface ip route

NAT

/ip firewall nat
add action=masquerade chain=srcnat out-interface=gateway1
add action=masquerade chain=srcnat out-interface=gateway2

Mangle is clean now. It had marks connections from and routes for selected clients. It is not a problem and workswith different gateways.

6
  • Please show /ip address, /ip firewall filter, /ip firewall nat, /ip route.
    – tsz
    Commented Mar 4, 2014 at 4:47
  • @lorsungcu edited
    – eri
    Commented Mar 4, 2014 at 10:00
  • Your gateway is the same for all three default gw entries. Is that correct? I would start by removing and rebuilding those routes. If using winbox, it's pretty straightforward, if you're in the CLI, try this: ip route add dst-address=0.0.0.0/0 gateway=1.1.1.1 - you will need one of these for each interface, obviously.
    – tsz
    Commented Mar 4, 2014 at 15:20
  • Your route to your ISP's gateway is also set for the same distance out both interfaces. There is quite a bit wrong with your current config - I will either need to know much more about what you want done, or more information on what your ISP is doing, or both.
    – tsz
    Commented Mar 4, 2014 at 15:37
  • @lorsungcu i have two cables, on each cable traffic is filtered by ISP to X.Y.164.128 and X.Y.164.72. it may be dhcp-client or static. gateway is same. I cant bridge or bounding these.
    – eri
    Commented Mar 4, 2014 at 19:27

2 Answers 2

5

Due to the fact that both links have the same IP gateway, you must set in some way the interface you want to use in your routing tables. The syntax is the following: gateway=[ip]%[interface] + specific preferred source; given this fact, in your router these routes should look like the following:

/ip route gateway=109.60.164.1%gateway1 pref-src 109.60.164.72 distance=1 
/ip route gateway=109.60.164.1%gateway2 pref-src 109.60.164.128 distance=2 

/ip route gateway=109.60.164.1%gateway1 pref-src 109.60.164.72 routing-mark=gate1 distance=1 
/ip route gateway=109.60.164.1%gateway2 pref-src 109.60.164.128 routing-mark=gate1 distance=2 

/ip route gateway=109.60.164.1%gateway2 pref-src 109.60.164.128 routing-mark=gate2 distance=1 
/ip route gateway=109.60.164.1%gateway1 pref-src 109.60.164.72 routing-mark=gate2 distance=2
1
  • Yea, i have the same problem with 2 cable modems. I ended up doing the % magic on both of my links and it works correctly.
    – TiernanO
    Commented Jun 1, 2014 at 18:48
0

If you need to route to the same gateway via different interfaces:

  1. /ip route add dst-address=0.0.0.0/0 gateway=YOUR_GATEWAY%wlan1 pref-src=192.168.0.1 distance=1
  2. /ip route add dst-address=0.0.0.0/0 gateway=YOUR_GATEWAY%wlan1 pref-src=192.168.100.1 distance=1 Then go to Firewall -> Mangle and add new prerouting chan select the Src Addr like 192.168.0.0/24 in action tab select Action "mark routing" New Routing Mark e.g. "wlan1" make prerouting

Do the same for another sub-net Go to IP routes and select which mark you want to assign to the interface. Select routing mark

Do the same for another route. Enjoy the separate routes on your, it works on the same bridge as well.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .