Basic routing
«Second star to the right, ...and straight on till morning!»
Edoardo Bennato
Routing is the basis of the network functionality implemented by level 3 entities (OSI) and allows two nodes A and B, not directly connected, to communicate each other through the collaboration of other nodes placed on a path in the network that connects A and B.
The task of the network layer is therefore the transmission of packets between two arbitrary hosts, which in general are not directly connected, that is they do not have a direct connection between them. In the ISO / OSI model, the network layer software is present in all the nodes of the network, while that of the higher levels is present only in the terminal nodes. In detail, the functions of the network layer are:
Purpose of routing: connecting networks.
Routing is necessary when the network starts to become complex; If we want:
- to be able to monitor and better manage the network;
- make the network more secure as firewall filters become simpler and more complete;
- to improve performance by concentrating broadcast traffic only in each subnet / network;
- to connect together public IP networks;
- to connect different Wide Area Netwok (company, provider, ...).
The principle on which IP routing is based is very simple: send packets on the shortest path to the destination. The calculation is performed in a distributed way by the routers through an exchange of information among them; in the table of each router possesses and it is indicated the direction the packet must take, only the next router on the path (next hop) is indicated, not the entire path. This approach exploits the property of graphs according to which even the sub-paths of a minimum path are minimal.
Routing classification
Routing, ie the process for forwarding packets from a network to other networks can be done using:
- Static routing - In this case the administrators perform the routing manually defining each network and its destination gateway and repeating this operation for each router present in all the connected networks.
- Dynamic routing - In this case the administrators make only a simple configuration in which the dynamic routing function is enabled on each router and the routers automatically search for the routes and the best gateway from all the connected networks.
Classification of dynamic routing protocols
routing-protocols
RouterOS routing components
The router keeps the routing information in two separate spaces:
- RIB (Routing Information Base) - is the routing table
- FIB (Forwarding Information Base) - is the forwarding table
Router Information Base (RIB)
rib The routing table is a table of data that in a specific router lists all the known routes to certain networks. For each route the metric that represents the cost that is spent along this route is indicated. The routing table consists of:
- all routes collected by dynamic routing protocols;
- all paths for the connected networks, that is for the interfaces directly connected to the router;
- each additional route manually added (static routes).
In RouterOS the routing table can be displayed using menu IP
> Route
> List
.
The
routing table is used:
- to filter the routing information of all routing protocol types;
- to calculate and choose the best route for a certain network;
- to create and update the forwarding table (see section fib
);
- to distribute routing information using dynamic routing protocols.
For each entry in the routing table there are letters indicating the route status according to the abbreviations shown in the table
table:route-flag
:
Property
|
Label
|
Description
|
disabled
|
X
|
The route is disabled ie it is not used.
|
active
|
A
|
The route is used to forward packets.
|
dynamic
|
D
|
The route was created by the software automatically.
|
|
|
It will not be exported and cannot be modified directly.
|
connected
|
C
|
Connected route.
|
statica
|
S
|
Static Route.
|
rip
|
r
|
Created through the RIP protocol.
|
bgp
|
b
|
Created through the BGP protocol.
|
ospf
|
o
|
Created through the OSPF protocol.
|
mme
|
m
|
Created through the MME protocol.
|
blackhole
|
B
|
Do not consider packets addressed to this route and
|
|
|
do not notify anyone of the action.
|
unreachable
|
U
|
Do not consider packages addressed to this route but
|
|
|
notify the situation with an ICMP message.
|
prohibited
|
P
|
Do not consider packets addressed to this route but
|
|
|
notify the situation with an ICMP message.
|
Labels that can be associated with a route
table:route-fla
g
Forwarding Information Base (FIB)
fib Routing tables (RIB) are generally not used directly for packet forwarding; the data present in the RIB are used to generate smaller and specific tables called forwarding tables: Forwarding Information Base (FIB). A forwarding table contains only the path selected by the routing algorithm to continue routing the packet to its destination. This path is often in the form of a cache in compressed or precompiled format, in a format optimized for archiving and searching for the specific hardware of the router. In Cisco devices this component is called Cisco Express Forwarding (CEF). Then the forwarding table:
- is the product of the routing table after it has been filtered;
- it's a cached copy;
- all active routes are in the main table;
- if routing markings are not used all default routes will be in main (see below to understand this step)
- there is only one hidden implicit rule ("catch all" rule) that uses the main table for all target searches.
How RIB and FIB tables are used
FIB uses the following package information to determine its destination:
- sourcing address,
- destination address,
- source interface,
- possible marking of routing,
- ToS (type of service) - field currently not used by the IPv4 protocol - not used by RouterOS in the routing rules, but part of the search key in the routing cache.
The possible routing decisions are:
- receive packet locally
- discard the packet (silently or by sending an ICMP message to the sender of the packet)
- send the packet to a specific IP address on a specific interface
The results of the routing decision are remembered in the routing cache (FIB) to improve forwarding performance. When another packet with the same source address, destination address, source interface, routing mark and ToS is routed, the cached results are used. This also allows the implementation of load balancing by connection (per-connection load balancing) via ECMP routes, since the values used to look up the entry in the routing cache are the same for all the packets belonging to the same connection and going in the same direction.
Forwarding Information Base (FIB)
If there is no routing entry in the cache for a packet then this is created by executing a routing decision according to the following process:
- it is checked whether the package should be delivered locally (the destination address is the router address),
- implicit routing rules are processed,
- routing rules added by the user are processed,
- implicit catch-all rule that searches for the destination in the main routing table is processed
- if all the previous steps fail then
the return result is "unreachable network".
Rules that do not match the current packet are ignored. If the rule has a drop or unreachable action then this is returned as a result of the routing decision process. If the action is the search, the destination address of the packet is searched for in the routing table specified in the rule. If search fails (there is no route that matches the destination address of the packet), then the FIB proceeds to the next rule. Otherwise:
- if the path type is blackhole, prohibited or unreachable, then it returns this action as a result of the routing decision;
- if it is a connected route or a route that has indicated an interface as a gateway value, then it returns this interface and the destination address of the packet as a result of the routing decision;
- if this route has the IP address as the gateway value, then it returns this address and the associated interface as a result of the routing decision;
- if this route has more than one value of nexthop, then it returns one of them in round robin mode.
The result of this routing decision is stored in the new routing cache entry. Notice how a routing decision is returned from the indicated process which can be:
- IP address of nexthop interface
- point-to-point interface
- local delivery
- to discard
- ICMP prohibite
d
- ICMP unreachable host
- ICMP network unreachable
Interoperability between RIB and FIB
Default route
The route with destination address 0.0.0.0/0 applies to all destination addresses. This path is called the default route and indicated router is called the default gateway. If the routing table contains an active default route then the routing table search will always be successful. To use an analogy is like traveling in a city and finding a road sign indicating "all directions".
Connected Routes
Connected routes are automatically created for each IP network that has at least one interface connected to it (as specified in the IP address configuration). RIB keeps track of the status of the connected routes but does not change them. For each connected route there is an ip address so that:
- the dst-address network of the connected route is equal to the network of the ip address
- the netmask of the dst-address of the connected route is equal to the netmask of the ip address
- the pref-src of the connected route is the same as the ip address
- the interface of the connected route is the same as the interface
Correspondence between addresses and connected routes.
We saw that every time we add an IP address on a valid interface (active interface) a connected route is automatically created. It should be noted that if there are two IP addresses coming from the same subnet and from the same interface there will be only one path connected. For this it is important not to place two IP addresses of the same subnet on two different interfaces, because it will confuse the RIB. For the same reason it is suggested that if an interface has multiple IP addresses on the same subnet, only the first address is indicated with the complete netmask while the
others will be indicated with the netmask / 32.
As described at the beginning of the chapter in MikroTik RouterOS dynamic routes and static routes are possible. The former are created automatically when an IP address is added to an interface or through routing information obtained from specific protocols such as RIP, OSPF and BGP. Static routes are routing information entered manually by the user (network administrator) to define a specific route. The default route is an example of a static route.
Static routing
Static routes are added by creating an entry in the RIB and defining a static route to route packets. The destination network and router (gateway) to be used for this destination is indicated. The gateway can be:
- IP address,
- the interface.
Remember that if Dst-address indicates 0.0.0.0/0, all IPs on the internet are included and a default route is created.
The following parameters are available when adding a static route:
- destination;
-
- destination address and netmask;
- 0.0.0.0/0 if it is a default route.
- gateway:
-
- the IP address of the gateway, must be the IP address of a subnet with IP installed on one of the
router interfaces;
- the gateway in the form of an interface: it is used when the IP gateway is unknown or is dynamic, for example in the case of a point-to-point or serial connection.
- pref source:
-
- the source IP address of the packet that will leave the router,
- usually it is the IP address installed on the interface where the gateway is located.
- distance:
-
- it is used for route calculation and route selection;
- value is between 0 and 255
- by default the value is decided on the routing protocol used:
-
- connected routes: 0
- static routes: 1
- eBGP: 20
- OSPF: 110
- RIP: 120
- MME: 130
- iBGP: 200
- note that a distance of 255 means "rejected".
- scope and target scope:
-
- used for nexthop recursive lookup (see section scope
on page scope
).
Labs
Before carrying out the following laboratories make sure you have answered correctly to the summary questions on the page
domande-1
.
Static routing - guided
Simple static routing
This laboratory allows you to recreate the network infrastructure of figure
routing-statico-semplice
and to verify the correctness of your answers. target
- restore factory router configuration (without default);
- connect the laptops between the participants based on the topology above;
- enter the following configuration in router R1:
{R1}
/ip address
add address=10.10.20.1/24 interface=ether1 network=10.10.20.0
add address=10.10.10.1/24 interface=ether2 network=10.10.10.0
add address=11.11.11.2/24 interface=ether3 network=11.11.11.0
/ip route add distance=1 dst-address=0.0.0.0/0 gateway=11.11.11.1
/system identity set name=R1
- enter the following configuration in router R2:
{R2}
/ip address
add address=11.11.11.1/24 interface=ether1 network=11.11.11.0
add address=22.22.22.2/24 interface=ether2 network=22.22.22.0
/ip route
add distance=1 dst-address=0.0.0.0/0 gateway=22.22.22.2
add distance=1 dst-address=10.10.10.0/24 gateway=11.11.11.2
add distance=1 dst-address=10.10.20.0/24 gateway=11.11.11.2
/system identity set name=R2
The laboratory is correctly executed if it is possible to ping between the two laptops and both can reach the 22.22.22.2 interface with the ping command.
Static routing - without help
Network with static routing
routing-statico-semplice-2
Run the following operations independently:
- restore router configuration (without default);
- connect the laptops between the participants based on the topology above;
- performs static routing on each router as shown in the diagram.
The lab runs correctly if you can ping the three laptops.
Labs solutions
{R1}
/system identity set name=R1
/ip address
add address=192.168.1.1/24 interface=ether1 network=192.168.1.0
add address=12.12.12.1/24 interface=ether2 network=12.12.12.0
/ip route
add distance=1 dst-address=23.23.23.0/24 gateway=12.12.12.2
add distance=1 dst-address=192.168.2.0/24 gateway=12.12.12.2
add distance=1 dst-address=192.168.3.0/24 gateway=12.12.12.2
{R2}
/system identity set name=R2
/ip address
add address=192.168.2.1/24 interface=ether1 network=192.168.2.0
add address=12.12.12.2/24 interface=ether2 network=12.12.12.0
add address=23.23.23.2/24 interface=ether3 network=23.23.23.0
/ip route
add distance=1 dst-address=192.168.1.0/24 gateway=12.12.12.1
add distance=1 dst-address=192.168.3.0/24 gateway=23.23.23.3
{R3}
/system identity set name=R3
/ip address
add address=192.168.3.1/24 interface=ether1 network=192.168.3.0
add address=23.23.23.3/24 interface=ether2 network=23.23.23.0
/ip route
add distance=1 dst-address=192.168.1.0/24 gateway=23.23.23.2
add distance=1 dst-address=192.168.2.0/24 gateway=23.23.23.2
Summary questions
domande-1
- The default distance value for a static route is:
- 255
- 1
- 10
- 0
- The following routes are present in the routing table:
0 dst=192.168.1.0/24 gateway=192.168.1.1
1 dst=192.168.1.0/25 gateway=192.168.1.2
Which gateway will be used to reach the 192.168.1.5 ip?
- Both, half of the traffic through 192.168.1.1 and the other half through 192.168.1.1
- Through 192.168.1.1
- Through 192.168.1.2
- The required route is not present in the routing table
- The default distance value for a connected route
is:
- 255
- 1
- 10
- 0
- Can a route have the D and S flags at the same time?
- Yes
- No
- Can a route have the A, C and S flags at the same time?
- Yes
- No
- The following routes are present in the routing table:
0 dst=192.168.1.0/24 gateway=192.168.1.1 distance=10
1 dst=192.168.1.0/25 gateway=192.168.1.2 distance=20
Which gateway will be used to reach the 192.168.1.5 ip?
- Both, half of the traffic through 192.168.1.1 and the other half through 192.168.1.1
- Through 192.168.1.1
- Through 192.168.1.2
- None because the distance is >= 10
- Remembering that the gateway routers must always be in the subnet of an IP interface of the router to answer the following questions with reference to figure routing-statico-semplice
:
Network with static routing
routing-statico-semplice
- On laptop A, what is the IP gateway on the 11.11.11.0/24 network?
- On laptop A, what is the IP gateway for the network is 22.22.22.0/24?
- On laptop A, what is the IP of the default gateway?
- In R1, what is the IP gateway on the 22.22.22.0/24 network?
- In R1, what is the IP of the default gateway?
- On R2, what IP gateways need to be set up to reach laptop networks?
Solutions