Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation

Example: Configuring BGP Local Preference

Understanding the BGP Local Preference

Internal BGP (IBGP) sessions use a metric called the local preference, which is carried in IBGP update packets in the path attribute LOCAL_PREF. When an autonomous system (AS) has multiple routes to another AS, the local preference indicates the degree of preference for one route over the other routes. The route with the highest local preference value is preferred.

The LOCAL_PREF path attribute is always advertised to IBGP peers and to neighboring confederations. It is never advertised to external BGP (EBGP) peers. The default behavior is to not modify the LOCAL_PREF path attribute if it is present.

The LOCAL_PREF path attribute applies at export time only, when the routes are exported from the routing table into BGP.

If a BGP route is received without a LOCAL_PREF attribute, the route is stored in the routing table and advertised by BGP as if it were received with a LOCAL_PREF value of 100. A non-BGP route that is advertised by BGP is advertised with a LOCAL_PREF value of 100 by default.

Example: Configuring the Local Preference Value for BGP Routes

This example shows how to configure local preference in internal BGP (IBGP) peer sessions.

Requirements

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

Overview

To change the local preference metric advertised in the path attribute, you must include the local-preference statement, specifying a value from 0 through 4,294,967,295 (232 – 1).

There are several reasons you might want to prefer one path over another. For example, compared to other paths, one path might be less expensive to use, might have higher bandwidth, or might be more stable.

Figure 1 shows a typical network with internal peer sessions and multiple exit points to a neighboring AS.

Figure 1: Typical Network with IBGP Sessions and Multiple Exit Points

Typical Network with IBGP Sessions
and Multiple Exit Points

To reach Device R4, Device R1 can take a path through either Device R2 or Device R3. By default, the local preference is 100 for either route. When the local preferences are equal, Junos OS has rules for breaking the tie and choosing a path. (See Understanding BGP Path Selection.) In this example, the active route is through Device R2 because the router ID of Device R2 is lower than the router ID of Device R3. The following example shows how to override the default behavior with an explicit setting for the local preference. The example configures a local preference of 300 on Device R3, thereby making Device R3 the preferred path to reach Device R4.

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 1 family inet address 12.12.12.1/24set interfaces fe-1/2/1 unit 2 family inet address 13.13.13.1/24set interfaces lo0 unit 1 family inet address 192.168.1.1/32set protocols bgp group internal type internalset protocols bgp group internal local-address 192.168.1.1set protocols bgp group internal export send-directset protocols bgp group internal neighbor 192.168.2.1set protocols bgp group internal neighbor 192.168.3.1set protocols ospf area 0.0.0.0 interface lo0.1 passiveset protocols ospf area 0.0.0.0 interface fe-1/2/0.1set protocols ospf area 0.0.0.0 interface fe-1/2/1.2set 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 123set routing-options router-id 192.168.1.1

Device R2

set interfaces fe-1/2/0 unit 3 family inet address 12.12.12.2/24set interfaces fe-1/2/1 unit 4 family inet address 24.24.24.2/24set interfaces lo0 unit 2 family inet address 192.168.2.1/32set protocols bgp group internal type internalset protocols bgp group internal local-address 192.168.2.1set protocols bgp group internal export send-directset protocols bgp group internal neighbor 192.168.1.1set protocols bgp group internal neighbor 192.168.3.1set protocols bgp group external type externalset protocols bgp group external export send-directset protocols bgp group external peer-as 4set protocols bgp group external neighbor 24.24.24.4set protocols ospf area 0.0.0.0 interface lo0.2 passiveset protocols ospf area 0.0.0.0 interface fe-1/2/0.3set protocols ospf area 0.0.0.0 interface fe-1/2/1.4set 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 123set routing-options router-id 192.168.2.1

Device R3

set interfaces fe-1/2/0 unit 5 family inet address 13.13.13.3/24set interfaces fe-1/2/1 unit 6 family inet address 34.34.34.3/24set interfaces lo0 unit 3 family inet address 192.168.3.1/32set protocols bgp group internal type internalset protocols bgp group internal local-address 192.168.3.1set protocols bgp group internal export send-directset protocols bgp group internal neighbor 192.168.1.1set protocols bgp group internal neighbor 192.168.2.1set protocols bgp group external type externalset protocols bgp group external export send-directset protocols bgp group external peer-as 4set protocols bgp group external neighbor 34.34.34.4set protocols ospf area 0.0.0.0 interface lo0.3 passiveset protocols ospf area 0.0.0.0 interface fe-1/2/0.5set protocols ospf area 0.0.0.0 interface fe-1/2/1.6set 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 123set routing-options router-id 192.168.3.1

