Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Example: Configuring BGP Route Preference (Administrative Distance)


Understanding Route Preference Values (Administrative Distance)

The Junos OS routing protocol process assigns a default preference value (also known as an administrative distance) to each route that the routing table receives. The default value depends on the source of the route. The preference value is a value from 0 through 4,294,967,295 (232 – 1), with a lower value indicating a more preferred route. Table 1 lists the default preference values.

Table 1: Default Route Preference Values

How Route Is Learned

Default Preference

Statement to Modify Default Preference

Directly connected network


System routes


Static and Static LSPs



Static LSPs


RSVP-signaled LSPs


RSVP preference as described in the MPLS Applications Feature Guide

LDP-signaled LSPs


LDP preference, as described in the MPLS Applications Feature Guide

OSPF internal route


OSPF preference

access-internal route


access route


IS-IS Level 1 internal route


IS-IS preference

IS-IS Level 2 internal route


IS-IS preference







Router discovery




RIP preference



RIPng preference



Multicast Protocols Feature Guide



Multicast Protocols Feature Guide




OSPF AS external routes


OSPF external-preference

IS-IS Level 1 external route


IS-IS external-preference

IS-IS Level 2 external route


IS-IS external-preference



BGP preference, export, import



Multicast Protocols Feature Guide

In general, the narrower the scope of the statement, the higher precedence its preference value is given, but the smaller the set of routes it affects. To modify the default preference value for routes learned by routing protocols, you generally apply routing policy when configuring the individual routing protocols. You also can modify some preferences with other configuration statements, which are indicated in the table.

Example: Configuring the Preference Value for BGP Routes

This example shows how to specify the preference for routes learned from BGP. Routing information can be learned from multiple sources. To break ties among equally specific routes learned from multiple sources, each source has a preference value. Routes that are learned through explicit administrative action, such as static routes, are preferred over routes learned from a routing protocol, such as BGP or OSPF. This concept is called administrative distance by some vendors.


No special configuration beyond device initialization is required before you configure this example.


Routing information can be learned from multiple sources, such as through static configuration, BGP, or an interior gateway protocol (IGP). When Junos OS determines a route’s preference to become the active route, it selects the route with the lowest preference as the active route and installs this route into the forwarding table. 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.

In a multivendor environment, you might want to change the preference value for BGP routes so that Junos OS chooses an EBGP route instead of an OSPF route. To accomplish this goal, one option is to include the preference statement in the EBGP configuration. To modify the default BGP preference value, include the preferece statement, specifying a value from 0 through 4,294,967,295 (232 – 1).


Another way to achieve multivendor compatibility is to include the advertise-inactive statement in the EBGP configuration. This causes the routing table to export to BGP the best route learned by BGP even if Junos OS did not select it to be an active route. By default, BGP stores the route information it receives from update messages in the Junos OS routing table, and the routing table exports only active routes into BGP, which BGP then advertises to its peers. The advertise-inactive statement causes Junos OS to advertise the best BGP route that is inactive because of IGP preference. When you use the advertise-inactive statement, the Junos OS device uses the OSPF route for forwarding, and the other vendor’s device uses the EBGP route for forwarding. However, from the perspective of an EBGP peer in a neighboring AS, both vendors’ devices appear to behave the same way.


In the sample network, Device R1 and Device R2 have EBGP routes to each other and also OSPF routes to each other.

This example shows the routing tables in the following cases:

  • Accept the default preference values of 170 for BGP and 10 for OSPF.

  • Change the BGP preference to 8.

Figure 1 shows the sample network.

Figure 1: BGP Preference Value Topology
BGP Preference Value Topology


CLI Quick Configuration

To quickly configure this example, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, and then copy and paste the commands into the CLI at the [edit] hierarchy level.

Device R1

Device R2

Step-by-Step Procedure

The following example requires that you navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode in the CLI User Guide.

To configure Device R1:

  1. Configure the interfaces.
  2. Configure the local autonomous system.
  3. Configure the external peering with Device R2.
  4. Configure OSPF.
  5. Configure the routing policy.


From configuration mode, confirm your configuration by entering the show interfaces, show policy-options, show protocols, and show routing-options commands. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

If you are done configuring the device, enter commit from configuration mode.

Repeat these steps on Device R2.


Confirm that the configuration is working properly.

Verifying the Preference


Make sure that the routing tables on Device R1 and Device R2 reflect the fact that Device R1 is using the configured EBGP preference of 8, and Device R2 is using the default EBGP preference of 170.


From operational mode, enter the show route command.

user@R1> show route
user@R2> show route


The output shows that on Device R1, the active path to Device R2’s loopback interface ( is a BGP route. The output also shows that on Device R2, the active path to Device R1’s loopback interface ( is an OSPF route.