This tutorial explains how to configure OSPF (Open Path Shortest First) Routing protocol step by step in detail. OSPF is one of the best Link State Routing protocol for larger network area. Learn how to enable and configure OSPF routing in Cisco router with practical example in packet tracer.
To explain OSPF Routing, I will use packet tracer network simulator software. You can use this too but you can use any network simulator software or can use a real Cisco switch to follow this guide.
There is no difference in output as long as your selected software contains the commands explained in this tutorial.
Either you can create the following lab given below in the figure by self , following the command and the guide or you can download the lab it self which link is given below
Initial IP configuration
This is the IP Table that you need to configure on the ports of all the devices in order to achieve the ospf lab.
Configure the IP
IP configuration for PC
To configure the IP on pc you can simple double click on the pc then go to Desktop>Ip configuration and then enter the IP and default gateway.
This way configure the IP and default gateway on PC1 also .
IP configuration for Routers
We need to configure IP address and other parameters on interfaces before we could actually use them for routing. Interface mode is used to assign IP address. Interface mode can be accessed from global configuration mode and for which we can use the following commands
Router>enable Router#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router(config)#
From global configuration mode we can enter in interface mode. From there we can configure the interface. Following commands will assign IP address on FastEthernet0/0.
now we are all set up to configure the IP on router so let configure on each router and also make the port up.
R1(config)#interface s0/0/0 R1(config-if)#ip address 10.0.0.1 255.0.0.0 R1(config-if)#no shutdown R1(config-if)#interface s0/1/0 R1(config-if)#ip address 126.96.36.199 255.0.0.0 R1(config-if)#no shutdown R1(config-if)#interface fa0/1 R1(config-if)#ip address 192.168.1.1 255.255.255.0 R1(config-if)#no shutdown Router(config-if)#exit R1(config)#
R1(config)#interface s0/0/0 R1(config-if)#ip address 188.8.131.52 255.0.0.0 R1(config-if)#no shutdown R1(config-if)#interface s0/1/0 R1(config-if)#ip address 184.108.40.206 255.0.0.0 R1(config-if)#no shutdown Router(config-if)#exit R1(config)#
R1(config)#interface s0/0/0 R1(config-if)#ip address 10.0.0.2 255.0.0.0 R1(config-if)#no shutdown R1(config-if)#interface s0/1/0 R1(config-if)#ip address 220.127.116.11 255.0.0.0 R1(config-if)#no shutdown R1(config-if)#interface fa0/1 R1(config-if)#ip address 192.168.2.1 255.255.255.0 R1(config-if)#no shutdown Router(config-if)#exit R1(config)#
Note- Since Serial Cable’s are having 2 ends DCE and DTE and for the real environment you need to configure the Clock Rate and Bandwidth on DCE ends . for the packet tracer if you don’t then no issue but in real keep in mind that it is necessary. so to do so you can apply the command below on the DCE ends.
R1(config)#interface s0/0/0 R1(config-if)#clock rate 64000 R1(config-if)#bandwidth 64 R1(config-if)#no shutdown R1(config-if)#exit
OSPF Routing Protocol Configuration
Configuration of OSPF protocol is much easier than you think. It requires only two steps to configure the OSPF routing.
- Enable OSPF routing protocol from global configuration mode.
- Tell OSPF routing protocol which networks you want to advertise.
Let’s configure it in R1 ( In my case i’ll add all the network in OSPF routing while it is up to you which network you want to add to perform the ospf routing)
R1(config)#router ospf 1
R1(config-router)#network 10.0.0.0 0.255.255.255 area 0
R1(config-router)#network 18.104.22.168 0.255.255.255 area 0
R1(config-router)#network 192.168.1.0 0.0.0.255 area 0
Note- Here in first command 1 is the OSPF process ID which you can take from 1-65535 and note that if you configure OSPF with multiple OSPF ID then there will be multiple OSPF processes which may use more CPU/RAM and my cause system instability.
While in the 2nd command there is the wildcard mask not the subnet mask and for area number you can take any number from 0-4294967295 . Just keep in mind that area number should be same on all the routers you are configuring the OSPF
To get a better insight you can read this article- What is ospf
R2(config)#router ospf 2
R2(config-router)#network 10.0.0.0 0.255.255.255 area 0
R2(config-router)#network 22.214.171.124 0.255.255.255 area 0
R2(config-router)#network 126.96.36.199 0.0.0.255 area 0
Note- have you seen here i have taken the ospf ID 2 not 1 unlike the R1 it is because it is just the ospf process ID that we can take any number from 1-65535 it doesn’t matter what you take with respect to other routers just take one
R3(config-router)#router ospf 1
R3(config-router)#network 188.8.131.52 0.255.255.255 area 0
R3(config-router)#network 184.108.40.206 0.255.255.255 area 0
Verify the OSPF Routing
To verify the OSPF routing you can run the following command and the result be look something like this. if you are configuring the same as above otherwise it may differ.
Here you can see that in R1 it’s routing table has all the routes as we have configured for all the networks to be participated in OSPF.
you can see all the neighbor network are also there in the neighbor table of OSPF.
Now let’s verify each route via sending the packets via PING . and for this go to pc1 then open the command prompt and issue the ping command with network id.
so here you can see its pinging and the routing is 100% successfull.
In the above image of routing scenario you can clearly see that to reach from pc1 to pc2 there are 2 path available
So let’s trace the routing path and let’s see which path ospf routing protocol choose to forward the data to the destination that is from pc1-pc2
for this you can go to pc1 then in command prompt issue the following command
Now here you can see its following the path 1 .
Do you know why it is choosing this path because this is the shortest path as you can see clearly for path 2 we have to travel one extra router and since OSPF uses SPF algo to determine the shortest path , that is why it is using this path.
To understand more let’s shutdown the port s0/0/0 of the R1 so that there will be only one path that is path 2. and now trace the route
now you can see it is following the 2nd path and for which it has to route the data to one more router that is why OSPF was not choosing this path when there were two path available as Path 2 is longer than Path 1
Download this Lab
Note that the lab is built from Cisco Packet Tracer V6.2 so it will only work in 6.2 or later version not in any other version.
Feel free to ask in comment if you have any problem .