Device R4

set interfaces fe-1/2/0 unit 7 family inet address 24.24.24.4/24set interfaces fe-1/2/1 unit 8 family inet address 34.34.34.4/24set interfaces lo0 unit 4 family inet address 192.168.4.1/32set protocols bgp group external type externalset protocols bgp group external export send-directset protocols bgp group external peer-as 123set protocols bgp group external neighbor 34.34.34.3set protocols bgp group external neighbor 24.24.24.2set 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 4set routing-options router-id 192.168.4.1

Configuring Device R1

Step-by-Step Procedure

The following example requires you to 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 fe-1/2/0 unit 1]user@R1# set family inet address 12.12.12.1/24
    [edit interfaces fe-1/2/1 unit 2]user@R1# set family inet address 13.13.13.1/24
    [edit interfaces lo0 unit 1]user@R1# set family inet address 192.168.1.1/32
  2. Configure BGP.
    [edit protocols bgp group internal]user@R1# set type internaluser@R1# set local-address 192.168.1.1user@R1# set export send-directuser@R1# set neighbor 192.168.2.1user@R1# set neighbor 192.168.3.1
  3. Configure OSPF.
    [edit protocols ospf area 0.0.0.0]user@R1# set interface lo0.1 passiveuser@R1# set interface fe-1/2/0.1user@R1# set interface fe-1/2/1.2
  4. Configure a policy that accepts direct routes.

    Note: Other useful options for this scenario might be to accept routes learned through OSPF or local routes.

    [edit policy-options policy-statement send-direct term 1]user@R1# set from protocol directuser@R1# set then accept
  5. Configure the router ID and autonomous system (AS) number.
    [edit routing-options]user@R1# set autonomous-system 123user@R1# set router-id 192.168.1.1

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 1 {family inet {address 12.12.12.1/24;}}}
fe-1/2/1 {unit 2 {family inet {address 13.13.13.1/24;}}}
lo0 {unit 1 {family inet {address 192.168.1.1/32;}}}
user@R1# show policy-options
policy-statement send-direct {term 1 {from protocol direct;then accept;}}
user@R1# show protocols
bgp {group internal {type internal;local-address 192.168.1.1;export send-direct;neighbor 192.168.2.1;neighbor 192.168.3.1;}}
ospf {area 0.0.0.0 {interface lo0.1 {passive;}interface fe-1/2/0.1;interface fe-1/2/1.2;}}
user@R1# show routing-optionsautonomous-system 123;router-id 192.168.1.1;

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

Configuring Device R2

Step-by-Step Procedure

The following example requires you to 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 R2:

  1. Configure the interfaces.
    [edit interfaces fe-1/2/0 unit 3]user@R2# set family inet address 12.12.12.21/24
    [edit interfaces fe-1/2/1 unit 4]user@R2# set family inet address 24.24.24.2/24
    [edit interfaces lo0 unit 2]user@R2# set family inet address 192.168.2.1/32
  2. Configure BGP.
    [edit protocols bgp group internal]user@R2# set type internaluser@R2# set local-address 192.168.2.1user@R2# set export send-directuser@R2# set neighbor 192.168.1.1user@R2# set neighbor 192.168.3.1
    [edit protocols bgp group external]user@R2# set type externaluser@R2# set export send-directuser@R2# set peer-as 4user@R2# set neighbor 24.24.24.4
  3. Configure OSPF.
    [edit protocols ospf area 0.0.0.0]user@R2# set interface lo0.2 passiveuser@R2# set interface fe-1/2/0.3user@R2# set interface fe-1/2/1.4
  4. Configure a policy that accepts direct routes.

    Note: Other useful options for this scenario might be to accept routes learned through OSPF or local routes.

    [edit policy-options policy-statement send-direct term 1]user@R2# set from protocol directuser@R2# set then accept
  5. Configure the router ID and autonomous system (AS) number.
    [edit routing-options]user@R2# set autonomous-system 123user@R2# set router-id 192.168.2.1

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@R2# show interfaces
fe-1/2/0 {unit 3 {family inet {address 12.12.12.2/24;}}}
fe-1/2/1 {unit 4 {family inet {address 24.24.24.2/24;}}}
lo0 {unit 2 {family inet {address 192.168.2.1/32;}}}
user@R2# show policy-options
policy-statement send-direct {term 1 {from protocol direct;then accept;}}
user@R2# show protocols
bgp {group internal {type internal;local-address 192.168.2.1;export send-direct;neighbor 192.168.1.1;neighbor 192.168.3.1;}group external {type external;export send-direct;peer-as 4;neighbor 24.24.24.4;}}
ospf {area 0.0.0.0 {interface lo0.2 {passive;}interface fe-1/2/0.3;interface fe-1/2/1.4;}}
user@R2# show routing-optionsautonomous-system 123;router-id 192.168.2.1;

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

