AD vs prefix length

Recently was asked a question on how to advertise specific routes over BGP when the prefix is not in the routing table. We decided to add static Null0 routes and advertise them over the BGP link. I was also provided the below points in choosing the route in the table.

  1. First the administrative distance (AD) is examined. If there are two entries that the IP address matches with, the entry with the lower AD will be used.
  2. If the AD is the same, then the more specific entry, that is, the entry with the smallest subnet mask is used.
  3. If the subnet mask is the same, then the entry with the lowest metric is used.
  4. If the metric is the same, then load balancing takes place.

The above order seems to be wrong according to some Cisco docs as in.

Should the prefix length triumph over AD ?

Example : as connected vs as static discarded/Null0 route.

Both the /24 and /32 are on the same switch.

I think is preferred over the /24 and the return traffic destined to will come back and the router drops it because /32 is chosen as it’s a Null route.

How can I overcome this issue ? Any ideas

Hello Jyothi

Yes, you are correct, the order of criteria checked is incorrect. This was a post I had posted, but I have since corrected it. The corrected post can be found here:

Thus, if you use a Null route, any traffic going to will be dropped. However, in order to correctly configure this, you should configure a static route to with an exit interface like so:

ip route gigabitethernet0/0

That way, any traffic that is destined for will match this route, and be sent out of the appropriate interface. Thus, such traffic will not be dropped.

I hope this has been helpful!


Hi Laz, thanks for correcting the earlier info. I think I have another problem with routing. I thought of using the exit interface after I figured Null0 won’t work but apparently because the server subnet ( the /24 from my earlier post ) is being redistributed into OSPF the router connecting the exit interface is going to send the packets right back to this device and again the static route will take effect pushing the packet back to the exit interface creating a routing loop.

to make it simple I tried my best to explain what’s happening below.

R1 —OSPF --Gigabit 0/0-- R2 — connected as and static route to Gigabit 0/0

Our server subnet ( /24 ) and the customer uplink ( BGP ) is local to R2

R2 has /24 as connected route redistributed into OSPF so R1 knows abt it.
When you write a static route for the /32 the traffic destined to .2 goes out to Gigabit 0/0 and reaches R1. R1 has route in its routing table for /24 alone pointing it back to R2. This is a routing loop I assume preventing traffic to .2 to never go to the proper interface where it is connected on the router.


Hello Jyothi

My impression was that the network, to which the server with the IP address of belongs to, is a directly connected network to R2. If this is the case, then any traffic destined for either the connected route or the static route should exit the same interface. Even if it is redistributed, it shouldn’t send it back out an incorrect interface, as long as you are using the correct exit interface for the static route.

It could be that I am not clear on your topology. Can you clarify and include a diagram with subnets as well as your OSPF config?