Changing routing protocols administrative distance

protocol-theory

Hello i have one doubt

1.if there are four protocols connections for instance rip,OSPF,static,and direct
which routing protocol would be used , although it will take one with lowest administrative distance. what if i just want only OSPF as a routing protocol not static,rip or any other routing protocols to be used.

2.what command we can use to change administrative distance?

Best Answer

According to your first question, the answer is not as easy as you might think.

When there are multiple routing protocols configured, all of them will run and form adjacencies to their next hop routers and exchange routing information. Most if not each routing protocol has a routing protocol specific information database, containing routes exchanged by this routing protocol. On cisco gear you can view them for example with sh ip ospf database or sh ip rip database.

Now, the router has to decide which routes are placed in his actual routing information base (also called RIB or routing table). Here, the most important factor is the "precision" of a route. That is: the higher the prefix length is, the more exact is the route and the more preferred. Only if there are two identical routes, that is same subnet address and same subnet mask or prefix length, the administrative distance comes into play.

Suppose the following example (note that ADs are default values from Cisco):

  • 192.168.100.0/24 learned by OSPF, AD is 110
  • 192.168.100.128/25 learned by RIP, AD is 120
  • 192.168.200.0/24 directly connected, AD is 0
  • 192.168.200.0/24 static route, AD is 1

In this example, the first route learned by OSPF will be placed in the routing table. As the second one is more specific (25 bit prefix instead of 24) it is also added to the routing table. Note that while the second route is included in the first one, they are not equal due to the different prefix length. The third and fourth routes are identical, but the AD of directly connected routes is always 0 and hence this route is preferred.

So basically you can influence routing decision in at least three ways:

  • In each routing protocol, you can tweak metrics
  • Change the AD of routing protocols
  • Advertise more specific routes which are always preferred.

Changing the AD

For Cisco gear, you can change the AD of routing protocols like this:

! static routes - the last optional value (50) is the AD
ip route 192.168.100.0 255.255.255.0 1.2.3.4 50

! OSPF - can be changed in the OSPF routing process, is slightly more complicated
! The generic command is: distance <AD> <source addr> <wildcard-mask> <ACL>
! AD is configured per source router, and an additional ACL is required
! To change AD of all routes to 85 (instead of default 110)
access-list 10 permit any

router ospf 1
    distance 85 0.0.0.0 255.255.255.255 10

! RIP
! For RIP, the command is:
! distance admin-distance [ prefix prefix-length | prefix mask ]
! The command needs to be entered inside the routing process, where the last 
! elements are not required but can be used to conditionally change the distance

router rip
    distance 50

Beware that you can never change the AD to be lower than or equal to 0, hence routing protocols cannot compete with directly connected routes using the administrative distance. If you need a routing protocol to override directly connected routes you should ask yourself why you need the direct connection. Technically however you could advertise more specific routes.

Related Topic