Configuring Device R3

Step-by-Step Procedure

The following example requires you to 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 R3:

  1. Configure the interfaces.
    [edit interfaces fe-1/2/0 unit 5]user@R3# set family inet address 13.13.13.3/24
    [edit interfaces fe-1/2/1 unit 6]user@R3# set family inet address 34.34.34.3/24
    [edit interfaces lo0 unit 3]user@R3# set family inet address 192.168.3.1/32
  2. Configure BGP.
    [edit protocols bgp group internal]user@R3# set type internaluser@R3# set local-address 192.168.3.1user@R3# set export send-directuser@R3# set neighbor 192.168.1.1user@R3# set neighbor 192.168.2.1
    [edit protocols bgp group external]user@R3# set type externaluser@R3# set export send-directuser@R3# set peer-as 4user@R3# set neighbor 34.34.34.4
  3. Configure OSPF.
    [edit protocols ospf area 0.0.0.0]user@R3# set interface lo0.3 passiveuser@R3# set interface fe-1/2/0.5user@R3# set interface fe-1/2/1.6
  4. Configure a policy that accepts direct routes.

    Note: Other useful options for this scenario might be to accept routes learned through OSPF or local routes.

    [edit policy-options policy-statement send-direct term 1]user@R3# set from protocol directuser@R3# set then accept
  5. Configure the router ID and autonomous system (AS) number.
    [edit routing-options]user@R3# set autonomous-system 123user@R3# set router-id 192.168.3.1

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@R3# show interfaces
fe-1/2/0 {unit 5 {family inet {address 13.13.13.3/24;}}}
fe-1/2/1 {unit 6 {family inet {address 34.34.34.3/24;}}}
lo0 {unit 3 {family inet {address 192.168.3.1/32;}}}
user@R3# show policy-options
policy-statement send-direct {term 1 {from protocol direct;then accept;}}
user@R3# show protocols
bgp {group internal {type internal;local-address 192.168.3.1;export send-direct;neighbor 192.168.1.1;neighbor 192.168.2.1;}group external {type external;export send-direct;peer-as 4;neighbor 34.34.34.4;}}
ospf {area 0.0.0.0 {interface lo0.3 {passive;}interface fe-1/2/0.5;interface fe-1/2/1.6;}}
user@R3# show routing-optionsautonomous-system 123;router-id 192.168.3.1;

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

Configuring Device R4

Step-by-Step Procedure

The following example requires you to 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 R4:

  1. Configure the interfaces.
    [edit interfaces fe-1/2/0 unit 7]user@R4# set family inet address 24.24.24.4/24
    [edit interfaces fe-1/2/1 unit 8]user@R4# set family inet address 34.34.34.4/24
    [edit interfaces lo0 unit 4]user@R4# set family inet address 192.168.4.1/32
  2. Configure BGP.
    [edit protocols bgp group external]user@R4# set type externaluser@R4# set export send-directuser@R4# set peer-as 123user@R4# set neighbor 34.34.34.3user@R4# set neighbor 24.24.24.2
  3. Configure a policy that accepts direct routes.

    Note: Other useful options for this scenario might be to accept routes learned through OSPF or local routes.

    [edit policy-options policy-statement send-direct term 1]user@R4# set from protocol directuser@R4# set then accept
  4. Configure the router ID and autonomous system (AS) number.
    [edit routing-options]user@R4# set autonomous-system 4user@R4# set router-id 192.168.4.1

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@R4# show interfaces
fe-1/2/0 {unit 7 {family inet {address 24.24.24.4/24;}}}
fe-1/2/1 {unit 8 {family inet {address 34.34.34.4/24;}}}
lo0 {unit 4 {family inet {address 192.168.4.1/32;}}}
user@R4# show policy-options
policy-statement send-direct {term 1 {from protocol direct;then accept;}}
user@R4# show protocols
bgp {group external {type external;export send-direct;peer-as 123;neighbor 34.34.34.3;neighbor 24.24.24.2;}}
user@R4# show routing-optionsautonomous-system 4;router-id 192.168.4.1;

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

