How To: MikroTik OSPF Tutorial

MikroTik OSPF

Why would somebody want to run Open Shortest Path First (OSPF) on their network?

By utilizing the OSPF dynamic routing protocol, the number of static routes would be reduced. OSPF would also allow automatic route updates when a new network has been added. As a path to a new network has been changed, OSFP would also allow automatic route updates as the devices or links behave upward or downward.

Basics
Taking a step backwards to look at the basics of OSPF may clarify some of the initial questions on why this is actually useful. OSPF is best served by running inside of a single Autonomous System, which are a group of devices under a single administrative control. The OSPF enables network routers to share information with one another. These connected routers within the OSPF network are referred to as Neighbors. The Neighbors are identified by an IP address that the router will use to identify itself to other routers running OSPF, known as the router ID. An initial connection can be made by utilizing a Hello packet, which is a special packet sent out periodically by a network router to establish and confirm network adjacency. Once the network adjacency relationship is formed, the routers can now share LSA packets.

Set-Up
OSPF is best set up with a router ID set to a loopback address. To set this up, first set up a bridge and name it “Loopback.” The next step is to assign the bridge a private address that no existing device already uses (i.e. 172.1.0.1). This will allow the router to be keep the same router ID in the event that an interface goes down. Step three involves adding an instance in order to set the router ID to loopback address that had been set up before. To do so go into Routing > OSPF. The last step will be to turn on OSFP and start to broadcast Hello packets on the network to the Neighbor routers.

Running the Process
Once all of the aforementioned steps have been completed the routing table will be populated with dynamic routes created by the OSPF process running on the router. If any of the OSPF routes are set to the default cost of 110, they will take precedence unless changed over the 110 value. In other words, OSPF will always use the highest IP address on the router’s loopback interface, regardless of OSPF enabled loopback.

To truly see OSFP in action, add the following lines of code into three demo routers:

Add Bridges on R1, R2, R3

/interface
bridgeadd name=LAN
add name=Lo0

Add IP addresses to routersR1

/ip address
add address=172.16.1.1/24 interface=LAN network=172.16.1.0
add address=10.0.2.2/30 interface=ether1 network=10.0.2.0
add address=10.0.0.1/30 interface=ether5 network=10.0.0.0
add address=172.1.0.1/32 interface=Lo0 network=172.1.0.1

R2

/ip address
add address=172.16.2.1/24 interface=LAN network=172.16.2.0
add address=10.0.1.1/30 interface=ether5 network=10.0.1.0
add address=10.0.0.2/30 interface=ether1 network=10.0.0.0
add address=172.1.0.2/32 interface=Lo0 network=172.1.0.2

R3

/ip address
add address=10.0.1.2/30 interface=ether1 network=10.0.1.0
add address=10.0.2.1/30 interface=ether5 network=10.0.2.0
add address=172.16.3.1/24 interface=LAN network=172.16.3.0
add address=172.1.0.3/32 interface=Lo0 network=172.1.0.3

Setup instance and set router-ID
R1

/routing ospf instance set [ find default=yes ] router-id=172.1.0.1

R2

/routing ospf instance set [ find default=yes ] router-id=172.1.0.2

R3

/routing ospf instance set [ find default=yes ] router-id=172.1.0.3

Add network statements for each network you wish to advertise
R1

/routing ospf network
add area=backbone network=172.16.1.0/24
add area=backbone network=10.0.0.0/30
add area=backbone network=10.0.2.0/30
add area=backbone network=172.1.0.1/32

R2

/routing ospf network
add area=backbone network=172.16.2.0/24
add area=backbone network=10.0.1.0/30
add area=backbone network=10.0.0.0/30
add area=backbone network=172.1.0.2/32

R3

/routing ospf network
add area=backbone network=172.16.3.0/24
add area=backbone network=10.0.2.0/30
add area=backbone network=10.0.1.0/30
add area=backbone network=172.1.0.3/32

Below is an example of R1’s routing table after all the routers have been setup.

MikroTik OSPF

Joshua Gray

About Joshua Gray

Joshua’s experience includes 8 years of networks engineering in enterprise environments and 8 years in LAN/WLAN design, configuration, implementation and monitoring. Joshua’s specialties include Routing Protocols, IPV6, and Wireless. He is also currently completing his Masters in Network Engineering, Security and Management at DePaul University. Joshua’s teaching experience comes from an academic background where he taught networking technologies as a lab assistant.

More posts by Joshua Gray
X