Route Selection Order

1. Longest Prefix Match

    e.g. /24 is chosen over /16 because it is more specific.

    2. Administrative Distance (AD)

    AD is used when there are multiple routes for the same destination and prefix length, for example static (10) wins over BGP (20).

    3. Route Priority

    If the prefix and AD are the same, then priority is used.

    Route A: 172.21.2.0/24 [10/5]
    Route B: 172.21.2.0/24 [10/10]

    The lower priority wins, i.e. 5.

    4. BGP best-path selection

    For multiple BGP paths to the same prefix, BGP attributes determine which path wins.

    Weight
    
    Local Preference
    
    Locally originated
    
    AS-path length
    
    Origin
    
    MED
    
    eBGP vs iBGP
    
    IGP cost to next hop