Verification

Confirm that the configuration is working properly.

Checking the Active Path From Device R1 to Device R4

Purpose

Verify that the active path from Device R1 to Device R4 goes through Device R2.

Action

From operational mode, enter the show route protocol bgp command.

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

12.12.12.0/24       [BGP/170] 00:11:48, localpref 100, from 192.168.2.1
                      AS path: I
                    > to 12.12.12.2 via fe-1/2/0.1
13.13.13.0/24       [BGP/170] 00:11:48, localpref 100, from 192.168.3.1
                      AS path: I
                    > to 13.13.13.3 via fe-1/2/1.2
24.24.24.0/24       [BGP/170] 00:11:48, localpref 100, from 192.168.2.1
                      AS path: I
                    > to 12.12.12.2 via fe-1/2/0.1
34.34.34.0/24       [BGP/170] 00:11:48, localpref 100, from 192.168.3.1
                      AS path: I
                    > to 13.13.13.3 via fe-1/2/1.2
192.168.2.1/32      [BGP/170] 00:11:48, localpref 100, from 192.168.2.1
                      AS path: I
                    > to 12.12.12.2 via fe-1/2/0.1
192.168.3.1/32      [BGP/170] 00:11:48, localpref 100, from 192.168.3.1
                      AS path: I
                    > to 13.13.13.3 via fe-1/2/1.2
192.168.4.1/32     *[BGP/170] 00:05:14, localpref 100, from 192.168.2.1
                      AS path: 4 I
                    > to 12.12.12.2 via fe-1/2/0.1
                    [BGP/170] 00:05:14, localpref 100, from 192.168.3.1
                      AS path: 4 I
                    > to 13.13.13.3 via fe-1/2/1.2

Meaning

The asterisk (*) shows that the preferred path is through Device R2. In the default configuration, Device R2 has a lower router ID than Device R3. The router ID is controlling the path selection.

Altering the Local Preference to Change the Path Selection

Purpose

Change the path so that it goes through Device R3.

Action

From configuration mode, enter the set local-preference 300 command.

[edit protocols bgp group internal]
user@R3# set local-preference 300
user@R3# commit

Rechecking the Active Path From Device R1 to Device R4

Purpose

Verify that the active path from Device R1 to Device R4 goes through Device R3.

Action

From operational mode, enter the show route protocol bgp command.

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

12.12.12.0/24       [BGP/170] 00:16:48, localpref 100, from 192.168.2.1
                      AS path: I
                    > to 12.12.12.2 via fe-1/2/0.1
13.13.13.0/24       [BGP/170] 00:00:22, localpref 300, from 192.168.3.1
                      AS path: I
                    > to 13.13.13.3 via fe-1/2/1.2
24.24.24.0/24       [BGP/170] 00:16:48, localpref 100, from 192.168.2.1
                      AS path: I
                    > to 12.12.12.2 via fe-1/2/0.1
34.34.34.0/24       [BGP/170] 00:00:22, localpref 300, from 192.168.3.1
                      AS path: I
                    > to 13.13.13.3 via fe-1/2/1.2
192.168.2.1/32      [BGP/170] 00:16:48, localpref 100, from 192.168.2.1
                      AS path: I
                    > to 12.12.12.2 via fe-1/2/0.1
192.168.3.1/32      [BGP/170] 00:00:22, localpref 300, from 192.168.3.1
                      AS path: I
                    > to 13.13.13.3 via fe-1/2/1.2
192.168.4.1/32     *[BGP/170] 00:00:21, localpref 300, from 192.168.3.1
                      AS path: 4 I
                    > to 13.13.13.3 via fe-1/2/1.2 

Meaning

The asterisk (*) shows that the preferred path is through Device R3. In the altered configuration, Device R3 has a higher local preference than Device R2. The local preference is controlling the path selection.

Published: 2013-07-09