N
N
Ninja52014-12-30 13:25:07
Mikrotik
Ninja5, 2014-12-30 13:25:07

How to deal with traffic marking in RouterOS (Mikrotik)?

Hello,
Please help me understand the marking and routing of traffic in RouterOS.
Given: Mikrotik 750GL (RouterOS 5.26), two providers (isp1,2) and 3 subnets (Network1,2,3).
port1: port1 - 1.1.1.1 (isp1)
port2: port2 - 2.2.2.2 (isp2)
port3: port3 - 192.168.1.0/24 (network1)
port4: port4 - 192.168.2.0/24 (network2)
port5: port5 - 192.168. 3.0/24 (network3)
Task:
1) Set up labeling in/out. traffic (input / output chains) for the router, so that traffic goes to the same interface from which it came. (For correct operation of VPN-pptp, etc.) for isp1, isp2.
2)Configure marking of passing traffic (forward/prerouting chains) for Network1/2/3 networks. In order for traffic to go to the same interface from which it came and to configure redundancy (see step 3)
3) You need to configure redundancy:
Network1: isp1->isp2
Network2: isp2->isp1
Network3: isp1->isp2
My config:
/ ip firewall mangle

01 add action=mark-routing chain=output disabled=no new-routing-mark=isp1 out-interface=port1 passthrough=no
02 add action=mark-routing chain=output disabled=no new-routing-mark=isp2 out-interface=port2 passthrough=no
 
03 add action=mark-connection chain=input disabled=no dst-address=1.1.1.1 in-interface=port1 new-connection-mark=port1_c_input passthrough=yes
04 add action=mark-routing chain=output connection-mark=port1_c_input disabled=no new-routing-mark=port1_r_input passthrough=no
 
05 add action=mark-connection chain=input disabled=no dst-address=2.2.2.2 in-interface=port2 new-connection-mark=port2_c_input passthrough=yes
06 add action=mark-routing chain=output connection-mark=port2_c_input disabled=no new-routing-mark=port2_r_input passthrough=no
 
07 add action=mark-routing chain=prerouting disabled=no new-routing-mark=network1 passthrough=no src-address=192.168.1.0/24
08 add action=mark-routing chain=prerouting disabled=no new-routing-mark=network2 passthrough=no src-address=192.168.2.0/24
09 add action=mark-routing chain=prerouting disabled=no new-routing-mark=network3 passthrough=no src-address=192.168.3.0/24
 
10 add action=mark-connection chain=forward disabled=no dst-address=192.168.1.0/24 in-interface=port1 new-connection-mark=port1-network1 passthrough=no
11 add action=mark-routing chain=prerouting connection-mark=port1-network1 disabled=no new-routing-mark=port1_network1 passthrough=no src-address=192.168.1.0/24
12 add action=mark-connection chain=forward disabled=no dst-address=192.168.1.0/24 in-interface=port2 new-connection-mark=port2-network1 passthrough=no
13 add action=mark-routing chain=prerouting connection-mark=port2-network1 disabled=no new-routing-mark=port2_network1 passthrough=no src-address=192.168.1.0/24
14 add action=mark-connection chain=forward disabled=no dst-address=192.168.2.0/24 in-interface=port1 new-connection-mark=port1-network2 passthrough=no
15 add action=mark-routing chain=prerouting connection-mark=port1-network2 disabled=no new-routing-mark=port1_network2 passthrough=no src-address=192.168.2.0/24
16 add action=mark-connection chain=forward disabled=no dst-address=192.168.2.0/24 in-interface=port2 new-connection-mark=port2-network2 passthrough=no
17 add action=mark-routing chain=prerouting connection-mark=port2-network2 disabled=no new-routing-mark=port2_network2 passthrough=no src-address=192.168.2.0/24
18 add action=mark-connection chain=forward disabled=no dst-address=192.168.3.0/24 in-interface=port1 new-connection-mark=port1-network3 passthrough=no
19 add action=mark-routing chain=prerouting connection-mark=port1-network3 disabled=no new-routing-mark=port1_network3 passthrough=no src-address=192.168.3.0/24
20 add action=mark-connection chain=forward disabled=no dst-address=192.168.3.0/24 in-interface=port2 new-connection-mark=port2-network3 passthrough=no
21 add action=mark-routing chain=prerouting connection-mark=port2-network3 disabled=no new-routing-mark=port2_network3 passthrough=no src-address=192.168.3.0/24

/ip route
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.1.1.10 routing-mark=isp1 scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=2.2.2.20 routing-mark=isp2 scope=30 target-scope=10
 
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.1.1.10 routing-mark=port1_r_input scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=2.2.2.20 routing-mark=port2_r_input scope=30 target-scope=10
 
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.1.1.10 routing-mark=network1 scope=30 target-scope=10
add disabled=no distance=10 dst-address=0.0.0.0/0 gateway=2.2.2.20 routing-mark=network1 scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=2.2.2.20 routing-mark=network2 scope=30 target-scope=10
add disabled=no distance=10 dst-address=0.0.0.0/0 gateway=1.1.1.10 routing-mark=network2 scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.1.1.10 routing-mark=network3 scope=30 target-scope=10
add disabled=no distance=10 dst-address=0.0.0.0/0 gateway=2.2.2.20 routing-mark=network3 scope=30 target-scope=10
 
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.1.1.10 routing-mark=port1_network1 scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=2.2.2.20 routing-mark=port2_network1 scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.1.1.10 routing-mark=port1_network2 scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=2.2.2.20 routing-mark=port2_network2 scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.1.1.10 routing-mark=port1_network3 scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=2.2.2.20 routing-mark=port2_network3 scope=30 target-scope=10
 
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.1.1.10,2.2.2.20,2.2.2.20 scope=30 target-scope=10

Is everything correct?
All with the coming!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ruskella, 2014-01-14
@ruskella

Not your case, habrahabr.ru/post/186284 ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question