Saturday, February 1, 2014

BGP Local Preference vs. AS Path Prepending

February 2014 - Reading time: 8–10 minutes

When manipulating traffic flow within a Border Gateway Protocol (BGP) environment, two common tools are frequently considered: Local Preference (Local Pref) and AS Path Prepending. While both methods influence outbound or inbound path selection, they serve different purposes and are applied at different ends of a BGP peering relationship. In this post, I’ll explore each technique in depth, explain when to use one over the other, and share configuration examples to solidify understanding.

Understanding Local Preference

Local Preference is a well-known attribute used for influencing outbound routing decisions within an AS (Autonomous System). It is a high-priority BGP attribute — evaluated early in the BGP decision process — and is used to tell internal routers which path to prefer when multiple routes to the same prefix exist.

Here’s a simple scenario: you’re connected to two upstream providers. You want your outbound traffic to exit via ISP A and only use ISP B when ISP A is down. Local Preference makes this easy.

  router bgp 65000
   neighbor 192.0.2.1 remote-as 64500
   neighbor 192.0.2.1 route-map PREFER_ISP_A in

  route-map PREFER_ISP_A permit 10
   set local-preference 200
  

In the above example, we increase the Local Preference for routes received from ISP A. As a result, internal routers will prefer to send outbound traffic to ISP A even if both paths appear equally viable.

Understanding AS Path Prepending

AS Path Prepending, on the other hand, is used for influencing inbound traffic. It works by artificially increasing the AS Path length of a route advertisement. Since BGP prefers routes with shorter AS Paths, prepending your AS multiple times makes that path less attractive to upstream routers.

  router bgp 65000
   neighbor 198.51.100.1 remote-as 64600
   neighbor 198.51.100.1 route-map PREPEND_FOR_ISPB out

  route-map PREPEND_FOR_ISPB permit 10
   set as-path prepend 65000 65000 65000
  

This configuration causes three prepends when advertising prefixes to ISP B, making ISP A’s path more favorable for remote routers — thus shaping inbound traffic toward ISP A.

Comparison and Best Practices

  • Local Preference is local to your AS — it doesn’t propagate outside. Use it to control outbound traffic.
  • AS Path Prepending affects how other ASes see your routes. Use it to manipulate inbound traffic.

Some best practices when using these tools:

  • Always document your policies. Multiple engineers may touch the router configuration, and undocumented route-maps can be confusing or dangerous.
  • Use meaningful names for route-maps.
  • Monitor changes using NetFlow or BGP route monitoring tools like BGPmon or bgp.tools to see how your changes are reflected globally.
  • Test configurations during maintenance windows to validate their impact before committing to full deployment.

Combining the Two

In multi-homed environments, it is common to use both techniques: Local Preference for outgoing traffic optimization and AS Path Prepending for inbound influence. Each can work independently, but combining them smartly allows you to achieve more sophisticated routing behaviors, especially when peering with Tier 1 or regional carriers.

Final Thoughts

Manipulating BGP traffic is both an art and a science. While these methods are well-documented, real-world application often involves subtle nuances — such as provider filtering, route-flap dampening, or upstream route-map overrides. Thorough testing, monitoring, and communication with peers are essential for successful implementation.

Understanding the mechanics behind Local Preference and AS Path Prepending is foundational to building resilient and responsive routing policies in any BGP-enabled network. If you haven’t already, lab these out and simulate scenarios using tools like GNS3 or EVE-NG to deepen your intuition around BGP path selection.



Eduardo Wnorowski is a network infrastructure consultant and technologist.
With over 19 years of experience in IT and consulting, he brings deep expertise in networking, security, infrastructure, and transformation.
Connect on Linkedin

AI-Augmented Network Management: Architecture Shifts in 2025

August, 2025 · 9 min read As enterprises grapple with increasingly complex network topologies and operational environments, 2025 mar...