Thursday, November 27, 2008

OSPF distance command

Me & my friend were having some discussion today & reached to the conclusion of ODCS (OSPF Distance Command Sucks). There seems to be some problem with the command.

I did a small recreate with a very simple setup with R2 & R3 as the spokes & R1 as the hub. I had OSPF adjacency going between R1 & R2, R1 & R3. I had 1 loopback on R2 (2.2.2.2/32) & 1 loopback on R3 (3.3.3.3/32) both advertised in OSPF area 0. So, obviously, both the loopbacks were being learnt correctly on the hub as OSPF intra area routes with the default AD of OSPF (110).

Now my objective was to decrease the AD of the loopback being learnt from one router to 109. So I went ahead & added the following command under the OSPF configuration on the hub "distance 109 192.168.1.3 0.0.0.0" (192.168.1.3 being the IP of R3). As soon as I did that as expected the "show ip route ospf" command was showing me that the AD of 3.3.3.3 (loopback from R3) to be 109 while the AD of 2.2.2.2 (loopback from R2) was still 110.

Now, Just for the sake of it I thought of adding an acl at the end of that 'distance' command to test it. So, I took out the command "distance 109 192.168.1.3 0.0.0.0" from the hub R1, & instead added the following commands:

router ospf 1
distance 109 192.168.1.3 0.0.0.0 10
!
access-list 10 permit 3.3.3.3 0.0.0.0
!

As soon as I did this & checked the "show ip route ospf" I saw that both the loopbacks 2.2.2.2 & 3.3.3.3 were being learnt with an AD of 110. Wierd!!

This in turn means if you want to change the AD of all the intra-area routes coming from a neighbor, you can do it easily using the 'distance' command, but if you want to selectively change the AD of some routes coming from a particular neighbor it might be a pain in the wrong place if you try to do it using the 'distance' command in OSPF. Of course you can use the 'distance ospf' command to easily to that for all the intra/inter/external area routes.

I searched to see if there is any bug related to this & found a few which were internal/junked. So, as per the documentation it should work but it does not looks like :-)

Note: "distance" command in OSPF needs you to use the neighbor's router-id instead of the next-hop id.

No comments: