Manual:Route lookup example
Route lookup example
Simple example:
[admin@MikroTik] > /ip address print # ADDRESS NETWORK BROADCAST INTERFACE 0 10.1.0.3/16 10.0.0.0 10.1.255.255 ether1 1 10.2.0.3/16 10.0.0.0 10.2.255.255 ether2 [admin@MikroTik] > /ip route print # DST-ADDRESS PREF-SRC G GATEWAY DISTANCE INTERFACE 0 A S 0.0.0.0/0 r 10.1.0.1 1 ether1 r 10.2.0.1 ether2 1 ADC 10.1.0.0/16 10.1.0.3 0 ether1 2 ADC 10.2.0.0/16 10.2.0.3 0 ether2
- Packet with destination address 10.1.1.1 will be forwarded using connected route (number 1) via interface ether1 to host with address 10.1.1.1.
- Packet with destination address 10.50.0.1 will be forwarded using static route (number 0) via interface ether1 to gateway 10.1.0.1, or via interface ether2 to gateway 10.2.0.1.
- Locally originated packet with destination address 10.100.0.1 will be sent using static route (number 0) via interface ether1 to gateway 10.1.0.1, or via interface ether2 to gateway 10.2.0.1.
- Locally originated packet with destination address 10.2.1.1 will be sent using connecter route (number 2) via interface ether2 to host with address 10.2.1.1 using source address 10.2.0.3.
If route does not have pref-src, then source address of locally originated packets is selected from local addresses of the router so that:
- this local address is assigned to the output interface
- gateway matches network of this local address
So, in the above example, if locally originated packet is sent to gateway 10.1.0.1, then local address 10.1.0.3 will be chosen, because
- address 10.1.0.3 is assigned to the output interface of this route (ether1)
- gateway 10.1.0.1 is inside the network 10.1.0.0/16 of this address