I have this route on my Juniper Router and some destinations have two routes: OSPF and BGP. I want to change the administrative distance for the BGP route so that it will be smaller than the OSPF route.
How do I do it?
Network Engineering Stack Exchange is a question and answer site for network engineers. It only takes a minute to sign up.Sign up to join this community
You can use the command
set protocols bgp group <group name> preference <value>
or you can also use a routing policy to change preference for specific routes within BGP.
However as commented by @TeunVink, there's only limited cases where you would tweak administrative distances. There's generally better options, or that would mean your network design is somewhat flawed.
Also you must be aware of how Juniper handle external BGP vs internal BGP and OSPF.
From the page Example: Configuring the Preference Value for BGP Routes
By default, the routing software assigns a preference of 170 to routes that originated from BGP. Of all the routing protocols, BGP has the highest default preference value, which means that routes learned by BGP are the least likely to become the active route.
Some vendors have a preference (distance) of 20 for external BGP (EBGP) and a distance of 200 for internal BGP (IGBP). Junos OS uses the same value (170) for both EBGP and IBGP. However, this difference between vendors has no operational impact because Junos OS always prefers EBGP routes over IBGP routes.
Another area in which vendors differ is in regard to IGP distance compared to BGP distance. For example, some vendors assign a distance of 110 to OSPF routes. This is higher than the EBGP distance of 20 , and results in the selection of an EBGP route over an equivalent OSPF route. In the same scenario, Junos OS chooses the OSPF route, because of the default preference 10 for an internal OSPF route and 150 for an external OSPF route, which are both lower than the 170 preference assigned to all BGP routes.