Introduction
Welcome to a new series on BGP Path Attributes – the mechanisms that control how BGP makes routing decisions. While my previous posts focused on route filtering and aggregation, this series dives into how BGP actually chooses the best path when multiple routes to the same destination exist.
We’re starting with one of the most powerful and commonly used attributes: Local Preference.
Local Preference is your primary tool for controlling outbound traffic from your autonomous system. When you have multiple exit points to reach external destinations, Local Preference determines which exit your entire AS will prefer. Set it once on the edge router receiving the routes, and every router in your AS will make consistent forwarding decisions.
Understanding Local Preference
What is Local Preference?
Local Preference is a BGP path attribute with these key characteristics:
- Numeric value: Default is 100. Higher values are preferred.
- Scope: iBGP only – never leaves your AS, not sent to eBGP peers
- Direction: Controls outbound traffic (exits from your AS)
- Propagation: Set inbound on routes received from eBGP, then distributed via iBGP throughout your AS
Why Local Preference Matters
When your AS has multiple connections to the outside world (multihoming), you need a way to coordinate exit point selection across all your routers. Without Local Preference, different routers might make different decisions based on IGP metrics or other tie-breakers, leading to suboptimal or unpredictable routing.
Local Preference ensures consistent exit point selection across your entire AS. Set it high on routes from your preferred provider, and every router in your AS will prefer that exit.
Lab Topology
The new topology for this BGP attributes series involves multiple autonomous systems with redundant connections:
- AS 12: R1, R2 (connected to both AS 100 and AS 1000)
- AS 100: R10 (connected to R1 and R2)
- AS 1000: R3, R4, R5, R6 (fully meshed)
- AS 2000: R7, R8, R9 (iBGP mesh)
- AS 110: R11
The key for Local Preference examples: AS 2000 has two exit points to reach AS 1000:
- R7 connects to R4 (via 192.1.47.0/24)
- R8 connects to R4 (via 192.1.48.0/24)
By default, AS 2000 routers might split their traffic or make inconsistent decisions. Local Preference allows us to enforce a consistent policy.
Example 1: Set Global Exit Preference for Entire AS
Requirement
AS 2000 should use the link between R7 and R4 as the preferred exit point for the entire AS.
This means all routers in AS 2000 (R7, R8, R9) should prefer routes learned via R7 over routes learned via R8 when reaching external destinations.
Initial State (Before Configuration)
R8’s BGP table shows routes to AS 1000 networks with two paths available:
R8#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
* i 1.0.0.0 10.7.7.7 0 100 0 1000 12 i
*> 192.1.48.4 0 1000 12 i
* i 2.0.0.0 10.7.7.7 0 100 0 1000 12 i
*> 192.1.48.4 0 1000 12 i
* i 3.0.0.0 10.7.7.7 0 100 0 1000 i
*> 192.1.48.4 0 1000 i
* i 4.0.0.0 10.7.7.7 0 100 0 1000 i
*> 192.1.48.4 0 0 1000 i
* i 6.0.0.0 10.7.7.7 0 100 0 1000 ?
*> 192.1.48.4 0 1000 ?
Notice:
- Two paths for each route: one via 10.7.7.7 (R7, received via iBGP), one via 192.1.48.4 (R4, received via eBGP directly)
- The
>symbol shows the best path – currently via 192.1.48.4 (R8’s own eBGP connection) - Local Preference is 100 for the iBGP routes (default value)
- R8 prefers its own eBGP path because eBGP beats iBGP in the best-path selection (step 6)
This is suboptimal. R8 is using its local connection rather than following the AS-wide policy that R7’s connection should be preferred.
Configuration
On R7 (the router receiving routes from the preferred exit), set Local Preference high on routes received from R4:
route-map SET-ATT permit 10
set local-preference 200
router bgp 2000
neighbor 192.1.47.4 route-map SET-ATT in
Breaking it down:
- The route-map
SET-ATTsets Local Preference to 200 (higher than the default 100) - Applied inbound on the eBGP neighbor 192.1.47.4 (R4)
- This affects all routes received from R4 via this neighbor
Important: Set Local Preference on the inbound direction of the eBGP session. As soon as routes are received from the external AS, tag them with high Local Preference. When R7 advertises these routes to R8 and R9 via iBGP, the Local Preference of 200 is carried with them.
Results After Configuration
R8’s BGP table now shows:
R8#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.0.0.0 10.7.7.7 0 200 0 1000 12 i
* 192.1.48.4 0 1000 12 i
*>i 2.0.0.0 10.7.7.7 0 200 0 1000 12 i
* 192.1.48.4 0 1000 12 i
*>i 3.0.0.0 10.7.7.7 0 200 0 1000 i
* 192.1.48.4 0 1000 i
*>i 4.0.0.0 10.7.7.7 0 200 0 1000 i
* 192.1.48.4 0 0 1000 i
*>i 6.0.0.0 10.7.7.7 0 200 0 1000 ?
* 192.1.48.4 0 1000 ?
The changes:
- Local Preference for routes via 10.7.7.7 (R7) is now 200 (up from 100)
- The
>best-path marker moved from the direct eBGP path to the iBGP path via R7 - Routes via 192.1.48.4 (R8’s own eBGP connection) are now backup paths
This is exactly what we wanted. Even though R8 has a direct eBGP connection to R4, it now prefers to route via R7 because Local Preference (200) beats the eBGP vs iBGP preference.
What Happens in the AS
Every router in AS 2000 now sees the same preference:
- R7: Originates routes with LP=200, uses its own eBGP connection (next-hop is itself)
- R8: Receives routes from R7 via iBGP with LP=200, prefers them over its own eBGP routes with default LP=100
- R9: Receives routes from R7 via iBGP with LP=200, forwards traffic toward R7
Result: All outbound traffic from AS 2000 exits via the R7-R4 link. The R8-R4 link becomes a backup, only used if the R7-R4 link fails.
Example 2: Selective Exit Preference for Specific Prefixes
Requirement
AS 2000 should use the link between R8 and R4 as the preferred exit for specific networks only:
- 5.0.0.0/8
- 55.5.5.0/24
All other traffic should continue to prefer the R7-R4 link (from Example 1).
This scenario is common when you want different prefixes to use different exit points for traffic engineering, cost optimization, or performance reasons.
Configuration
On R8, create a selective Local Preference policy using a route-map with match conditions:
access-list 1 permit 5.0.0.0 0.255.255.255
access-list 1 permit 55.5.5.0 0.0.0.255
route-map SET-ATT permit 10
match ip address 1
set local-preference 300
route-map SET-ATT permit 20
router bgp 2000
neighbor 192.1.48.4 route-map SET-ATT in
Breaking it down:
Sequence 10 (specific networks):
- Matches 5.0.0.0/8 and 55.5.5.0/24 via ACL 1
- Sets Local Preference to 300
Sequence 20 (everything else):
- No match clause = matches everything not matched by sequence 10
- No set clause = leaves Local Preference at default (100)
Why LP=300? It needs to be:
- Higher than 200 (what R7 already sets inbound) so R8’s path beats R9’s view of these routes
- But we could also use any value; the point is R8’s path for these specific routes now has higher LP than the paths learned from R7
Results After Configuration
R8’s BGP table now shows:
R8#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.0.0.0 10.7.7.7 0 200 0 1000 12 i
* 192.1.48.4 0 1000 12 i
*>i 2.0.0.0 10.7.7.7 0 200 0 1000 12 i
* 192.1.48.4 0 1000 12 i
*>i 3.0.0.0 10.7.7.7 0 200 0 1000 i
* 192.1.48.4 0 1000 i
*>i 4.0.0.0 10.7.7.7 0 200 0 1000 i
* 192.1.48.4 0 0 1000 i
*> 5.0.0.0 192.1.48.4 300 0 1000 i
*>i 6.0.0.0 10.7.7.7 0 200 0 1000 ?
* 192.1.48.4 0 1000 ?
*> 55.5.5.0/24 192.1.48.4 300 0 1000 i
The key observations:
5.0.0.0/8 and 55.5.5.0/24:
- Best path is via 192.1.48.4 (R8’s direct eBGP connection)
- These routes now have LP=300 after being set by R8’s inbound route-map
- When R8 advertises these to R7 and R9 via iBGP with LP=300, they will be preferred over any other path to these networks
All other routes (1.0.0.0, 2.0.0.0, 3.0.0.0, etc.):
- Best path remains via 10.7.7.7 (R7) with LP=200
- R8’s local eBGP path for these has default LP, which is lower than 200
Traffic Flow Result
After this configuration:
- 5.0.0.0/8 traffic: All routers in AS 2000 exit via R8’s connection to R4
- 55.5.5.0/24 traffic: All routers in AS 2000 exit via R8’s connection to R4
- All other traffic: All routers in AS 2000 exit via R7’s connection to R4
This gives you per-prefix traffic engineering control while maintaining AS-wide consistency for each prefix.