Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation

Example: Configuring BGP Route Preference (Administrative Distance)

Understanding Route Preference Values

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

0

System routes

4

Static and Static LSPs

5

static

RSVP-signaled LSPs

7

RSVP preference as described in the Junos OS MPLS Applications Configuration Guide

LDP-signaled LSPs

9

LDP preference, as described in the Junos OS MPLS Applications Configuration Guide

OSPF internal route

10

OSPF preference

IS-IS Level 1 internal route

15

IS-IS preference

IS-IS Level 2 internal route

18

IS-IS preference

Redirects

30

Kernel

40

SNMP

50

Router discovery

55

RIP

100

RIP preference

RIPng

100

RIPng preference

PIM

105

Multicast Protocols Configuration Guide

DVMRP

110

Multicast Protocols Configuration Guide

Aggregate

130

aggregate

OSPF AS external routes

150

OSPF external-preference

IS-IS Level 1 external route

160

IS-IS external-preference

IS-IS Level 2 external route

165

IS-IS external-preference

BGP

170

BGP preference, export, import

MSDP

175

Multicast Protocols Configuration 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.

Requirements

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

Overview

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).

Tip: 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.

Topology

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

Configuration

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

set interfaces fe-1/2/0 unit 4 family inet address 1.12.0.1/30set interfaces lo0 unit 2 family inet address 10.255.71.24/32set protocols bgp export send-directset protocols bgp group ext type externalset protocols bgp group ext preference 8set protocols bgp group ext peer-as 65000set protocols bgp group ext neighbor 1.12.0.2set protocols ospf area 0.0.0.0 interface fe-1/2/0.4set protocols ospf area 0.0.0.0 interface 10.255.71.24set policy-options policy-statement send-direct term 1 from protocol directset policy-options policy-statement send-direct term 1 then acceptset routing-options autonomous-system 65500

Device R2

set interfaces fe-1/2/0 unit 6 family inet address 1.12.0.2/30set interfaces lo0 unit 3 family inet address 10.255.14.177/32set protocols bgp export send-directset protocols bgp group ext type externalset protocols bgp group ext peer-as 65500set protocols bgp group ext neighbor 1.12.0.1set protocols ospf area 0.0.0.0 interface fe-1/2/0.6set protocols ospf area 0.0.0.0 interface 10.255.14.177set policy-options policy-statement send-direct term 1 from protocol directset policy-options policy-statement send-direct term 1 then acceptset routing-options autonomous-system 65000

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.
    [edit interfaces]user@R1# set fe-1/2/0 unit 4 family inet address 1.12.0.1/30user@R1# set lo0 unit 2 family inet address 10.255.71.24/32
  2. Configure the local autonomous system.
    [edit routing-options]user@R1# set autonomous-system 65500
  3. Configure the external peering with Device R2.
    [edit protocols bgp]user@R1# set export send-directuser@R1# set group ext type externaluser@R1# set group ext preference 8user@R1# set group ext peer-as 65000user@R1# set group ext neighbor 1.12.0.2
  4. Configure OSPF.
    [edit protocols ospf area 0.0.0.0]user@R1# set interface fe-1/2/0.4user@R1# set interface 10.255.71.24
  5. Configure the routing policy.
    [edit policy-options policy-statement send-direct term 1]user@R1# set from protocol directuser@R1# set then accept

Results

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.

user@R1# show interfaces
fe-1/2/0 {unit 4 {family inet {address 1.12.0.1/30;}}}
lo0 {unit 2 {family inet {address 10.255.71.24/32;}}}
user@R1# show policy-options
policy-statement send-direct {term 1 {from protocol direct;then accept;}}
user@R1# show protocols
protocols {bgp {export send-direct;group ext {type external;preference 8;peer-as 65000;neighbor 1.12.0.2;}}ospf {area 0.0.0.0 {interface fe-1/2/0.4;interface 10.255.71.24;}}}
user@R1# show routing-optionsautonomous-system 65500;

If you are done configuring the device, enter commit from configuration mode.
Repeat these steps on Device R2.

Verification

Confirm that the configuration is working properly.

Verifying the Preference

Purpose

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.

Action

From operational mode, enter the show route command.

user@R1> show route
inet.0: 5 destinations, 7 routes (5 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

1.12.0.0/30        *[Direct/0] 3d 07:03:01
                    > via fe-1/2/0.4
                    [BGP/8] 01:04:49, localpref 100
                      AS path: 65000 I
                    > to 1.12.0.2 via fe-1/2/0.4
1.12.0.1/32        *[Local/0] 3d 07:03:01
                      Local via fe-1/2/0.4
10.255.14.177/32   *[BGP/8] 01:04:49, localpref 100
                      AS path: 65000 I
                    > to 1.12.0.2 via fe-1/2/0.4
                    [OSPF/10] 3d 07:02:16, metric 1
                    > to 1.12.0.2 via fe-1/2/0.4
10.255.71.24/32    *[Direct/0] 3d 07:03:01
                    > via lo0.2
224.0.0.5/32       *[OSPF/10] 5d 03:42:16, metric 1
                      MultiRecv
user@R2> show route
inet.0: 5 destinations, 7 routes (5 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

1.12.0.0/30        *[Direct/0] 3d 07:03:30
                    > via fe-1/2/0.6
                    [BGP/170] 00:45:36, localpref 100
                      AS path: 65500 I
                    > to 1.12.0.1 via fe-1/2/0.6
1.12.0.2/32        *[Local/0] 3d 07:03:30
                      Local via fe-1/2/0.6
10.255.14.177/32   *[Direct/0] 3d 07:03:30
                    > via lo0.3
10.255.71.24/32    *[OSPF/10] 3d 07:02:45, metric 1
                    > to 1.12.0.1 via fe-1/2/0.6
                    [BGP/170] 00:45:36, localpref 100
                      AS path: 65500 I
                    > to 1.12.0.1 via fe-1/2/0.6
224.0.0.5/32       *[OSPF/10] 5d 03:42:45, metric 1
                      MultiRecv

Meaning

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

Published: 2013-07-09